llimits.h 3.9 KB

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