aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2016-02-29 11:27:14 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2016-02-29 11:27:14 -0300
commit03ca6385dc426fefabe9204037fc76ebf0627a11 (patch)
treeab3e0f36557840bbd7736c4d9649204096cb77cb
parent7777b412deb46d051967b699697d1d6e6286a7b6 (diff)
downloadlua-03ca6385dc426fefabe9204037fc76ebf0627a11.tar.gz
lua-03ca6385dc426fefabe9204037fc76ebf0627a11.tar.bz2
lua-03ca6385dc426fefabe9204037fc76ebf0627a11.zip
call 'checkGC' *after* creating new objects (this is how 'execute'
does it) (It increases the changes that 'allgc' start with a non-white object, which helps 'entersweep')
-rw-r--r--lapi.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/lapi.c b/lapi.c
index 2f492754..1c4d07dd 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.257 2015/11/02 18:48:07 roberto Exp roberto $ 2** $Id: lapi.c,v 2.258 2016/01/05 16:07:21 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -378,9 +378,9 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {
378 return NULL; 378 return NULL;
379 } 379 }
380 lua_lock(L); /* 'luaO_tostring' may create a new string */ 380 lua_lock(L); /* 'luaO_tostring' may create a new string */
381 luaO_tostring(L, o);
381 luaC_checkGC(L); 382 luaC_checkGC(L);
382 o = index2addr(L, idx); /* previous call may reallocate the stack */ 383 o = index2addr(L, idx); /* previous call may reallocate the stack */
383 luaO_tostring(L, o);
384 lua_unlock(L); 384 lua_unlock(L);
385 } 385 }
386 if (len != NULL) 386 if (len != NULL)
@@ -479,10 +479,10 @@ LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
479LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) { 479LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) {
480 TString *ts; 480 TString *ts;
481 lua_lock(L); 481 lua_lock(L);
482 luaC_checkGC(L);
483 ts = (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len); 482 ts = (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len);
484 setsvalue2s(L, L->top, ts); 483 setsvalue2s(L, L->top, ts);
485 api_incr_top(L); 484 api_incr_top(L);
485 luaC_checkGC(L);
486 lua_unlock(L); 486 lua_unlock(L);
487 return getstr(ts); 487 return getstr(ts);
488} 488}
@@ -494,12 +494,12 @@ LUA_API const char *lua_pushstring (lua_State *L, const char *s) {
494 setnilvalue(L->top); 494 setnilvalue(L->top);
495 else { 495 else {
496 TString *ts; 496 TString *ts;
497 luaC_checkGC(L);
498 ts = luaS_new(L, s); 497 ts = luaS_new(L, s);
499 setsvalue2s(L, L->top, ts); 498 setsvalue2s(L, L->top, ts);
500 s = getstr(ts); /* internal copy's address */ 499 s = getstr(ts); /* internal copy's address */
501 } 500 }
502 api_incr_top(L); 501 api_incr_top(L);
502 luaC_checkGC(L);
503 lua_unlock(L); 503 lua_unlock(L);
504 return s; 504 return s;
505} 505}
@@ -509,8 +509,8 @@ LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt,
509 va_list argp) { 509 va_list argp) {
510 const char *ret; 510 const char *ret;
511 lua_lock(L); 511 lua_lock(L);
512 luaC_checkGC(L);
513 ret = luaO_pushvfstring(L, fmt, argp); 512 ret = luaO_pushvfstring(L, fmt, argp);
513 luaC_checkGC(L);
514 lua_unlock(L); 514 lua_unlock(L);
515 return ret; 515 return ret;
516} 516}
@@ -520,10 +520,10 @@ LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) {
520 const char *ret; 520 const char *ret;
521 va_list argp; 521 va_list argp;
522 lua_lock(L); 522 lua_lock(L);
523 luaC_checkGC(L);
524 va_start(argp, fmt); 523 va_start(argp, fmt);
525 ret = luaO_pushvfstring(L, fmt, argp); 524 ret = luaO_pushvfstring(L, fmt, argp);
526 va_end(argp); 525 va_end(argp);
526 luaC_checkGC(L);
527 lua_unlock(L); 527 lua_unlock(L);
528 return ret; 528 return ret;
529} 529}
@@ -538,7 +538,6 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
538 CClosure *cl; 538 CClosure *cl;
539 api_checknelems(L, n); 539 api_checknelems(L, n);
540 api_check(L, n <= MAXUPVAL, "upvalue index too large"); 540 api_check(L, n <= MAXUPVAL, "upvalue index too large");
541 luaC_checkGC(L);
542 cl = luaF_newCclosure(L, n); 541 cl = luaF_newCclosure(L, n);
543 cl->f = fn; 542 cl->f = fn;
544 L->top -= n; 543 L->top -= n;
@@ -549,6 +548,7 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
549 setclCvalue(L, L->top, cl); 548 setclCvalue(L, L->top, cl);
550 } 549 }
551 api_incr_top(L); 550 api_incr_top(L);
551 luaC_checkGC(L);
552 lua_unlock(L); 552 lua_unlock(L);
553} 553}
554 554
@@ -683,12 +683,12 @@ LUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) {
683LUA_API void lua_createtable (lua_State *L, int narray, int nrec) { 683LUA_API void lua_createtable (lua_State *L, int narray, int nrec) {
684 Table *t; 684 Table *t;
685 lua_lock(L); 685 lua_lock(L);
686 luaC_checkGC(L);
687 t = luaH_new(L); 686 t = luaH_new(L);
688 sethvalue(L, L->top, t); 687 sethvalue(L, L->top, t);
689 api_incr_top(L); 688 api_incr_top(L);
690 if (narray > 0 || nrec > 0) 689 if (narray > 0 || nrec > 0)
691 luaH_resize(L, t, narray, nrec); 690 luaH_resize(L, t, narray, nrec);
691 luaC_checkGC(L);
692 lua_unlock(L); 692 lua_unlock(L);
693} 693}
694 694
@@ -1140,7 +1140,6 @@ LUA_API void lua_concat (lua_State *L, int n) {
1140 lua_lock(L); 1140 lua_lock(L);
1141 api_checknelems(L, n); 1141 api_checknelems(L, n);
1142 if (n >= 2) { 1142 if (n >= 2) {
1143 luaC_checkGC(L);
1144 luaV_concat(L, n); 1143 luaV_concat(L, n);
1145 } 1144 }
1146 else if (n == 0) { /* push empty string */ 1145 else if (n == 0) { /* push empty string */
@@ -1148,6 +1147,7 @@ LUA_API void lua_concat (lua_State *L, int n) {
1148 api_incr_top(L); 1147 api_incr_top(L);
1149 } 1148 }
1150 /* else n == 1; nothing to do */ 1149 /* else n == 1; nothing to do */
1150 luaC_checkGC(L);
1151 lua_unlock(L); 1151 lua_unlock(L);
1152} 1152}
1153 1153
@@ -1183,10 +1183,10 @@ LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) {
1183LUA_API void *lua_newuserdata (lua_State *L, size_t size) { 1183LUA_API void *lua_newuserdata (lua_State *L, size_t size) {
1184 Udata *u; 1184 Udata *u;
1185 lua_lock(L); 1185 lua_lock(L);
1186 luaC_checkGC(L);
1187 u = luaS_newudata(L, size); 1186 u = luaS_newudata(L, size);
1188 setuvalue(L, L->top, u); 1187 setuvalue(L, L->top, u);
1189 api_incr_top(L); 1188 api_incr_top(L);
1189 luaC_checkGC(L);
1190 lua_unlock(L); 1190 lua_unlock(L);
1191 return getudatamem(u); 1191 return getudatamem(u);
1192} 1192}