llimits.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. ** $Id: llimits.h,v 1.116 2014/04/15 16:32:49 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. /* maximum value for size_t */
  17. #define MAX_SIZET ((size_t)(~(size_t)0)-2)
  18. /* maximum size visible for Lua (must be representable in a lua_Integer */
  19. #define MAX_SIZE (sizeof(size_t) < sizeof(lua_Integer) ? MAX_SIZET \
  20. : (size_t)(LUA_MAXINTEGER)-2)
  21. #define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2)
  22. #define MAX_LMEM ((l_mem) ((MAX_LUMEM >> 1) - 2))
  23. #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
  24. /*
  25. ** conversion of pointer to integer:
  26. ** this is for hashing only; there is no problem if the integer
  27. ** cannot hold the whole pointer value
  28. */
  29. #define point2int(p) ((unsigned int)((lu_mem)(p) & UINT_MAX))
  30. /* type to ensure maximum alignment */
  31. #if !defined(LUAI_USER_ALIGNMENT_T)
  32. #define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; }
  33. #endif
  34. typedef LUAI_USER_ALIGNMENT_T L_Umaxalign;
  35. /* types of 'usual argument conversions' for lua_Number and lua_Integer */
  36. typedef LUAI_UACNUMBER l_uacNumber;
  37. typedef LUAI_UACINT l_uacInt;
  38. /* internal assertions for in-house debugging */
  39. #if defined(lua_assert)
  40. #define check_exp(c,e) (lua_assert(c), (e))
  41. /* to avoid problems with conditions too long */
  42. #define lua_longassert(c) { if (!(c)) lua_assert(0); }
  43. #else
  44. #define lua_assert(c) ((void)0)
  45. #define check_exp(c,e) (e)
  46. #define lua_longassert(c) ((void)0)
  47. #endif
  48. /*
  49. ** assertion for checking API calls
  50. */
  51. #if !defined(luai_apicheck)
  52. #if defined(LUA_USE_APICHECK)
  53. #include <assert.h>
  54. #define luai_apicheck(L,e) assert(e)
  55. #else
  56. #define luai_apicheck(L,e) lua_assert(e)
  57. #endif
  58. #endif
  59. #define api_check(l,e,msg) luai_apicheck(l,(e) && msg)
  60. #if !defined(UNUSED)
  61. #define UNUSED(x) ((void)(x)) /* to avoid warnings */
  62. #endif
  63. #define cast(t, exp) ((t)(exp))
  64. #define cast_void(i) cast(void, (i))
  65. #define cast_byte(i) cast(lu_byte, (i))
  66. #define cast_num(i) cast(lua_Number, (i))
  67. #define cast_int(i) cast(int, (i))
  68. #define cast_uchar(i) cast(unsigned char, (i))
  69. /* cast a signed lua_Integer to lua_Unsigned */
  70. #if !defined(l_castS2U)
  71. #define l_castS2U(i) ((lua_Unsigned)(i))
  72. #endif
  73. /*
  74. ** cast a lua_Unsigned to a signed lua_Integer; this cast is
  75. ** not strict ANSI C, but two-complement architectures should
  76. ** work fine.
  77. */
  78. #if !defined(l_castU2S)
  79. #define l_castU2S(i) ((lua_Integer)(i))
  80. #endif
  81. /*
  82. ** non-return type
  83. */
  84. #if defined(__GNUC__)
  85. #define l_noret void __attribute__((noreturn))
  86. #elif defined(_MSC_VER)
  87. #define l_noret void __declspec(noreturn)
  88. #else
  89. #define l_noret void
  90. #endif
  91. /*
  92. ** maximum depth for nested C calls and syntactical nested non-terminals
  93. ** in a program. (Value must fit in an unsigned short int.)
  94. */
  95. #if !defined(LUAI_MAXCCALLS)
  96. #define LUAI_MAXCCALLS 200
  97. #endif
  98. /*
  99. ** maximum number of upvalues in a closure (both C and Lua). (Value
  100. ** must fit in an unsigned char.)
  101. */
  102. #define MAXUPVAL UCHAR_MAX
  103. /*
  104. ** type for virtual-machine instructions
  105. ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
  106. */
  107. typedef lu_int32 Instruction;
  108. /* maximum stack for a Lua function */
  109. #define MAXSTACK 250
  110. /* minimum size for the string table (must be power of 2) */
  111. #if !defined(MINSTRTABSIZE)
  112. #define MINSTRTABSIZE 64 /* minimum size for "predefined" strings */
  113. #endif
  114. /* minimum size for string buffer */
  115. #if !defined(LUA_MINBUFFER)
  116. #define LUA_MINBUFFER 32
  117. #endif
  118. #if !defined(lua_lock)
  119. #define lua_lock(L) ((void) 0)
  120. #define lua_unlock(L) ((void) 0)
  121. #endif
  122. #if !defined(luai_threadyield)
  123. #define luai_threadyield(L) {lua_unlock(L); lua_lock(L);}
  124. #endif
  125. /*
  126. ** these macros allow user-specific actions on threads when you defined
  127. ** LUAI_EXTRASPACE and need to do something extra when a thread is
  128. ** created/deleted/resumed/yielded.
  129. */
  130. #if !defined(luai_userstateopen)
  131. #define luai_userstateopen(L) ((void)L)
  132. #endif
  133. #if !defined(luai_userstateclose)
  134. #define luai_userstateclose(L) ((void)L)
  135. #endif
  136. #if !defined(luai_userstatethread)
  137. #define luai_userstatethread(L,L1) ((void)L)
  138. #endif
  139. #if !defined(luai_userstatefree)
  140. #define luai_userstatefree(L,L1) ((void)L)
  141. #endif
  142. #if !defined(luai_userstateresume)
  143. #define luai_userstateresume(L,n) ((void)L)
  144. #endif
  145. #if !defined(luai_userstateyield)
  146. #define luai_userstateyield(L,n) ((void)L)
  147. #endif
  148. /*
  149. ** macro to control inclusion of some hard tests on stack reallocation
  150. */
  151. #if !defined(HARDSTACKTESTS)
  152. #define condmovestack(L) ((void)0)
  153. #else
  154. /* realloc stack keeping its size */
  155. #define condmovestack(L) luaD_reallocstack((L), (L)->stacksize)
  156. #endif
  157. #if !defined(HARDMEMTESTS)
  158. #define condchangemem(L) condmovestack(L)
  159. #else
  160. #define condchangemem(L) \
  161. ((void)(!(G(L)->gcrunning) || (luaC_fullgc(L, 0), 1)))
  162. #endif
  163. #endif