llimits.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. ** $Id: llimits.h,v 1.109 2013/08/21 19:02:30 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_byte(i) cast(lu_byte, (i))
  69. #define cast_num(i) cast(lua_Number, (i))
  70. #define cast_int(i) cast(int, (i))
  71. #define cast_uchar(i) cast(unsigned char, (i))
  72. #define cast_integer(i) cast(lua_Integer, (i))
  73. #define cast_unsigned(i) cast(lua_Unsigned, (i))
  74. /*
  75. ** non-return type
  76. */
  77. #if defined(__GNUC__)
  78. #define l_noret void __attribute__((noreturn))
  79. #elif defined(_MSC_VER)
  80. #define l_noret void __declspec(noreturn)
  81. #else
  82. #define l_noret void
  83. #endif
  84. /*
  85. ** maximum depth for nested C calls and syntactical nested non-terminals
  86. ** in a program. (Value must fit in an unsigned short int.)
  87. */
  88. #if !defined(LUAI_MAXCCALLS)
  89. #define LUAI_MAXCCALLS 200
  90. #endif
  91. /*
  92. ** maximum number of upvalues in a closure (both C and Lua). (Value
  93. ** must fit in an unsigned char.)
  94. */
  95. #define MAXUPVAL UCHAR_MAX
  96. /*
  97. ** type for virtual-machine instructions
  98. ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
  99. */
  100. typedef lu_int32 Instruction;
  101. /* maximum stack for a Lua function */
  102. #define MAXSTACK 250
  103. /* minimum size for the string table (must be power of 2) */
  104. #if !defined(MINSTRTABSIZE)
  105. #define MINSTRTABSIZE 64 /* minimum size for "predefined" strings */
  106. #endif
  107. /* minimum size for string buffer */
  108. #if !defined(LUA_MINBUFFER)
  109. #define LUA_MINBUFFER 32
  110. #endif
  111. #if !defined(lua_lock)
  112. #define lua_lock(L) ((void) 0)
  113. #define lua_unlock(L) ((void) 0)
  114. #endif
  115. #if !defined(luai_threadyield)
  116. #define luai_threadyield(L) {lua_unlock(L); lua_lock(L);}
  117. #endif
  118. /*
  119. ** these macros allow user-specific actions on threads when you defined
  120. ** LUAI_EXTRASPACE and need to do something extra when a thread is
  121. ** created/deleted/resumed/yielded.
  122. */
  123. #if !defined(luai_userstateopen)
  124. #define luai_userstateopen(L) ((void)L)
  125. #endif
  126. #if !defined(luai_userstateclose)
  127. #define luai_userstateclose(L) ((void)L)
  128. #endif
  129. #if !defined(luai_userstatethread)
  130. #define luai_userstatethread(L,L1) ((void)L)
  131. #endif
  132. #if !defined(luai_userstatefree)
  133. #define luai_userstatefree(L,L1) ((void)L)
  134. #endif
  135. #if !defined(luai_userstateresume)
  136. #define luai_userstateresume(L,n) ((void)L)
  137. #endif
  138. #if !defined(luai_userstateyield)
  139. #define luai_userstateyield(L,n) ((void)L)
  140. #endif
  141. /*
  142. ** macro to control inclusion of some hard tests on stack reallocation
  143. */
  144. #if !defined(HARDSTACKTESTS)
  145. #define condmovestack(L) ((void)0)
  146. #else
  147. /* realloc stack keeping its size */
  148. #define condmovestack(L) luaD_reallocstack((L), (L)->stacksize)
  149. #endif
  150. #if !defined(HARDMEMTESTS)
  151. #define condchangemem(L) condmovestack(L)
  152. #else
  153. #define condchangemem(L) \
  154. ((void)(!(G(L)->gcrunning) || (luaC_fullgc(L, 0), 1)))
  155. #endif
  156. #endif