File indexing completed on 2026-11-07 10:37:56
0001
0002
0003
0004
0005
0006
0007 #ifndef llimits_h
0008 #define llimits_h
0009
0010
0011 #include <limits.h>
0012 #include <stddef.h>
0013
0014
0015 #include "lua.h"
0016
0017
0018
0019
0020
0021
0022
0023 #if defined(LUAI_MEM)
0024 typedef LUAI_UMEM lu_mem;
0025 typedef LUAI_MEM l_mem;
0026 #elif LUAI_IS32INT
0027 typedef size_t lu_mem;
0028 typedef ptrdiff_t l_mem;
0029 #else
0030 typedef unsigned long lu_mem;
0031 typedef long l_mem;
0032 #endif
0033
0034
0035
0036 typedef unsigned char lu_byte;
0037 typedef signed char ls_byte;
0038
0039
0040
0041 #define MAX_SIZET ((size_t)(~(size_t)0))
0042
0043
0044 #define MAX_SIZE (sizeof(size_t) < sizeof(lua_Integer) ? MAX_SIZET \
0045 : (size_t)(LUA_MAXINTEGER))
0046
0047
0048 #define MAX_LUMEM ((lu_mem)(~(lu_mem)0))
0049
0050 #define MAX_LMEM ((l_mem)(MAX_LUMEM >> 1))
0051
0052
0053 #define MAX_INT INT_MAX
0054
0055
0056
0057
0058
0059
0060 #define log2maxs(t) (sizeof(t) * 8 - 2)
0061
0062
0063
0064
0065
0066 #define ispow2(x) (((x) & ((x) - 1)) == 0)
0067
0068
0069
0070 #define LL(x) (sizeof(x)/sizeof(char) - 1)
0071
0072
0073
0074
0075
0076
0077
0078
0079 #if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \
0080 __STDC_VERSION__ >= 199901L
0081 #include <stdint.h>
0082 #if defined(UINTPTR_MAX)
0083 #define L_P2I uintptr_t
0084 #else
0085 #define L_P2I uintmax_t
0086 #endif
0087 #else
0088 #define L_P2I size_t
0089 #endif
0090
0091 #define point2uint(p) ((unsigned int)((L_P2I)(p) & UINT_MAX))
0092
0093
0094
0095
0096 typedef LUAI_UACNUMBER l_uacNumber;
0097 typedef LUAI_UACINT l_uacInt;
0098
0099
0100
0101
0102
0103 #if defined LUAI_ASSERT
0104 #undef NDEBUG
0105 #include <assert.h>
0106 #define lua_assert(c) assert(c)
0107 #endif
0108
0109 #if defined(lua_assert)
0110 #define check_exp(c,e) (lua_assert(c), (e))
0111
0112 #define lua_longassert(c) ((c) ? (void)0 : lua_assert(0))
0113 #else
0114 #define lua_assert(c) ((void)0)
0115 #define check_exp(c,e) (e)
0116 #define lua_longassert(c) ((void)0)
0117 #endif
0118
0119
0120
0121
0122 #if !defined(luai_apicheck)
0123 #define luai_apicheck(l,e) ((void)l, lua_assert(e))
0124 #endif
0125
0126 #define api_check(l,e,msg) luai_apicheck(l,(e) && msg)
0127
0128
0129
0130 #if !defined(UNUSED)
0131 #define UNUSED(x) ((void)(x))
0132 #endif
0133
0134
0135
0136 #define cast(t, exp) ((t)(exp))
0137
0138 #define cast_void(i) cast(void, (i))
0139 #define cast_voidp(i) cast(void *, (i))
0140 #define cast_num(i) cast(lua_Number, (i))
0141 #define cast_int(i) cast(int, (i))
0142 #define cast_uint(i) cast(unsigned int, (i))
0143 #define cast_byte(i) cast(lu_byte, (i))
0144 #define cast_uchar(i) cast(unsigned char, (i))
0145 #define cast_char(i) cast(char, (i))
0146 #define cast_charp(i) cast(char *, (i))
0147 #define cast_sizet(i) cast(size_t, (i))
0148
0149
0150
0151 #if !defined(l_castS2U)
0152 #define l_castS2U(i) ((lua_Unsigned)(i))
0153 #endif
0154
0155
0156
0157
0158
0159
0160 #if !defined(l_castU2S)
0161 #define l_castU2S(i) ((lua_Integer)(i))
0162 #endif
0163
0164
0165
0166
0167
0168 #if !defined(l_noret)
0169
0170 #if defined(__GNUC__)
0171 #define l_noret void __attribute__((noreturn))
0172 #elif defined(_MSC_VER) && _MSC_VER >= 1200
0173 #define l_noret void __declspec(noreturn)
0174 #else
0175 #define l_noret void
0176 #endif
0177
0178 #endif
0179
0180
0181
0182
0183
0184 #if !defined(LUA_USE_C89)
0185 #define l_inline inline
0186 #elif defined(__GNUC__)
0187 #define l_inline __inline__
0188 #else
0189 #define l_inline
0190 #endif
0191
0192 #define l_sinline static l_inline
0193
0194
0195
0196
0197
0198
0199 #if LUAI_IS32INT
0200 typedef unsigned int l_uint32;
0201 #else
0202 typedef unsigned long l_uint32;
0203 #endif
0204
0205 typedef l_uint32 Instruction;
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215 #if !defined(LUAI_MAXSHORTLEN)
0216 #define LUAI_MAXSHORTLEN 40
0217 #endif
0218
0219
0220
0221
0222
0223
0224
0225
0226 #if !defined(MINSTRTABSIZE)
0227 #define MINSTRTABSIZE 128
0228 #endif
0229
0230
0231
0232
0233
0234
0235
0236 #if !defined(STRCACHE_N)
0237 #define STRCACHE_N 53
0238 #define STRCACHE_M 2
0239 #endif
0240
0241
0242
0243 #if !defined(LUA_MINBUFFER)
0244 #define LUA_MINBUFFER 32
0245 #endif
0246
0247
0248
0249
0250
0251
0252
0253
0254 #if !defined(LUAI_MAXCCALLS)
0255 #define LUAI_MAXCCALLS 200
0256 #endif
0257
0258
0259
0260
0261
0262
0263 #if !defined(lua_lock)
0264 #define lua_lock(L) ((void) 0)
0265 #define lua_unlock(L) ((void) 0)
0266 #endif
0267
0268
0269
0270
0271
0272 #if !defined(luai_threadyield)
0273 #define luai_threadyield(L) {lua_unlock(L); lua_lock(L);}
0274 #endif
0275
0276
0277
0278
0279
0280
0281 #if !defined(luai_userstateopen)
0282 #define luai_userstateopen(L) ((void)L)
0283 #endif
0284
0285 #if !defined(luai_userstateclose)
0286 #define luai_userstateclose(L) ((void)L)
0287 #endif
0288
0289 #if !defined(luai_userstatethread)
0290 #define luai_userstatethread(L,L1) ((void)L)
0291 #endif
0292
0293 #if !defined(luai_userstatefree)
0294 #define luai_userstatefree(L,L1) ((void)L)
0295 #endif
0296
0297 #if !defined(luai_userstateresume)
0298 #define luai_userstateresume(L,n) ((void)L)
0299 #endif
0300
0301 #if !defined(luai_userstateyield)
0302 #define luai_userstateyield(L,n) ((void)L)
0303 #endif
0304
0305
0306
0307
0308
0309
0310
0311
0312 #if !defined(luai_numidiv)
0313 #define luai_numidiv(L,a,b) ((void)L, l_floor(luai_numdiv(L,a,b)))
0314 #endif
0315
0316
0317 #if !defined(luai_numdiv)
0318 #define luai_numdiv(L,a,b) ((a)/(b))
0319 #endif
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332 #if !defined(luai_nummod)
0333 #define luai_nummod(L,a,b,m) \
0334 { (void)L; (m) = l_mathop(fmod)(a,b); \
0335 if (((m) > 0) ? (b) < 0 : ((m) < 0 && (b) > 0)) (m) += (b); }
0336 #endif
0337
0338
0339 #if !defined(luai_numpow)
0340 #define luai_numpow(L,a,b) \
0341 ((void)L, (b == 2) ? (a)*(a) : l_mathop(pow)(a,b))
0342 #endif
0343
0344
0345 #if !defined(luai_numadd)
0346 #define luai_numadd(L,a,b) ((a)+(b))
0347 #define luai_numsub(L,a,b) ((a)-(b))
0348 #define luai_nummul(L,a,b) ((a)*(b))
0349 #define luai_numunm(L,a) (-(a))
0350 #define luai_numeq(a,b) ((a)==(b))
0351 #define luai_numlt(a,b) ((a)<(b))
0352 #define luai_numle(a,b) ((a)<=(b))
0353 #define luai_numgt(a,b) ((a)>(b))
0354 #define luai_numge(a,b) ((a)>=(b))
0355 #define luai_numisnan(a) (!luai_numeq((a), (a)))
0356 #endif
0357
0358
0359
0360
0361
0362
0363
0364
0365 #if !defined(HARDSTACKTESTS)
0366 #define condmovestack(L,pre,pos) ((void)0)
0367 #else
0368
0369 #define condmovestack(L,pre,pos) \
0370 { int sz_ = stacksize(L); pre; luaD_reallocstack((L), sz_, 0); pos; }
0371 #endif
0372
0373 #if !defined(HARDMEMTESTS)
0374 #define condchangemem(L,pre,pos) ((void)0)
0375 #else
0376 #define condchangemem(L,pre,pos) \
0377 { if (gcrunning(G(L))) { pre; luaC_fullgc(L, 0); pos; } }
0378 #endif
0379
0380 #endif