llimits.h 4.8 KB

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