aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/lapi.c b/lapi.c
index 9ff1b851..d18445e0 100644
--- a/lapi.c
+++ b/lapi.c
@@ -53,6 +53,16 @@ const char lua_ident[] =
53#define isupvalue(i) ((i) < LUA_REGISTRYINDEX) 53#define isupvalue(i) ((i) < LUA_REGISTRYINDEX)
54 54
55 55
56/* Advance the garbage collector when creating large objects */
57static void advancegc (lua_State *L, size_t delta) {
58 delta >>= 5; /* one object for each 32 bytes (empirical) */
59 if (delta > 0) {
60 global_State *g = G(L);
61 luaE_setdebt(g, g->GCdebt - delta);
62 }
63}
64
65
56/* 66/*
57** Convert an acceptable index to a pointer to its respective value. 67** Convert an acceptable index to a pointer to its respective value.
58** Non-valid indices return the special nil value 'G(L)->nilvalue'. 68** Non-valid indices return the special nil value 'G(L)->nilvalue'.
@@ -530,6 +540,7 @@ LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) {
530 ts = (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len); 540 ts = (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len);
531 setsvalue2s(L, L->top.p, ts); 541 setsvalue2s(L, L->top.p, ts);
532 api_incr_top(L); 542 api_incr_top(L);
543 advancegc(L, len);
533 luaC_checkGC(L); 544 luaC_checkGC(L);
534 lua_unlock(L); 545 lua_unlock(L);
535 return getstr(ts); 546 return getstr(ts);
@@ -544,6 +555,8 @@ LUA_API const char *lua_pushextlstring (lua_State *L,
544 ts = luaS_newextlstr (L, s, len, falloc, ud); 555 ts = luaS_newextlstr (L, s, len, falloc, ud);
545 setsvalue2s(L, L->top.p, ts); 556 setsvalue2s(L, L->top.p, ts);
546 api_incr_top(L); 557 api_incr_top(L);
558 if (falloc != NULL) /* non-static string? */
559 advancegc(L, len); /* count its memory */
547 luaC_checkGC(L); 560 luaC_checkGC(L);
548 lua_unlock(L); 561 lua_unlock(L);
549 return getstr(ts); 562 return getstr(ts);
@@ -1336,6 +1349,7 @@ LUA_API void *lua_newuserdatauv (lua_State *L, size_t size, int nuvalue) {
1336 u = luaS_newudata(L, size, nuvalue); 1349 u = luaS_newudata(L, size, nuvalue);
1337 setuvalue(L, s2v(L->top.p), u); 1350 setuvalue(L, s2v(L->top.p), u);
1338 api_incr_top(L); 1351 api_incr_top(L);
1352 advancegc(L, size);
1339 luaC_checkGC(L); 1353 luaC_checkGC(L);
1340 lua_unlock(L); 1354 lua_unlock(L);
1341 return getudatamem(u); 1355 return getudatamem(u);