diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-06-20 13:43:33 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-06-20 13:43:33 -0300 |
commit | 55ac40f859ad8e28fe71a8801d49f4a4140e8aa3 (patch) | |
tree | 1a1f02de45d28c7eb8976087ade773d7937bed14 | |
parent | 97ef8e7bd40340d47a9789beb06f0128d7438d0a (diff) | |
download | lua-55ac40f859ad8e28fe71a8801d49f4a4140e8aa3.tar.gz lua-55ac40f859ad8e28fe71a8801d49f4a4140e8aa3.tar.bz2 lua-55ac40f859ad8e28fe71a8801d49f4a4140e8aa3.zip |
Cleaning of llimits.h
Several definitions that don't need to be "global" (that is, that
concerns only specific parts of the code) moved out of llimits.h,
to more appropriate places.
-rw-r--r-- | lapi.h | 20 | ||||
-rw-r--r-- | lcode.c | 6 | ||||
-rw-r--r-- | ldo.c | 13 | ||||
-rw-r--r-- | ldo.h | 21 | ||||
-rw-r--r-- | ldump.c | 1 | ||||
-rw-r--r-- | lgc.h | 8 | ||||
-rw-r--r-- | llex.c | 7 | ||||
-rw-r--r-- | llimits.h | 144 | ||||
-rw-r--r-- | lobject.h | 3 | ||||
-rw-r--r-- | lopcodes.h | 6 | ||||
-rw-r--r-- | lparser.c | 2 | ||||
-rw-r--r-- | lstate.c | 21 | ||||
-rw-r--r-- | lstate.h | 11 | ||||
-rw-r--r-- | lstring.c | 16 | ||||
-rw-r--r-- | lstring.h | 11 | ||||
-rw-r--r-- | luaconf.h | 5 | ||||
-rw-r--r-- | lvm.c | 9 | ||||
-rw-r--r-- | lzio.c | 1 | ||||
-rw-r--r-- | makefile | 19 |
19 files changed, 159 insertions, 165 deletions
@@ -12,12 +12,32 @@ | |||
12 | #include "lstate.h" | 12 | #include "lstate.h" |
13 | 13 | ||
14 | 14 | ||
15 | #if defined(LUA_USE_APICHECK) | ||
16 | #include <assert.h> | ||
17 | #define api_check(l,e,msg) assert(e) | ||
18 | #else /* for testing */ | ||
19 | #define api_check(l,e,msg) ((void)(l), lua_assert((e) && msg)) | ||
20 | #endif | ||
21 | |||
22 | |||
23 | |||
15 | /* Increments 'L->top.p', checking for stack overflows */ | 24 | /* Increments 'L->top.p', checking for stack overflows */ |
16 | #define api_incr_top(L) \ | 25 | #define api_incr_top(L) \ |
17 | (L->top.p++, api_check(L, L->top.p <= L->ci->top.p, "stack overflow")) | 26 | (L->top.p++, api_check(L, L->top.p <= L->ci->top.p, "stack overflow")) |
18 | 27 | ||
19 | 28 | ||
20 | /* | 29 | /* |
30 | ** macros that are executed whenever program enters the Lua core | ||
31 | ** ('lua_lock') and leaves the core ('lua_unlock') | ||
32 | */ | ||
33 | #if !defined(lua_lock) | ||
34 | #define lua_lock(L) ((void) 0) | ||
35 | #define lua_unlock(L) ((void) 0) | ||
36 | #endif | ||
37 | |||
38 | |||
39 | |||
40 | /* | ||
21 | ** If a call returns too many multiple returns, the callee may not have | 41 | ** If a call returns too many multiple returns, the callee may not have |
22 | ** stack space to accommodate all results. In this case, this macro | 42 | ** stack space to accommodate all results. In this case, this macro |
23 | ** increases its stack space ('L->ci->top.p'). | 43 | ** increases its stack space ('L->ci->top.p'). |
@@ -331,14 +331,14 @@ static void savelineinfo (FuncState *fs, Proto *f, int line) { | |||
331 | int pc = fs->pc - 1; /* last instruction coded */ | 331 | int pc = fs->pc - 1; /* last instruction coded */ |
332 | if (abs(linedif) >= LIMLINEDIFF || fs->iwthabs++ >= MAXIWTHABS) { | 332 | if (abs(linedif) >= LIMLINEDIFF || fs->iwthabs++ >= MAXIWTHABS) { |
333 | luaM_growvector(fs->ls->L, f->abslineinfo, fs->nabslineinfo, | 333 | luaM_growvector(fs->ls->L, f->abslineinfo, fs->nabslineinfo, |
334 | f->sizeabslineinfo, AbsLineInfo, MAX_INT, "lines"); | 334 | f->sizeabslineinfo, AbsLineInfo, INT_MAX, "lines"); |
335 | f->abslineinfo[fs->nabslineinfo].pc = pc; | 335 | f->abslineinfo[fs->nabslineinfo].pc = pc; |
336 | f->abslineinfo[fs->nabslineinfo++].line = line; | 336 | f->abslineinfo[fs->nabslineinfo++].line = line; |
337 | linedif = ABSLINEINFO; /* signal that there is absolute information */ | 337 | linedif = ABSLINEINFO; /* signal that there is absolute information */ |
338 | fs->iwthabs = 1; /* restart counter */ | 338 | fs->iwthabs = 1; /* restart counter */ |
339 | } | 339 | } |
340 | luaM_growvector(fs->ls->L, f->lineinfo, pc, f->sizelineinfo, ls_byte, | 340 | luaM_growvector(fs->ls->L, f->lineinfo, pc, f->sizelineinfo, ls_byte, |
341 | MAX_INT, "opcodes"); | 341 | INT_MAX, "opcodes"); |
342 | f->lineinfo[pc] = linedif; | 342 | f->lineinfo[pc] = linedif; |
343 | fs->previousline = line; /* last line saved */ | 343 | fs->previousline = line; /* last line saved */ |
344 | } | 344 | } |
@@ -383,7 +383,7 @@ int luaK_code (FuncState *fs, Instruction i) { | |||
383 | Proto *f = fs->f; | 383 | Proto *f = fs->f; |
384 | /* put new instruction in code array */ | 384 | /* put new instruction in code array */ |
385 | luaM_growvector(fs->ls->L, f->code, fs->pc, f->sizecode, Instruction, | 385 | luaM_growvector(fs->ls->L, f->code, fs->pc, f->sizecode, Instruction, |
386 | MAX_INT, "opcodes"); | 386 | INT_MAX, "opcodes"); |
387 | f->code[fs->pc++] = i; | 387 | f->code[fs->pc++] = i; |
388 | savelineinfo(fs, f, fs->ls->lastline); | 388 | savelineinfo(fs, f, fs->ls->lastline); |
389 | return fs->pc - 1; /* index of new instruction */ | 389 | return fs->pc - 1; /* index of new instruction */ |
@@ -39,6 +39,19 @@ | |||
39 | 39 | ||
40 | 40 | ||
41 | /* | 41 | /* |
42 | ** these macros allow user-specific actions when a thread is | ||
43 | ** resumed/yielded. | ||
44 | */ | ||
45 | #if !defined(luai_userstateresume) | ||
46 | #define luai_userstateresume(L,n) ((void)L) | ||
47 | #endif | ||
48 | |||
49 | #if !defined(luai_userstateyield) | ||
50 | #define luai_userstateyield(L,n) ((void)L) | ||
51 | #endif | ||
52 | |||
53 | |||
54 | /* | ||
42 | ** {====================================================== | 55 | ** {====================================================== |
43 | ** Error-recovery functions | 56 | ** Error-recovery functions |
44 | ** ======================================================= | 57 | ** ======================================================= |
@@ -23,10 +23,19 @@ | |||
23 | ** 'condmovestack' is used in heavy tests to force a stack reallocation | 23 | ** 'condmovestack' is used in heavy tests to force a stack reallocation |
24 | ** at every check. | 24 | ** at every check. |
25 | */ | 25 | */ |
26 | |||
27 | #if !defined(HARDSTACKTESTS) | ||
28 | #define condmovestack(L,pre,pos) ((void)0) | ||
29 | #else | ||
30 | /* realloc stack keeping its size */ | ||
31 | #define condmovestack(L,pre,pos) \ | ||
32 | { int sz_ = stacksize(L); pre; luaD_reallocstack((L), sz_, 0); pos; } | ||
33 | #endif | ||
34 | |||
26 | #define luaD_checkstackaux(L,n,pre,pos) \ | 35 | #define luaD_checkstackaux(L,n,pre,pos) \ |
27 | if (l_unlikely(L->stack_last.p - L->top.p <= (n))) \ | 36 | if (l_unlikely(L->stack_last.p - L->top.p <= (n))) \ |
28 | { pre; luaD_growstack(L, n, 1); pos; } \ | 37 | { pre; luaD_growstack(L, n, 1); pos; } \ |
29 | else { condmovestack(L,pre,pos); } | 38 | else { condmovestack(L,pre,pos); } |
30 | 39 | ||
31 | /* In general, 'pre'/'pos' are empty (nothing to save) */ | 40 | /* In general, 'pre'/'pos' are empty (nothing to save) */ |
32 | #define luaD_checkstack(L,n) luaD_checkstackaux(L,n,(void)0,(void)0) | 41 | #define luaD_checkstack(L,n) luaD_checkstackaux(L,n,(void)0,(void)0) |
@@ -44,6 +53,16 @@ | |||
44 | p = restorestack(L, t__)) /* 'pos' part: restore 'p' */ | 53 | p = restorestack(L, t__)) /* 'pos' part: restore 'p' */ |
45 | 54 | ||
46 | 55 | ||
56 | /* | ||
57 | ** Maximum depth for nested C calls, syntactical nested non-terminals, | ||
58 | ** and other features implemented through recursion in C. (Value must | ||
59 | ** fit in a 16-bit unsigned integer. It must also be compatible with | ||
60 | ** the size of the C stack.) | ||
61 | */ | ||
62 | #if !defined(LUAI_MAXCCALLS) | ||
63 | #define LUAI_MAXCCALLS 200 | ||
64 | #endif | ||
65 | |||
47 | 66 | ||
48 | /* type of protected functions, to be ran by 'runprotected' */ | 67 | /* type of protected functions, to be ran by 'runprotected' */ |
49 | typedef void (*Pfunc) (lua_State *L, void *ud); | 68 | typedef void (*Pfunc) (lua_State *L, void *ud); |
@@ -15,6 +15,7 @@ | |||
15 | 15 | ||
16 | #include "lua.h" | 16 | #include "lua.h" |
17 | 17 | ||
18 | #include "lapi.h" | ||
18 | #include "lgc.h" | 19 | #include "lgc.h" |
19 | #include "lobject.h" | 20 | #include "lobject.h" |
20 | #include "lstate.h" | 21 | #include "lstate.h" |
@@ -211,6 +211,14 @@ | |||
211 | ** 'condchangemem' is used only for heavy tests (forcing a full | 211 | ** 'condchangemem' is used only for heavy tests (forcing a full |
212 | ** GC cycle on every opportunity) | 212 | ** GC cycle on every opportunity) |
213 | */ | 213 | */ |
214 | |||
215 | #if !defined(HARDMEMTESTS) | ||
216 | #define condchangemem(L,pre,pos) ((void)0) | ||
217 | #else | ||
218 | #define condchangemem(L,pre,pos) \ | ||
219 | { if (gcrunning(G(L))) { pre; luaC_fullgc(L, 0); pos; } } | ||
220 | #endif | ||
221 | |||
214 | #define luaC_condGC(L,pre,pos) \ | 222 | #define luaC_condGC(L,pre,pos) \ |
215 | { if (G(L)->GCdebt <= 0) { pre; luaC_step(L); pos;}; \ | 223 | { if (G(L)->GCdebt <= 0) { pre; luaC_step(L); pos;}; \ |
216 | condchangemem(L,pre,pos); } | 224 | condchangemem(L,pre,pos); } |
@@ -32,6 +32,11 @@ | |||
32 | #define next(ls) (ls->current = zgetc(ls->z)) | 32 | #define next(ls) (ls->current = zgetc(ls->z)) |
33 | 33 | ||
34 | 34 | ||
35 | /* minimum size for string buffer */ | ||
36 | #if !defined(LUA_MINBUFFER) | ||
37 | #define LUA_MINBUFFER 32 | ||
38 | #endif | ||
39 | |||
35 | 40 | ||
36 | #define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r') | 41 | #define currIsNewline(ls) (ls->current == '\n' || ls->current == '\r') |
37 | 42 | ||
@@ -159,7 +164,7 @@ static void inclinenumber (LexState *ls) { | |||
159 | next(ls); /* skip '\n' or '\r' */ | 164 | next(ls); /* skip '\n' or '\r' */ |
160 | if (currIsNewline(ls) && ls->current != old) | 165 | if (currIsNewline(ls) && ls->current != old) |
161 | next(ls); /* skip '\n\r' or '\r\n' */ | 166 | next(ls); /* skip '\n\r' or '\r\n' */ |
162 | if (++ls->linenumber >= MAX_INT) | 167 | if (++ls->linenumber >= INT_MAX) |
163 | lexerror(ls, "chunk has too many lines", 0); | 168 | lexerror(ls, "chunk has too many lines", 0); |
164 | } | 169 | } |
165 | 170 | ||
@@ -46,15 +46,11 @@ typedef signed char ls_byte; | |||
46 | #define MAX_SIZET ((size_t)(~(size_t)0)) | 46 | #define MAX_SIZET ((size_t)(~(size_t)0)) |
47 | 47 | ||
48 | /* | 48 | /* |
49 | ** Maximum size for strings and userdata visible for Lua (should be | 49 | ** Maximum size for strings and userdata visible for Lua; should be |
50 | ** representable in a lua_Integer) | 50 | ** representable as a lua_Integer and as a size_t. |
51 | */ | 51 | */ |
52 | #define MAX_SIZE (sizeof(size_t) < sizeof(lua_Integer) ? MAX_SIZET \ | 52 | #define MAX_SIZE (sizeof(size_t) < sizeof(lua_Integer) ? MAX_SIZET \ |
53 | : (size_t)(LUA_MAXINTEGER)) | 53 | : cast_sizet(LUA_MAXINTEGER)) |
54 | |||
55 | |||
56 | #define MAX_INT INT_MAX /* maximum value of an int */ | ||
57 | |||
58 | 54 | ||
59 | /* | 55 | /* |
60 | ** floor of the log2 of the maximum signed value for integral type 't'. | 56 | ** floor of the log2 of the maximum signed value for integral type 't'. |
@@ -119,15 +115,6 @@ typedef LUAI_UACINT l_uacInt; | |||
119 | #define lua_longassert(c) ((void)0) | 115 | #define lua_longassert(c) ((void)0) |
120 | #endif | 116 | #endif |
121 | 117 | ||
122 | /* | ||
123 | ** assertion for checking API calls | ||
124 | */ | ||
125 | #if !defined(luai_apicheck) | ||
126 | #define luai_apicheck(l,e) ((void)l, lua_assert(e)) | ||
127 | #endif | ||
128 | |||
129 | #define api_check(l,e,msg) luai_apicheck(l,(e) && msg) | ||
130 | |||
131 | 118 | ||
132 | /* macro to avoid warnings about unused variables */ | 119 | /* macro to avoid warnings about unused variables */ |
133 | #if !defined(UNUSED) | 120 | #if !defined(UNUSED) |
@@ -196,8 +183,7 @@ typedef LUAI_UACINT l_uacInt; | |||
196 | 183 | ||
197 | 184 | ||
198 | /* | 185 | /* |
199 | ** type for virtual-machine instructions; | 186 | ** An unsigned with (at least) 4 bytes |
200 | ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) | ||
201 | */ | 187 | */ |
202 | #if LUAI_IS32INT | 188 | #if LUAI_IS32INT |
203 | typedef unsigned int l_uint32; | 189 | typedef unsigned int l_uint32; |
@@ -205,107 +191,6 @@ typedef unsigned int l_uint32; | |||
205 | typedef unsigned long l_uint32; | 191 | typedef unsigned long l_uint32; |
206 | #endif | 192 | #endif |
207 | 193 | ||
208 | typedef l_uint32 Instruction; | ||
209 | |||
210 | |||
211 | |||
212 | /* | ||
213 | ** Maximum length for short strings, that is, strings that are | ||
214 | ** internalized. (Cannot be smaller than reserved words or tags for | ||
215 | ** metamethods, as these strings must be internalized; | ||
216 | ** #("function") = 8, #("__newindex") = 10.) | ||
217 | */ | ||
218 | #if !defined(LUAI_MAXSHORTLEN) | ||
219 | #define LUAI_MAXSHORTLEN 40 | ||
220 | #endif | ||
221 | |||
222 | |||
223 | /* | ||
224 | ** Initial size for the string table (must be power of 2). | ||
225 | ** The Lua core alone registers ~50 strings (reserved words + | ||
226 | ** metaevent keys + a few others). Libraries would typically add | ||
227 | ** a few dozens more. | ||
228 | */ | ||
229 | #if !defined(MINSTRTABSIZE) | ||
230 | #define MINSTRTABSIZE 128 | ||
231 | #endif | ||
232 | |||
233 | |||
234 | /* | ||
235 | ** Size of cache for strings in the API. 'N' is the number of | ||
236 | ** sets (better be a prime) and "M" is the size of each set (M == 1 | ||
237 | ** makes a direct cache.) | ||
238 | */ | ||
239 | #if !defined(STRCACHE_N) | ||
240 | #define STRCACHE_N 53 | ||
241 | #define STRCACHE_M 2 | ||
242 | #endif | ||
243 | |||
244 | |||
245 | /* minimum size for string buffer */ | ||
246 | #if !defined(LUA_MINBUFFER) | ||
247 | #define LUA_MINBUFFER 32 | ||
248 | #endif | ||
249 | |||
250 | |||
251 | /* | ||
252 | ** Maximum depth for nested C calls, syntactical nested non-terminals, | ||
253 | ** and other features implemented through recursion in C. (Value must | ||
254 | ** fit in a 16-bit unsigned integer. It must also be compatible with | ||
255 | ** the size of the C stack.) | ||
256 | */ | ||
257 | #if !defined(LUAI_MAXCCALLS) | ||
258 | #define LUAI_MAXCCALLS 200 | ||
259 | #endif | ||
260 | |||
261 | |||
262 | /* | ||
263 | ** macros that are executed whenever program enters the Lua core | ||
264 | ** ('lua_lock') and leaves the core ('lua_unlock') | ||
265 | */ | ||
266 | #if !defined(lua_lock) | ||
267 | #define lua_lock(L) ((void) 0) | ||
268 | #define lua_unlock(L) ((void) 0) | ||
269 | #endif | ||
270 | |||
271 | /* | ||
272 | ** macro executed during Lua functions at points where the | ||
273 | ** function can yield. | ||
274 | */ | ||
275 | #if !defined(luai_threadyield) | ||
276 | #define luai_threadyield(L) {lua_unlock(L); lua_lock(L);} | ||
277 | #endif | ||
278 | |||
279 | |||
280 | /* | ||
281 | ** these macros allow user-specific actions when a thread is | ||
282 | ** created/deleted/resumed/yielded. | ||
283 | */ | ||
284 | #if !defined(luai_userstateopen) | ||
285 | #define luai_userstateopen(L) ((void)L) | ||
286 | #endif | ||
287 | |||
288 | #if !defined(luai_userstateclose) | ||
289 | #define luai_userstateclose(L) ((void)L) | ||
290 | #endif | ||
291 | |||
292 | #if !defined(luai_userstatethread) | ||
293 | #define luai_userstatethread(L,L1) ((void)L) | ||
294 | #endif | ||
295 | |||
296 | #if !defined(luai_userstatefree) | ||
297 | #define luai_userstatefree(L,L1) ((void)L) | ||
298 | #endif | ||
299 | |||
300 | #if !defined(luai_userstateresume) | ||
301 | #define luai_userstateresume(L,n) ((void)L) | ||
302 | #endif | ||
303 | |||
304 | #if !defined(luai_userstateyield) | ||
305 | #define luai_userstateyield(L,n) ((void)L) | ||
306 | #endif | ||
307 | |||
308 | |||
309 | 194 | ||
310 | /* | 195 | /* |
311 | ** The luai_num* macros define the primitive operations over numbers. | 196 | ** The luai_num* macros define the primitive operations over numbers. |
@@ -359,25 +244,4 @@ typedef l_uint32 Instruction; | |||
359 | #endif | 244 | #endif |
360 | 245 | ||
361 | 246 | ||
362 | |||
363 | |||
364 | |||
365 | /* | ||
366 | ** macro to control inclusion of some hard tests on stack reallocation | ||
367 | */ | ||
368 | #if !defined(HARDSTACKTESTS) | ||
369 | #define condmovestack(L,pre,pos) ((void)0) | ||
370 | #else | ||
371 | /* realloc stack keeping its size */ | ||
372 | #define condmovestack(L,pre,pos) \ | ||
373 | { int sz_ = stacksize(L); pre; luaD_reallocstack((L), sz_, 0); pos; } | ||
374 | #endif | ||
375 | |||
376 | #if !defined(HARDMEMTESTS) | ||
377 | #define condchangemem(L,pre,pos) ((void)0) | ||
378 | #else | ||
379 | #define condchangemem(L,pre,pos) \ | ||
380 | { if (gcrunning(G(L))) { pre; luaC_fullgc(L, 0); pos; } } | ||
381 | #endif | ||
382 | |||
383 | #endif | 247 | #endif |
@@ -538,6 +538,9 @@ typedef struct Udata0 { | |||
538 | #define LUA_VPROTO makevariant(LUA_TPROTO, 0) | 538 | #define LUA_VPROTO makevariant(LUA_TPROTO, 0) |
539 | 539 | ||
540 | 540 | ||
541 | typedef l_uint32 Instruction; | ||
542 | |||
543 | |||
541 | /* | 544 | /* |
542 | ** Description of an upvalue for function prototypes | 545 | ** Description of an upvalue for function prototypes |
543 | */ | 546 | */ |
@@ -71,7 +71,7 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */ | |||
71 | #if L_INTHASBITS(SIZE_Bx) | 71 | #if L_INTHASBITS(SIZE_Bx) |
72 | #define MAXARG_Bx ((1<<SIZE_Bx)-1) | 72 | #define MAXARG_Bx ((1<<SIZE_Bx)-1) |
73 | #else | 73 | #else |
74 | #define MAXARG_Bx MAX_INT | 74 | #define MAXARG_Bx INT_MAX |
75 | #endif | 75 | #endif |
76 | 76 | ||
77 | #define OFFSET_sBx (MAXARG_Bx>>1) /* 'sBx' is signed */ | 77 | #define OFFSET_sBx (MAXARG_Bx>>1) /* 'sBx' is signed */ |
@@ -80,13 +80,13 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */ | |||
80 | #if L_INTHASBITS(SIZE_Ax) | 80 | #if L_INTHASBITS(SIZE_Ax) |
81 | #define MAXARG_Ax ((1<<SIZE_Ax)-1) | 81 | #define MAXARG_Ax ((1<<SIZE_Ax)-1) |
82 | #else | 82 | #else |
83 | #define MAXARG_Ax MAX_INT | 83 | #define MAXARG_Ax INT_MAX |
84 | #endif | 84 | #endif |
85 | 85 | ||
86 | #if L_INTHASBITS(SIZE_sJ) | 86 | #if L_INTHASBITS(SIZE_sJ) |
87 | #define MAXARG_sJ ((1 << SIZE_sJ) - 1) | 87 | #define MAXARG_sJ ((1 << SIZE_sJ) - 1) |
88 | #else | 88 | #else |
89 | #define MAXARG_sJ MAX_INT | 89 | #define MAXARG_sJ INT_MAX |
90 | #endif | 90 | #endif |
91 | 91 | ||
92 | #define OFFSET_sJ (MAXARG_sJ >> 1) | 92 | #define OFFSET_sJ (MAXARG_sJ >> 1) |
@@ -859,7 +859,7 @@ static void recfield (LexState *ls, ConsControl *cc) { | |||
859 | int reg = ls->fs->freereg; | 859 | int reg = ls->fs->freereg; |
860 | expdesc tab, key, val; | 860 | expdesc tab, key, val; |
861 | if (ls->t.token == TK_NAME) { | 861 | if (ls->t.token == TK_NAME) { |
862 | checklimit(fs, cc->nh, MAX_INT, "items in a constructor"); | 862 | checklimit(fs, cc->nh, INT_MAX, "items in a constructor"); |
863 | codename(ls, &key); | 863 | codename(ls, &key); |
864 | } | 864 | } |
865 | else /* ls->t.token == '[' */ | 865 | else /* ls->t.token == '[' */ |
@@ -52,6 +52,27 @@ typedef struct LG { | |||
52 | 52 | ||
53 | 53 | ||
54 | /* | 54 | /* |
55 | ** these macros allow user-specific actions when a thread is | ||
56 | ** created/deleted | ||
57 | */ | ||
58 | #if !defined(luai_userstateopen) | ||
59 | #define luai_userstateopen(L) ((void)L) | ||
60 | #endif | ||
61 | |||
62 | #if !defined(luai_userstateclose) | ||
63 | #define luai_userstateclose(L) ((void)L) | ||
64 | #endif | ||
65 | |||
66 | #if !defined(luai_userstatethread) | ||
67 | #define luai_userstatethread(L,L1) ((void)L) | ||
68 | #endif | ||
69 | |||
70 | #if !defined(luai_userstatefree) | ||
71 | #define luai_userstatefree(L,L1) ((void)L) | ||
72 | #endif | ||
73 | |||
74 | |||
75 | /* | ||
55 | ** set GCdebt to a new value keeping the real number of allocated | 76 | ** set GCdebt to a new value keeping the real number of allocated |
56 | ** objects (totalobjs - GCdebt) invariant and avoiding overflows in | 77 | ** objects (totalobjs - GCdebt) invariant and avoiding overflows in |
57 | ** 'totalobjs'. | 78 | ** 'totalobjs'. |
@@ -142,6 +142,17 @@ struct lua_longjmp; /* defined in ldo.c */ | |||
142 | #define EXTRA_STACK 5 | 142 | #define EXTRA_STACK 5 |
143 | 143 | ||
144 | 144 | ||
145 | /* | ||
146 | ** Size of cache for strings in the API. 'N' is the number of | ||
147 | ** sets (better be a prime) and "M" is the size of each set. | ||
148 | ** (M == 1 makes a direct cache.) | ||
149 | */ | ||
150 | #if !defined(STRCACHE_N) | ||
151 | #define STRCACHE_N 53 | ||
152 | #define STRCACHE_M 2 | ||
153 | #endif | ||
154 | |||
155 | |||
145 | #define BASIC_STACK_SIZE (2*LUA_MINSTACK) | 156 | #define BASIC_STACK_SIZE (2*LUA_MINSTACK) |
146 | 157 | ||
147 | #define stacksize(th) cast_int((th)->stack_last.p - (th)->stack.p) | 158 | #define stacksize(th) cast_int((th)->stack_last.p - (th)->stack.p) |
@@ -25,7 +25,17 @@ | |||
25 | /* | 25 | /* |
26 | ** Maximum size for string table. | 26 | ** Maximum size for string table. |
27 | */ | 27 | */ |
28 | #define MAXSTRTB cast_int(luaM_limitN(MAX_INT, TString*)) | 28 | #define MAXSTRTB cast_int(luaM_limitN(INT_MAX, TString*)) |
29 | |||
30 | /* | ||
31 | ** Initial size for the string table (must be power of 2). | ||
32 | ** The Lua core alone registers ~50 strings (reserved words + | ||
33 | ** metaevent keys + a few others). Libraries would typically add | ||
34 | ** a few dozens more. | ||
35 | */ | ||
36 | #if !defined(MINSTRTABSIZE) | ||
37 | #define MINSTRTABSIZE 128 | ||
38 | #endif | ||
29 | 39 | ||
30 | 40 | ||
31 | /* | 41 | /* |
@@ -188,9 +198,9 @@ void luaS_remove (lua_State *L, TString *ts) { | |||
188 | 198 | ||
189 | 199 | ||
190 | static void growstrtab (lua_State *L, stringtable *tb) { | 200 | static void growstrtab (lua_State *L, stringtable *tb) { |
191 | if (l_unlikely(tb->nuse == MAX_INT)) { /* too many strings? */ | 201 | if (l_unlikely(tb->nuse == INT_MAX)) { /* too many strings? */ |
192 | luaC_fullgc(L, 1); /* try to free some... */ | 202 | luaC_fullgc(L, 1); /* try to free some... */ |
193 | if (tb->nuse == MAX_INT) /* still too many? */ | 203 | if (tb->nuse == INT_MAX) /* still too many? */ |
194 | luaM_error(L); /* cannot even create a message... */ | 204 | luaM_error(L); /* cannot even create a message... */ |
195 | } | 205 | } |
196 | if (tb->size <= MAXSTRTB / 2) /* can grow string table? */ | 206 | if (tb->size <= MAXSTRTB / 2) /* can grow string table? */ |
@@ -20,6 +20,17 @@ | |||
20 | 20 | ||
21 | 21 | ||
22 | /* | 22 | /* |
23 | ** Maximum length for short strings, that is, strings that are | ||
24 | ** internalized. (Cannot be smaller than reserved words or tags for | ||
25 | ** metamethods, as these strings must be internalized; | ||
26 | ** #("function") = 8, #("__newindex") = 10.) | ||
27 | */ | ||
28 | #if !defined(LUAI_MAXSHORTLEN) | ||
29 | #define LUAI_MAXSHORTLEN 40 | ||
30 | #endif | ||
31 | |||
32 | |||
33 | /* | ||
23 | ** Size of a short TString: Size of the header plus space for the string | 34 | ** Size of a short TString: Size of the header plus space for the string |
24 | ** itself (including final '\0'). | 35 | ** itself (including final '\0'). |
25 | */ | 36 | */ |
@@ -722,10 +722,7 @@ | |||
722 | @@ LUA_USE_APICHECK turns on several consistency checks on the C API. | 722 | @@ LUA_USE_APICHECK turns on several consistency checks on the C API. |
723 | ** Define it as a help when debugging C code. | 723 | ** Define it as a help when debugging C code. |
724 | */ | 724 | */ |
725 | #if defined(LUA_USE_APICHECK) | 725 | /* #define LUA_USE_APICHECK */ |
726 | #include <assert.h> | ||
727 | #define luai_apicheck(l,e) assert(e) | ||
728 | #endif | ||
729 | 726 | ||
730 | /* }================================================================== */ | 727 | /* }================================================================== */ |
731 | 728 | ||
@@ -18,6 +18,7 @@ | |||
18 | 18 | ||
19 | #include "lua.h" | 19 | #include "lua.h" |
20 | 20 | ||
21 | #include "lapi.h" | ||
21 | #include "ldebug.h" | 22 | #include "ldebug.h" |
22 | #include "ldo.h" | 23 | #include "ldo.h" |
23 | #include "lfunc.h" | 24 | #include "lfunc.h" |
@@ -1122,6 +1123,14 @@ void luaV_finishOp (lua_State *L) { | |||
1122 | */ | 1123 | */ |
1123 | #define halfProtect(exp) (savestate(L,ci), (exp)) | 1124 | #define halfProtect(exp) (savestate(L,ci), (exp)) |
1124 | 1125 | ||
1126 | /* | ||
1127 | ** macro executed during Lua functions at points where the | ||
1128 | ** function can yield. | ||
1129 | */ | ||
1130 | #if !defined(luai_threadyield) | ||
1131 | #define luai_threadyield(L) {lua_unlock(L); lua_lock(L);} | ||
1132 | #endif | ||
1133 | |||
1125 | /* 'c' is the limit of live values in the stack */ | 1134 | /* 'c' is the limit of live values in the stack */ |
1126 | #define checkGC(L,c) \ | 1135 | #define checkGC(L,c) \ |
1127 | { luaC_condGC(L, (savepc(L), L->top.p = (c)), \ | 1136 | { luaC_condGC(L, (savepc(L), L->top.p = (c)), \ |
@@ -14,6 +14,7 @@ | |||
14 | 14 | ||
15 | #include "lua.h" | 15 | #include "lua.h" |
16 | 16 | ||
17 | #include "lapi.h" | ||
17 | #include "llimits.h" | 18 | #include "llimits.h" |
18 | #include "lmem.h" | 19 | #include "lmem.h" |
19 | #include "lstate.h" | 20 | #include "lstate.h" |
@@ -158,12 +158,13 @@ ldebug.o: ldebug.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ | |||
158 | ldo.o: ldo.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ | 158 | ldo.o: ldo.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ |
159 | lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lopcodes.h \ | 159 | lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lopcodes.h \ |
160 | lparser.h lstring.h ltable.h lundump.h lvm.h | 160 | lparser.h lstring.h ltable.h lundump.h lvm.h |
161 | ldump.o: ldump.c lprefix.h lua.h luaconf.h lobject.h llimits.h lstate.h \ | 161 | ldump.o: ldump.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ |
162 | ltm.h lzio.h lmem.h lundump.h | 162 | lobject.h ltm.h lzio.h lmem.h lgc.h ltable.h lundump.h |
163 | lfunc.o: lfunc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ | 163 | lfunc.o: lfunc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ |
164 | llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h | 164 | llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h |
165 | lgc.o: lgc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ | 165 | lgc.o: lgc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ |
166 | llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h | 166 | llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h llex.h lstring.h \ |
167 | ltable.h | ||
167 | linit.o: linit.c lprefix.h lua.h luaconf.h lualib.h lauxlib.h | 168 | linit.o: linit.c lprefix.h lua.h luaconf.h lualib.h lauxlib.h |
168 | liolib.o: liolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h | 169 | liolib.o: liolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h |
169 | llex.o: llex.c lprefix.h lua.h luaconf.h lctype.h llimits.h ldebug.h \ | 170 | llex.o: llex.c lprefix.h lua.h luaconf.h lctype.h llimits.h ldebug.h \ |
@@ -199,12 +200,12 @@ ltm.o: ltm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ | |||
199 | lua.o: lua.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h | 200 | lua.o: lua.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h |
200 | lundump.o: lundump.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \ | 201 | lundump.o: lundump.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \ |
201 | lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h \ | 202 | lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h \ |
202 | lundump.h | 203 | ltable.h lundump.h |
203 | lutf8lib.o: lutf8lib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h | 204 | lutf8lib.o: lutf8lib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h |
204 | lvm.o: lvm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ | 205 | lvm.o: lvm.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ |
205 | llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h \ | 206 | lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lopcodes.h \ |
206 | ltable.h lvm.h ljumptab.h | 207 | lstring.h ltable.h lvm.h ljumptab.h |
207 | lzio.o: lzio.c lprefix.h lua.h luaconf.h llimits.h lmem.h lstate.h \ | 208 | lzio.o: lzio.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ |
208 | lobject.h ltm.h lzio.h | 209 | lobject.h ltm.h lzio.h lmem.h |
209 | 210 | ||
210 | # (end of Makefile) | 211 | # (end of Makefile) |