llimits.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. ** $Id: llimits.h,v 1.79 2010/04/29 17:31:31 roberto Exp roberto $
  3. ** Limits, basic types, and some other `installation-dependent' definitions
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef llimits_h
  7. #define llimits_h
  8. #include <limits.h>
  9. #include <stddef.h>
  10. #include "lua.h"
  11. typedef unsigned LUA_INT32 lu_int32;
  12. typedef LUAI_UMEM lu_mem;
  13. typedef LUAI_MEM l_mem;
  14. /* chars used as small naturals (so that `char' is reserved for characters) */
  15. typedef unsigned char lu_byte;
  16. #define MAX_SIZET ((size_t)(~(size_t)0)-2)
  17. #define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2)
  18. #define MIN_LMEM ((l_mem)~((~(lu_mem)0)>>1))
  19. #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
  20. /*
  21. ** conversion of pointer to integer
  22. ** this is for hashing only; there is no problem if the integer
  23. ** cannot hold the whole pointer value
  24. */
  25. #define IntPoint(p) ((unsigned int)(lu_mem)(p))
  26. /* type to ensure maximum alignment */
  27. #if !defined(LUAI_USER_ALIGNMENT_T)
  28. #define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; }
  29. #endif
  30. typedef LUAI_USER_ALIGNMENT_T L_Umaxalign;
  31. /* result of a `usual argument conversion' over lua_Number */
  32. typedef LUAI_UACNUMBER l_uacNumber;
  33. /* internal assertions for in-house debugging */
  34. #if defined(lua_assert)
  35. #define check_exp(c,e) (lua_assert(c), (e))
  36. #else
  37. #define lua_assert(c) /* empty */
  38. #define check_exp(c,e) (e)
  39. #endif
  40. /*
  41. ** assertion for checking API calls
  42. */
  43. #if defined(LUA_USE_APICHECK)
  44. #include <assert.h>
  45. #define luai_apicheck(L,e) { (void)L; assert(e); }
  46. #elif !defined(luai_apicheck)
  47. #define luai_apicheck(L,e) lua_assert(e)
  48. #endif
  49. #define api_check(l,e,msg) luai_apicheck(l,(e) && msg)
  50. #if !defined(UNUSED)
  51. #define UNUSED(x) ((void)(x)) /* to avoid warnings */
  52. #endif
  53. #define cast(t, exp) ((t)(exp))
  54. #define cast_byte(i) cast(lu_byte, (i))
  55. #define cast_num(i) cast(lua_Number, (i))
  56. #define cast_int(i) cast(int, (i))
  57. /*
  58. ** maximum depth for nested C calls and syntactical nested non-terminals
  59. ** in a program. (Value must fit in an unsigned short int.)
  60. */
  61. #if !defined(LUAI_MAXCCALLS)
  62. #define LUAI_MAXCCALLS 200
  63. #endif
  64. /*
  65. ** type for virtual-machine instructions
  66. ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
  67. */
  68. typedef lu_int32 Instruction;
  69. /* maximum stack for a Lua function */
  70. #define MAXSTACK 250
  71. /* minimum size for the string table (must be power of 2) */
  72. #if !defined(MINSTRTABSIZE)
  73. #define MINSTRTABSIZE 32
  74. #endif
  75. /* minimum size for string buffer */
  76. #if !defined(LUA_MINBUFFER)
  77. #define LUA_MINBUFFER 32
  78. #endif
  79. #if !defined(lua_lock)
  80. #define lua_lock(L) ((void) 0)
  81. #define lua_unlock(L) ((void) 0)
  82. #endif
  83. #if !defined(luai_threadyield)
  84. #define luai_threadyield(L) {lua_unlock(L); lua_lock(L);}
  85. #endif
  86. /*
  87. ** these macros allow user-specific actions on threads when you defined
  88. ** LUAI_EXTRASPACE and need to do something extra when a thread is
  89. ** created/deleted/resumed/yielded.
  90. */
  91. #if !defined(luai_userstateopen)
  92. #define luai_userstateopen(L) ((void)L)
  93. #endif
  94. #if !defined(luai_userstateclose)
  95. #define luai_userstateclose(L) ((void)L)
  96. #endif
  97. #if !defined(luai_userstatethread)
  98. #define luai_userstatethread(L,L1) ((void)L)
  99. #endif
  100. #if !defined(luai_userstatefree)
  101. #define luai_userstatefree(L,L1) ((void)L)
  102. #endif
  103. #if !defined(luai_userstateresume)
  104. #define luai_userstateresume(L,n) ((void)L)
  105. #endif
  106. #if !defined(luai_userstateyield)
  107. #define luai_userstateyield(L,n) ((void)L)
  108. #endif
  109. /*
  110. ** macro to control inclusion of some hard tests on stack reallocation
  111. */
  112. #if !defined(HARDSTACKTESTS)
  113. #define condmovestack(L) ((void)0)
  114. #else
  115. /* realloc stack keeping its size */
  116. #define condmovestack(L) luaD_reallocstack((L), (L)->stacksize)
  117. #endif
  118. #if !defined(HARDMEMTESTS)
  119. #define condchangemem(L) condmovestack(L)
  120. #else
  121. #define condchangemem(L) luaC_fullgc(L, 0)
  122. #endif
  123. #endif