mirror of
https://github.com/lua/lua
synced 2025-04-17 10:22:47 +03:00
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')
This commit is contained in:
parent
7777b412de
commit
03ca6385dc
20
lapi.c
20
lapi.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lapi.c,v 2.257 2015/11/02 18:48:07 roberto Exp roberto $
|
** $Id: lapi.c,v 2.258 2016/01/05 16:07:21 roberto Exp roberto $
|
||||||
** Lua API
|
** Lua API
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -378,9 +378,9 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
lua_lock(L); /* 'luaO_tostring' may create a new string */
|
lua_lock(L); /* 'luaO_tostring' may create a new string */
|
||||||
|
luaO_tostring(L, o);
|
||||||
luaC_checkGC(L);
|
luaC_checkGC(L);
|
||||||
o = index2addr(L, idx); /* previous call may reallocate the stack */
|
o = index2addr(L, idx); /* previous call may reallocate the stack */
|
||||||
luaO_tostring(L, o);
|
|
||||||
lua_unlock(L);
|
lua_unlock(L);
|
||||||
}
|
}
|
||||||
if (len != NULL)
|
if (len != NULL)
|
||||||
@ -479,10 +479,10 @@ LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
|
|||||||
LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) {
|
LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) {
|
||||||
TString *ts;
|
TString *ts;
|
||||||
lua_lock(L);
|
lua_lock(L);
|
||||||
luaC_checkGC(L);
|
|
||||||
ts = (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len);
|
ts = (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len);
|
||||||
setsvalue2s(L, L->top, ts);
|
setsvalue2s(L, L->top, ts);
|
||||||
api_incr_top(L);
|
api_incr_top(L);
|
||||||
|
luaC_checkGC(L);
|
||||||
lua_unlock(L);
|
lua_unlock(L);
|
||||||
return getstr(ts);
|
return getstr(ts);
|
||||||
}
|
}
|
||||||
@ -494,12 +494,12 @@ LUA_API const char *lua_pushstring (lua_State *L, const char *s) {
|
|||||||
setnilvalue(L->top);
|
setnilvalue(L->top);
|
||||||
else {
|
else {
|
||||||
TString *ts;
|
TString *ts;
|
||||||
luaC_checkGC(L);
|
|
||||||
ts = luaS_new(L, s);
|
ts = luaS_new(L, s);
|
||||||
setsvalue2s(L, L->top, ts);
|
setsvalue2s(L, L->top, ts);
|
||||||
s = getstr(ts); /* internal copy's address */
|
s = getstr(ts); /* internal copy's address */
|
||||||
}
|
}
|
||||||
api_incr_top(L);
|
api_incr_top(L);
|
||||||
|
luaC_checkGC(L);
|
||||||
lua_unlock(L);
|
lua_unlock(L);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@ -509,8 +509,8 @@ LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt,
|
|||||||
va_list argp) {
|
va_list argp) {
|
||||||
const char *ret;
|
const char *ret;
|
||||||
lua_lock(L);
|
lua_lock(L);
|
||||||
luaC_checkGC(L);
|
|
||||||
ret = luaO_pushvfstring(L, fmt, argp);
|
ret = luaO_pushvfstring(L, fmt, argp);
|
||||||
|
luaC_checkGC(L);
|
||||||
lua_unlock(L);
|
lua_unlock(L);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -520,10 +520,10 @@ LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) {
|
|||||||
const char *ret;
|
const char *ret;
|
||||||
va_list argp;
|
va_list argp;
|
||||||
lua_lock(L);
|
lua_lock(L);
|
||||||
luaC_checkGC(L);
|
|
||||||
va_start(argp, fmt);
|
va_start(argp, fmt);
|
||||||
ret = luaO_pushvfstring(L, fmt, argp);
|
ret = luaO_pushvfstring(L, fmt, argp);
|
||||||
va_end(argp);
|
va_end(argp);
|
||||||
|
luaC_checkGC(L);
|
||||||
lua_unlock(L);
|
lua_unlock(L);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -538,7 +538,6 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
|
|||||||
CClosure *cl;
|
CClosure *cl;
|
||||||
api_checknelems(L, n);
|
api_checknelems(L, n);
|
||||||
api_check(L, n <= MAXUPVAL, "upvalue index too large");
|
api_check(L, n <= MAXUPVAL, "upvalue index too large");
|
||||||
luaC_checkGC(L);
|
|
||||||
cl = luaF_newCclosure(L, n);
|
cl = luaF_newCclosure(L, n);
|
||||||
cl->f = fn;
|
cl->f = fn;
|
||||||
L->top -= n;
|
L->top -= n;
|
||||||
@ -549,6 +548,7 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
|
|||||||
setclCvalue(L, L->top, cl);
|
setclCvalue(L, L->top, cl);
|
||||||
}
|
}
|
||||||
api_incr_top(L);
|
api_incr_top(L);
|
||||||
|
luaC_checkGC(L);
|
||||||
lua_unlock(L);
|
lua_unlock(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -683,12 +683,12 @@ LUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) {
|
|||||||
LUA_API void lua_createtable (lua_State *L, int narray, int nrec) {
|
LUA_API void lua_createtable (lua_State *L, int narray, int nrec) {
|
||||||
Table *t;
|
Table *t;
|
||||||
lua_lock(L);
|
lua_lock(L);
|
||||||
luaC_checkGC(L);
|
|
||||||
t = luaH_new(L);
|
t = luaH_new(L);
|
||||||
sethvalue(L, L->top, t);
|
sethvalue(L, L->top, t);
|
||||||
api_incr_top(L);
|
api_incr_top(L);
|
||||||
if (narray > 0 || nrec > 0)
|
if (narray > 0 || nrec > 0)
|
||||||
luaH_resize(L, t, narray, nrec);
|
luaH_resize(L, t, narray, nrec);
|
||||||
|
luaC_checkGC(L);
|
||||||
lua_unlock(L);
|
lua_unlock(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1140,7 +1140,6 @@ LUA_API void lua_concat (lua_State *L, int n) {
|
|||||||
lua_lock(L);
|
lua_lock(L);
|
||||||
api_checknelems(L, n);
|
api_checknelems(L, n);
|
||||||
if (n >= 2) {
|
if (n >= 2) {
|
||||||
luaC_checkGC(L);
|
|
||||||
luaV_concat(L, n);
|
luaV_concat(L, n);
|
||||||
}
|
}
|
||||||
else if (n == 0) { /* push empty string */
|
else if (n == 0) { /* push empty string */
|
||||||
@ -1148,6 +1147,7 @@ LUA_API void lua_concat (lua_State *L, int n) {
|
|||||||
api_incr_top(L);
|
api_incr_top(L);
|
||||||
}
|
}
|
||||||
/* else n == 1; nothing to do */
|
/* else n == 1; nothing to do */
|
||||||
|
luaC_checkGC(L);
|
||||||
lua_unlock(L);
|
lua_unlock(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1183,10 +1183,10 @@ LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud) {
|
|||||||
LUA_API void *lua_newuserdata (lua_State *L, size_t size) {
|
LUA_API void *lua_newuserdata (lua_State *L, size_t size) {
|
||||||
Udata *u;
|
Udata *u;
|
||||||
lua_lock(L);
|
lua_lock(L);
|
||||||
luaC_checkGC(L);
|
|
||||||
u = luaS_newudata(L, size);
|
u = luaS_newudata(L, size);
|
||||||
setuvalue(L, L->top, u);
|
setuvalue(L, L->top, u);
|
||||||
api_incr_top(L);
|
api_incr_top(L);
|
||||||
|
luaC_checkGC(L);
|
||||||
lua_unlock(L);
|
lua_unlock(L);
|
||||||
return getudatamem(u);
|
return getudatamem(u);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user