1 /* $NetBSD: llimits.h,v 1.2 2014/07/19 18:38:34 lneto Exp $ */ 2 3 /* 4 ** $Id: llimits.h,v 1.2 2014/07/19 18:38:34 lneto Exp $ 5 ** Limits, basic types, and some other `installation-dependent' definitions 6 ** See Copyright Notice in lua.h 7 */ 8 9 #ifndef llimits_h 10 #define llimits_h 11 12 13 #ifndef _KERNEL 14 #include <limits.h> 15 #include <stddef.h> 16 #endif 17 18 19 #include "lua.h" 20 21 22 typedef unsigned LUA_INT32 lu_int32; 23 24 typedef LUAI_UMEM lu_mem; 25 26 typedef LUAI_MEM l_mem; 27 28 29 30 /* chars used as small naturals (so that `char' is reserved for characters) */ 31 typedef unsigned char lu_byte; 32 33 34 /* maximum value for size_t */ 35 #define MAX_SIZET ((size_t)(~(size_t)0)-2) 36 37 /* maximum size visible for Lua (must be representable in a lua_Integer */ 38 #define MAX_SIZE (sizeof(size_t) < sizeof(lua_Integer) ? MAX_SIZET \ 39 : (size_t)(LUA_MAXINTEGER)-2) 40 41 42 #define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) 43 44 #define MAX_LMEM ((l_mem) ((MAX_LUMEM >> 1) - 2)) 45 46 47 #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ 48 49 50 /* 51 ** conversion of pointer to integer 52 ** this is for hashing only; there is no problem if the integer 53 ** cannot hold the whole pointer value 54 */ 55 #define IntPoint(p) ((unsigned int)(lu_mem)(p)) 56 57 58 59 /* type to ensure maximum alignment */ 60 #if !defined(LUAI_USER_ALIGNMENT_T) 61 #define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; } 62 #endif 63 64 typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; 65 66 67 /* types of 'usual argument conversions' for lua_Number and lua_Integer */ 68 typedef LUAI_UACNUMBER l_uacNumber; 69 typedef LUAI_UACINT l_uacInt; 70 71 72 /* internal assertions for in-house debugging */ 73 #if defined(lua_assert) 74 #define check_exp(c,e) (lua_assert(c), (e)) 75 /* to avoid problems with conditions too long */ 76 #define lua_longassert(c) { if (!(c)) lua_assert(0); } 77 #else 78 #define lua_assert(c) ((void)0) 79 #define check_exp(c,e) (e) 80 #define lua_longassert(c) ((void)0) 81 #endif 82 83 /* 84 ** assertion for checking API calls 85 */ 86 #if !defined(luai_apicheck) 87 88 #if defined(LUA_USE_APICHECK) 89 #include <assert.h> 90 #define luai_apicheck(L,e) assert(e) 91 #else 92 #define luai_apicheck(L,e) lua_assert(e) 93 #endif 94 95 #endif 96 97 #define api_check(l,e,msg) luai_apicheck(l,(e) && msg) 98 99 100 #if !defined(UNUSED) 101 #define UNUSED(x) ((void)(x)) /* to avoid warnings */ 102 #endif 103 104 105 #define cast(t, exp) ((t)(exp)) 106 107 #define cast_void(i) cast(void, (i)) 108 #define cast_byte(i) cast(lu_byte, (i)) 109 #define cast_num(i) cast(lua_Number, (i)) 110 #define cast_int(i) cast(int, (i)) 111 #define cast_uchar(i) cast(unsigned char, (i)) 112 113 114 /* cast a signed lua_Integer to lua_Unsigned */ 115 #if !defined(l_castS2U) 116 #define l_castS2U(i) ((lua_Unsigned)(i)) 117 #endif 118 119 /* 120 ** cast a lua_Unsigned to a signed lua_Integer; this cast is 121 ** not strict ANSI C, but two-complement architectures should 122 ** work fine. 123 */ 124 #if !defined(l_castU2S) 125 #define l_castU2S(i) ((lua_Integer)(i)) 126 #endif 127 128 129 /* 130 ** non-return type 131 */ 132 #if defined(__GNUC__) 133 #define l_noret void __attribute__((noreturn)) 134 #elif defined(_MSC_VER) 135 #define l_noret void __declspec(noreturn) 136 #else 137 #define l_noret void 138 #endif 139 140 141 142 /* 143 ** maximum depth for nested C calls and syntactical nested non-terminals 144 ** in a program. (Value must fit in an unsigned short int.) 145 */ 146 #if !defined(LUAI_MAXCCALLS) 147 #define LUAI_MAXCCALLS 200 148 #endif 149 150 /* 151 ** maximum number of upvalues in a closure (both C and Lua). (Value 152 ** must fit in an unsigned char.) 153 */ 154 #define MAXUPVAL UCHAR_MAX 155 156 157 /* 158 ** type for virtual-machine instructions 159 ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) 160 */ 161 typedef lu_int32 Instruction; 162 163 164 165 /* maximum stack for a Lua function */ 166 #define MAXSTACK 250 167 168 169 170 /* minimum size for the string table (must be power of 2) */ 171 #if !defined(MINSTRTABSIZE) 172 #define MINSTRTABSIZE 64 /* minimum size for "predefined" strings */ 173 #endif 174 175 176 /* minimum size for string buffer */ 177 #if !defined(LUA_MINBUFFER) 178 #define LUA_MINBUFFER 32 179 #endif 180 181 182 #if !defined(lua_lock) 183 #define lua_lock(L) ((void) 0) 184 #define lua_unlock(L) ((void) 0) 185 #endif 186 187 #if !defined(luai_threadyield) 188 #define luai_threadyield(L) {lua_unlock(L); lua_lock(L);} 189 #endif 190 191 192 /* 193 ** these macros allow user-specific actions on threads when you defined 194 ** LUAI_EXTRASPACE and need to do something extra when a thread is 195 ** created/deleted/resumed/yielded. 196 */ 197 #if !defined(luai_userstateopen) 198 #define luai_userstateopen(L) ((void)L) 199 #endif 200 201 #if !defined(luai_userstateclose) 202 #define luai_userstateclose(L) ((void)L) 203 #endif 204 205 #if !defined(luai_userstatethread) 206 #define luai_userstatethread(L,L1) ((void)L) 207 #endif 208 209 #if !defined(luai_userstatefree) 210 #define luai_userstatefree(L,L1) ((void)L) 211 #endif 212 213 #if !defined(luai_userstateresume) 214 #define luai_userstateresume(L,n) ((void)L) 215 #endif 216 217 #if !defined(luai_userstateyield) 218 #define luai_userstateyield(L,n) ((void)L) 219 #endif 220 221 222 223 /* 224 ** macro to control inclusion of some hard tests on stack reallocation 225 */ 226 #if !defined(HARDSTACKTESTS) 227 #define condmovestack(L) ((void)0) 228 #else 229 /* realloc stack keeping its size */ 230 #define condmovestack(L) luaD_reallocstack((L), (L)->stacksize) 231 #endif 232 233 #if !defined(HARDMEMTESTS) 234 #define condchangemem(L) condmovestack(L) 235 #else 236 #define condchangemem(L) \ 237 ((void)(!(G(L)->gcrunning) || (luaC_fullgc(L, 0), 1))) 238 #endif 239 240 #endif 241