History

Lua 5.0.1

Lua Team committed 22 years ago

Commit a985bf41 parent 488a64b15 files · +822 −155Browse files

Showing the changes to src (9 of 15 files). Show all

Unified · Split

9 files
  1. src/ldo.c +19 −6
  2. src/lgc.c +14 −9
  3. src/lgc.h +2 −2
  4. src/lib/lbaselib.c +2 −2
  5. src/lib/liolib.c +3 −3
  6. src/lparser.c +7 −3
  7. src/luac/Makefile +1 −1
  8. src/luac/luac.c +3 −1
  9. src/lvm.c +4 −6
src/ldo.c+19−6
@@ -1,5 +1,5 @@
11 /*
2−** $Id: ldo.c,v 1.217 2003/04/03 13:35:34 roberto Exp $
2+** $Id: ldo.c,v 1.217a 2003/04/03 13:35:34 roberto Exp $
33 ** Stack and Call structure of Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -322,11 +322,11 @@ static void resume (lua_State *L, void *ud) { · 316 unmodified lines
322322 int nargs = *cast(int *, ud);
323323 CallInfo *ci = L->ci;
324324 if (ci == L->base_ci) { /* no activation record? */
325− if (nargs >= L->top - L->base)
326− luaG_runerror(L, "cannot resume dead coroutine");
325+ lua_assert(nargs < L->top - L->base);
327326 luaD_precall(L, L->top - (nargs + 1)); /* start coroutine */
328327 }
329− else if (ci->state & CI_YIELD) { /* inside a yield? */
328+ else { /* inside a yield */
329+ lua_assert(ci->state & CI_YIELD);
330330 if (ci->state & CI_C) { /* `common' yield? */
331331 /* finish interrupted execution of `OP_CALL' */
332332 int nresults;
@@ -341,18 +341,31 @@ static void resume (lua_State *L, void *ud) { · 8 unmodified lines
341341 ci->state &= ~CI_YIELD;
342342 }
343343 }
344− else
345− luaG_runerror(L, "cannot resume non-suspended coroutine");
346344 firstResult = luaV_execute(L);
347345 if (firstResult != NULL) /* return? */
348346 luaD_poscall(L, LUA_MULTRET, firstResult); /* finalize this coroutine */
349347 }
350348
351349
350+static int resume_error (lua_State *L, const char *msg) {
351+ L->top = L->ci->base;
352+ setsvalue2s(L->top, luaS_new(L, msg));
353+ incr_top(L);
354+ lua_unlock(L);
355+ return LUA_ERRRUN;
356+}
357+
358+
352359 LUA_API int lua_resume (lua_State *L, int nargs) {
353360 int status;
354361 lu_byte old_allowhooks;
355362 lua_lock(L);
363+ if (L->ci == L->base_ci) {
364+ if (nargs >= L->top - L->base)
365+ return resume_error(L, "cannot resume dead coroutine");
366+ }
367+ else if (!(L->ci->state & CI_YIELD)) /* not inside a yield? */
368+ return resume_error(L, "cannot resume non-suspended coroutine");
356369 old_allowhooks = L->allowhook;
357370 lua_assert(L->errfunc == 0 && L->nCcalls == 0);
358371 status = luaD_rawrunprotected(L, resume, &nargs);
src/lgc.c+14−9
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lgc.c,v 1.171 2003/04/03 13:35:34 roberto Exp $
2+** $Id: lgc.c,v 1.171a 2003/04/03 13:35:34 roberto Exp $
33 ** Garbage Collector
44 ** See Copyright Notice in lua.h
55 */
@@ -110,7 +110,8 @@ static void marktmu (GCState *st) { · 104 unmodified lines
110110
111111
112112 /* move `dead' udata that need finalization to list `tmudata' */
113−void luaC_separateudata (lua_State *L) {
113+size_t luaC_separateudata (lua_State *L) {
114+ size_t deadmem = 0;
114115 GCObject **p = &G(L)->rootudata;
115116 GCObject *curr;
116117 GCObject *collected = NULL; /* to collect udata with gc event */
@@ -125,6 +126,7 @@ void luaC_separateudata (lua_State *L) { · 8 unmodified lines
125126 p = &curr->gch.next;
126127 }
127128 else { /* must call its gc method */
129+ deadmem += sizeudata(gcotou(curr)->uv.len);
128130 *p = curr->gch.next;
129131 curr->gch.next = NULL; /* link `curr' at the end of `collected' list */
130132 *lastcollected = curr;
@@ -134,6 +136,7 @@ void luaC_separateudata (lua_State *L) { · 3 unmodified lines
134136 /* insert collected udata with gc event into `tmudata' list */
135137 *lastcollected = G(L)->tmudata;
136138 G(L)->tmudata = collected;
139+ return deadmem;
137140 }
138141
139142
@@ -244,7 +247,7 @@ static void traversestack (GCState *st, lua_State *L1) { · 104 unmodified lines
244247 for (ci = L1->base_ci; ci <= L1->ci; ci++) {
245248 lua_assert(ci->top <= L1->stack_last);
246249 lua_assert(ci->state & (CI_C | CI_HASFRAME | CI_SAVEDPC));
247− if (!(ci->state & CI_C) && lim < ci->top)
250+ if (lim < ci->top)
248251 lim = ci->top;
249252 }
250253 for (o = L1->stack; o < L1->top; o++)
@@ -387,7 +390,7 @@ static void sweepstrings (lua_State *L, int all) { · 136 unmodified lines
387390 }
388391
389392
390−static void checkSizes (lua_State *L) {
393+static void checkSizes (lua_State *L, size_t deadmem) {
391394 /* check size of string hash */
392395 if (G(L)->strt.nuse < cast(ls_nstr, G(L)->strt.size/4) &&
393396 G(L)->strt.size > MINSTRTABSIZE*2)
@@ -397,7 +400,7 @@ static void checkSizes (lua_State *L) { · 3 unmodified lines
397400 size_t newsize = luaZ_sizebuffer(&G(L)->buff) / 2;
398401 luaZ_resizebuffer(L, &G(L)->buff, newsize);
399402 }
400− G(L)->GCthreshold = 2*G(L)->nblocks; /* new threshold */
403+ G(L)->GCthreshold = 2*G(L)->nblocks - deadmem; /* new threshold */
401404 }
402405
403406
@@ -451,7 +454,8 @@ static void markroot (GCState *st, lua_State *L) { · 47 unmodified lines
451454 }
452455
453456
454−static void mark (lua_State *L) {
457+static size_t mark (lua_State *L) {
458+ size_t deadmem;
455459 GCState st;
456460 GCObject *wkv;
457461 st.g = G(L);
@@ -464,7 +468,7 @@ static void mark (lua_State *L) { · 6 unmodified lines
464468 wkv = st.wkv; /* keys must be cleared after preserving udata */
465469 st.wkv = NULL;
466470 st.wv = NULL;
467− luaC_separateudata(L); /* separate userdata to be preserved */
471+ deadmem = luaC_separateudata(L); /* separate userdata to be preserved */
468472 marktmu(&st); /* mark `preserved' userdata */
469473 propagatemarks(&st); /* remark, to propagate `preserveness' */
470474 cleartablekeys(wkv);
@@ -473,13 +477,14 @@ static void mark (lua_State *L) { · 2 unmodified lines
473477 cleartablevalues(st.wv);
474478 cleartablekeys(st.wkv);
475479 cleartablevalues(st.wkv);
480+ return deadmem;
476481 }
477482
478483
479484 void luaC_collectgarbage (lua_State *L) {
480− mark(L);
485+ size_t deadmem = mark(L);
481486 luaC_sweep(L, 0);
482− checkSizes(L);
487+ checkSizes(L, deadmem);
483488 luaC_callGCTM(L);
484489 }
485490
src/lgc.h+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lgc.h,v 1.19 2003/02/28 19:45:15 roberto Exp $
2+** $Id: lgc.h,v 1.19a 2003/02/28 19:45:15 roberto Exp $
33 ** Garbage Collector
44 ** See Copyright Notice in lua.h
55 */
@@ -15,7 +15,7 @@ · 9 unmodified lines
1515 if (G(L)->nblocks >= G(L)->GCthreshold) luaC_collectgarbage(L); }
1616
1717
18−void luaC_separateudata (lua_State *L);
18+size_t luaC_separateudata (lua_State *L);
1919 void luaC_callGCTM (lua_State *L);
2020 void luaC_sweep (lua_State *L, int all);
2121 void luaC_collectgarbage (lua_State *L);
src/lib/lbaselib.c+2−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lbaselib.c,v 1.130 2003/04/03 13:35:34 roberto Exp $
2+** $Id: lbaselib.c,v 1.130a 2003/04/03 13:35:34 roberto Exp $
33 ** Basic library
44 ** See Copyright Notice in lua.h
55 */
@@ -324,7 +324,7 @@ static int luaB_xpcall (lua_State *L) { · 318 unmodified lines
324324
325325
326326 static int luaB_tostring (lua_State *L) {
327− char buff[64];
327+ char buff[128];
328328 luaL_checkany(L, 1);
329329 if (luaL_callmeta(L, 1, "__tostring")) /* is there a metafield? */
330330 return 1; /* use its value */
src/lib/liolib.c+3−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: liolib.c,v 2.39 2003/03/19 21:16:12 roberto Exp $
2+** $Id: liolib.c,v 2.39a 2003/03/19 21:16:12 roberto Exp $
33 ** Standard I/O (and system) library
44 ** See Copyright Notice in lua.h
55 */
@@ -158,7 +158,7 @@ static int aux_close (lua_State *L) { · 152 unmodified lines
158158
159159
160160 static int io_close (lua_State *L) {
161− if (lua_isnone(L, 1)) {
161+ if (lua_isnone(L, 1) && lua_type(L, lua_upvalueindex(1)) == LUA_TTABLE) {
162162 lua_pushstring(L, IO_OUTPUT);
163163 lua_rawget(L, lua_upvalueindex(1));
164164 }
@@ -175,7 +175,7 @@ static int io_gc (lua_State *L) { · 10 unmodified lines
175175
176176
177177 static int io_tostring (lua_State *L) {
178− char buff[32];
178+ char buff[128];
179179 FILE **f = topfile(L, 1);
180180 if (*f == NULL)
181181 strcpy(buff, "closed");
src/lparser.c+7−3
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lparser.c,v 1.208 2003/04/03 13:35:34 roberto Exp $
2+** $Id: lparser.c,v 1.208a 2003/04/03 13:35:34 roberto Exp $
33 ** Lua Parser
44 ** See Copyright Notice in lua.h
55 */
@@ -1141,11 +1141,15 @@ static void ifstat (LexState *ls, int line) { · 1135 unmodified lines
11411141
11421142 static void localfunc (LexState *ls) {
11431143 expdesc v, b;
1144+ FuncState *fs = ls->fs;
11441145 new_localvar(ls, str_checkname(ls), 0);
1145− init_exp(&v, VLOCAL, ls->fs->freereg++);
1146+ init_exp(&v, VLOCAL, fs->freereg);
1147+ luaK_reserveregs(fs, 1);
11461148 adjustlocalvars(ls, 1);
11471149 body(ls, &b, 0, ls->linenumber);
1148− luaK_storevar(ls->fs, &v, &b);
1150+ luaK_storevar(fs, &v, &b);
1151+ /* debug information will only see the variable after this point! */
1152+ getlocvar(fs, fs->nactvar - 1).startpc = fs->pc;
11491153 }
11501154
11511155
src/luac/Makefile+1−1
@@ -13,7 +13,7 @@ T= $(BIN)/luac · 12 unmodified lines
1313 all: $T
1414
1515 $T: $(OBJS) $(LIB)/liblua.a $(LIB)/liblualib.a
16− $(CC) -o $@ $(MYLDFLAGS) $(OBJS) -L$(LIB) -llua -llualib $(EXTRA_LIBS)
16+ $(CC) -o $@ $(MYLDFLAGS) $(OBJS) -L$(LIB) -llua -llualib $(EXTRA_LIBS) $(DLLIB)
1717
1818 # print.c needs opcode names from lopcodes.c
1919 lopcodes.o: ../lopcodes.c ../lopcodes.h
src/luac/luac.c+3−1
@@ -1,5 +1,5 @@
11 /*
2−** $Id: luac.c,v 1.44 2003/04/07 20:34:20 lhf Exp $
2+** $Id: luac.c,v 1.44a 2003/04/07 20:34:20 lhf Exp $
33 ** Lua compiler (saves bytecodes to files; also list bytecodes)
44 ** See Copyright Notice in lua.h
55 */
@@ -182,7 +182,9 @@ int main(int argc, char* argv[]) · 176 unmodified lines
182182 FILE* D=fopen(output,"wb");
183183 if (D==NULL) cannot(output,"open","out");
184184 if (stripping) strip(L,f);
185+ lua_lock(L);
185186 luaU_dump(L,f,writer,D);
187+ lua_unlock(L);
186188 if (ferror(D)) cannot(output,"write","out");
187189 fclose(D);
188190 }
src/lvm.c+4−6
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lvm.c,v 1.284 2003/04/03 13:35:34 roberto Exp $
2+** $Id: lvm.c,v 1.284a 2003/04/03 13:35:34 roberto Exp $
33 ** Lua virtual machine
44 ** See Copyright Notice in lua.h
55 */
@@ -66,7 +66,7 @@ int luaV_tostring (lua_State *L, StkId obj) { · 60 unmodified lines
6666
6767 static void traceexec (lua_State *L) {
6868 lu_byte mask = L->hookmask;
69− if (mask > LUA_MASKLINE) { /* instruction-hook set? */
69+ if (mask & LUA_MASKCOUNT) { /* instruction-hook set? */
7070 if (L->hookcount == 0) {
7171 resethookcount(L);
7272 luaD_callhook(L, LUA_HOOKCOUNT, -1);
@@ -399,10 +399,10 @@ StkId luaV_execute (lua_State *L) { · 326 unmodified lines
399399 TObject *k;
400400 const Instruction *pc;
401401 callentry: /* entry point when calling new functions */
402− L->ci->u.l.pc = &pc;
403402 if (L->hookmask & LUA_MASKCALL)
404403 luaD_callhook(L, LUA_HOOKCALL, -1);
405404 retentry: /* entry point when returning to old functions */
405+ L->ci->u.l.pc = &pc;
406406 lua_assert(L->ci->state == CI_SAVEDPC ||
407407 L->ci->state == (CI_SAVEDPC | CI_CALLING));
408408 L->ci->state = CI_HASFRAME; /* activate frame */
@@ -673,9 +673,7 @@ StkId luaV_execute (lua_State *L) { · 264 unmodified lines
673673 }
674674 else { /* yes: continue its execution */
675675 int nresults;
676− lua_assert(ci->u.l.pc == &pc &&
677− ttisfunction(ci->base - 1) &&
678− (ci->state & CI_SAVEDPC));
676+ lua_assert(ttisfunction(ci->base - 1) && (ci->state & CI_SAVEDPC));
679677 lua_assert(GET_OPCODE(*(ci->u.l.savedpc - 1)) == OP_CALL);
680678 nresults = GETARG_C(*(ci->u.l.savedpc - 1)) - 1;
681679 luaD_poscall(L, nresults, ra);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t