llimits.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. ** $Id: llimits.h,v 1.75 2009/11/17 11:56:03 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 MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
  19. /*
  20. ** conversion of pointer to integer
  21. ** this is for hashing only; there is no problem if the integer
  22. ** cannot hold the whole pointer value
  23. */
  24. #define IntPoint(p) ((unsigned int)(lu_mem)(p))
  25. /* type to ensure maximum alignment */
  26. #if !defined(LUAI_USER_ALIGNMENT_T)
  27. #define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; }
  28. #endif
  29. typedef LUAI_USER_ALIGNMENT_T L_Umaxalign;
  30. /* result of a `usual argument conversion' over lua_Number */
  31. typedef LUAI_UACNUMBER l_uacNumber;
  32. /* internal assertions for in-house debugging */
  33. #if defined(lua_assert)
  34. #define check_exp(c,e) (lua_assert(c), (e))
  35. #else
  36. #define lua_assert(c) ((void)0)
  37. #define check_exp(c,e) (e)
  38. #endif
  39. /*
  40. ** assertion for checking API calls
  41. */
  42. #if defined(LUA_USE_APICHECK)
  43. #include <assert.h>
  44. #define luai_apicheck(L,e) { (void)L; assert(e); }
  45. #elif !defined(luai_apicheck)
  46. #define luai_apicheck(L,e) lua_assert(e)
  47. #endif
  48. #define api_check(l,e,msg) luai_apicheck(l,(e) && msg)
  49. #if !defined(UNUSED)
  50. #define UNUSED(x) ((void)(x)) /* to avoid warnings */
  51. #endif
  52. #define cast(t, exp) ((t)(exp))
  53. #define cast_byte(i) cast(lu_byte, (i))
  54. #define cast_num(i) cast(lua_Number, (i))
  55. #define cast_int(i) cast(int, (i))
  56. /*
  57. ** maximum depth for nested C calls and syntactical nested non-terminals
  58. ** in a program. (Value must fit in an unsigned short int.)
  59. */
  60. #if !defined(LUAI_MAXCCALLS)
  61. #define LUAI_MAXCCALLS 200
  62. #endif
  63. /*
  64. ** type for virtual-machine instructions
  65. ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
  66. */
  67. typedef lu_int32 Instruction;
  68. /* maximum stack for a Lua function */
  69. #define MAXSTACK 250
  70. /* minimum size for the string table (must be power of 2) */
  71. #if !defined(MINSTRTABSIZE)
  72. #define MINSTRTABSIZE 32
  73. #endif
  74. /* minimum size for string buffer */
  75. #if !defined(LUA_MINBUFFER)
  76. #define LUA_MINBUFFER 32
  77. #endif
  78. #if !defined(lua_lock)
  79. #define lua_lock(L) ((void) 0)
  80. #define lua_unlock(L) ((void) 0)
  81. #endif
  82. #if !defined(luai_threadyield)
  83. #define luai_threadyield(L) {lua_unlock(L); lua_lock(L);}
  84. #endif
  85. /*
  86. ** macro to control inclusion of some hard tests on stack reallocation
  87. */
  88. #if !defined(HARDSTACKTESTS)
  89. #define condmovestack(L) ((void)0)
  90. #else
  91. /* realloc stack keeping its size */
  92. #define condmovestack(L) luaD_reallocstack((L), (L)->stacksize)
  93. #endif
  94. #if !defined(HARDMEMTESTS)
  95. #define condchangemem(L) condmovestack(L)
  96. #else
  97. #define condchangemem(L) luaC_fullgc(L, 0)
  98. #endif
  99. #endif