aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c19
1 files changed, 3 insertions, 16 deletions
diff --git a/lapi.c b/lapi.c
index 4f4e3021..c493609a 100644
--- a/lapi.c
+++ b/lapi.c
@@ -53,16 +53,6 @@ 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 - cast(l_obj, delta));
62 }
63}
64
65
66/* 56/*
67** Convert an acceptable index to a pointer to its respective value. 57** Convert an acceptable index to a pointer to its respective value.
68** Non-valid indices return the special nil value 'G(L)->nilvalue'. 58** Non-valid indices return the special nil value 'G(L)->nilvalue'.
@@ -540,7 +530,6 @@ LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) {
540 ts = (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len); 530 ts = (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len);
541 setsvalue2s(L, L->top.p, ts); 531 setsvalue2s(L, L->top.p, ts);
542 api_incr_top(L); 532 api_incr_top(L);
543 advancegc(L, len);
544 luaC_checkGC(L); 533 luaC_checkGC(L);
545 lua_unlock(L); 534 lua_unlock(L);
546 return getstr(ts); 535 return getstr(ts);
@@ -557,7 +546,6 @@ LUA_API const char *lua_pushextlstring (lua_State *L,
557 setsvalue2s(L, L->top.p, ts); 546 setsvalue2s(L, L->top.p, ts);
558 api_incr_top(L); 547 api_incr_top(L);
559 if (falloc != NULL) /* non-static string? */ 548 if (falloc != NULL) /* non-static string? */
560 advancegc(L, len); /* count its memory */
561 luaC_checkGC(L); 549 luaC_checkGC(L);
562 lua_unlock(L); 550 lua_unlock(L);
563 return getstr(ts); 551 return getstr(ts);
@@ -1190,16 +1178,16 @@ LUA_API int lua_gc (lua_State *L, int what, ...) {
1190 } 1178 }
1191 case LUA_GCCOUNT: { 1179 case LUA_GCCOUNT: {
1192 /* GC values are expressed in Kbytes: #bytes/2^10 */ 1180 /* GC values are expressed in Kbytes: #bytes/2^10 */
1193 res = cast_int(g->GCtotalbytes >> 10); 1181 res = cast_int(gettotalbytes(g) >> 10);
1194 break; 1182 break;
1195 } 1183 }
1196 case LUA_GCCOUNTB: { 1184 case LUA_GCCOUNTB: {
1197 res = cast_int(g->GCtotalbytes & 0x3ff); 1185 res = cast_int(gettotalbytes(g) & 0x3ff);
1198 break; 1186 break;
1199 } 1187 }
1200 case LUA_GCSTEP: { 1188 case LUA_GCSTEP: {
1201 lu_byte oldstp = g->gcstp; 1189 lu_byte oldstp = g->gcstp;
1202 l_obj n = cast(l_obj, va_arg(argp, size_t)); 1190 l_mem n = cast(l_mem, va_arg(argp, size_t));
1203 int work = 0; /* true if GC did some work */ 1191 int work = 0; /* true if GC did some work */
1204 g->gcstp = 0; /* allow GC to run (other bits must be zero here) */ 1192 g->gcstp = 0; /* allow GC to run (other bits must be zero here) */
1205 if (n <= 0) 1193 if (n <= 0)
@@ -1356,7 +1344,6 @@ LUA_API void *lua_newuserdatauv (lua_State *L, size_t size, int nuvalue) {
1356 u = luaS_newudata(L, size, cast(unsigned short, nuvalue)); 1344 u = luaS_newudata(L, size, cast(unsigned short, nuvalue));
1357 setuvalue(L, s2v(L->top.p), u); 1345 setuvalue(L, s2v(L->top.p), u);
1358 api_incr_top(L); 1346 api_incr_top(L);
1359 advancegc(L, size);
1360 luaC_checkGC(L); 1347 luaC_checkGC(L);
1361 lua_unlock(L); 1348 lua_unlock(L);
1362 return getudatamem(u); 1349 return getudatamem(u);