llimits.h 4.9 KB

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