llimits.h 4.9 KB

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