diff options
Diffstat (limited to '')
-rw-r--r-- | lapi.c | 76 |
1 files changed, 41 insertions, 35 deletions
@@ -1145,7 +1145,7 @@ LUA_API int lua_gc (lua_State *L, int what, ...) { | |||
1145 | } | 1145 | } |
1146 | case LUA_GCRESTART: { | 1146 | case LUA_GCRESTART: { |
1147 | luaE_setdebt(g, 0); | 1147 | luaE_setdebt(g, 0); |
1148 | g->gcstp = 0; /* (GCSTPGC must be already zero here) */ | 1148 | g->gcstp = 0; /* (bit GCSTPGC must be zero here) */ |
1149 | break; | 1149 | break; |
1150 | } | 1150 | } |
1151 | case LUA_GCCOLLECT: { | 1151 | case LUA_GCCOLLECT: { |
@@ -1154,42 +1154,46 @@ LUA_API int lua_gc (lua_State *L, int what, ...) { | |||
1154 | } | 1154 | } |
1155 | case LUA_GCCOUNT: { | 1155 | case LUA_GCCOUNT: { |
1156 | /* GC values are expressed in Kbytes: #bytes/2^10 */ | 1156 | /* GC values are expressed in Kbytes: #bytes/2^10 */ |
1157 | res = cast_int(gettotalbytes(g) >> 10); | 1157 | res = cast_int(g->totalbytes >> 10); |
1158 | break; | 1158 | break; |
1159 | } | 1159 | } |
1160 | case LUA_GCCOUNTB: { | 1160 | case LUA_GCCOUNTB: { |
1161 | res = cast_int(gettotalbytes(g) & 0x3ff); | 1161 | res = cast_int(g->totalbytes & 0x3ff); |
1162 | break; | 1162 | break; |
1163 | } | 1163 | } |
1164 | case LUA_GCSTEP: { | 1164 | case LUA_GCSTEP: { |
1165 | int data = va_arg(argp, int); | 1165 | int todo = va_arg(argp, int); /* work to be done */ |
1166 | l_mem debt = 1; /* =1 to signal that it did an actual step */ | 1166 | int didsomething = 0; |
1167 | lu_byte oldstp = g->gcstp; | 1167 | lu_byte oldstp = g->gcstp; |
1168 | g->gcstp = 0; /* allow GC to run (GCSTPGC must be zero here) */ | 1168 | g->gcstp = 0; /* allow GC to run (bit GCSTPGC must be zero here) */ |
1169 | if (data == 0) { | 1169 | if (todo == 0) |
1170 | luaE_setdebt(g, 0); /* do a basic step */ | 1170 | todo = 1 << g->gcstepsize; /* standard step size */ |
1171 | luaC_step(L); | 1171 | while (todo >= g->GCdebt) { /* enough to run a step? */ |
1172 | } | 1172 | todo -= g->GCdebt; /* decrement 'todo' */ |
1173 | else { /* add 'data' to total debt */ | 1173 | luaC_step(L); /* run one basic step */ |
1174 | debt = cast(l_mem, data) * 1024 + g->GCdebt; | 1174 | didsomething = 1; |
1175 | luaE_setdebt(g, debt); | 1175 | if (g->gckind == KGC_GEN) /* minor collections? */ |
1176 | luaC_checkGC(L); | 1176 | todo = 0; /* doesn't make sense to repeat in this case */ |
1177 | else if (g->gcstate == GCSpause) | ||
1178 | break; /* don't run more than one cycle */ | ||
1177 | } | 1179 | } |
1180 | /* remove remaining 'todo' from total debt */ | ||
1181 | luaE_setdebt(g, g->GCdebt - todo); | ||
1178 | g->gcstp = oldstp; /* restore previous state */ | 1182 | g->gcstp = oldstp; /* restore previous state */ |
1179 | if (debt > 0 && g->gcstate == GCSpause) /* end of cycle? */ | 1183 | if (didsomething && g->gcstate == GCSpause) /* end of cycle? */ |
1180 | res = 1; /* signal it */ | 1184 | res = 1; /* signal it */ |
1181 | break; | 1185 | break; |
1182 | } | 1186 | } |
1183 | case LUA_GCSETPAUSE: { | 1187 | case LUA_GCSETPAUSE: { |
1184 | int data = va_arg(argp, int); | 1188 | unsigned int data = va_arg(argp, unsigned int); |
1185 | res = getgcparam(g->gcpause); | 1189 | res = applygcparam(g, gcpause, 100); |
1186 | setgcparam(g->gcpause, data); | 1190 | setgcparam(g, gcpause, data); |
1187 | break; | 1191 | break; |
1188 | } | 1192 | } |
1189 | case LUA_GCSETSTEPMUL: { | 1193 | case LUA_GCSETSTEPMUL: { |
1190 | int data = va_arg(argp, int); | 1194 | unsigned int data = va_arg(argp, unsigned int); |
1191 | res = getgcparam(g->gcstepmul); | 1195 | res = applygcparam(g, gcstepmul, 100); |
1192 | setgcparam(g->gcstepmul, data); | 1196 | setgcparam(g, gcstepmul, data); |
1193 | break; | 1197 | break; |
1194 | } | 1198 | } |
1195 | case LUA_GCISRUNNING: { | 1199 | case LUA_GCISRUNNING: { |
@@ -1197,27 +1201,28 @@ LUA_API int lua_gc (lua_State *L, int what, ...) { | |||
1197 | break; | 1201 | break; |
1198 | } | 1202 | } |
1199 | case LUA_GCGEN: { | 1203 | case LUA_GCGEN: { |
1200 | int minormul = va_arg(argp, int); | 1204 | unsigned int minormul = va_arg(argp, unsigned int); |
1201 | int majormul = va_arg(argp, int); | 1205 | unsigned int majormul = va_arg(argp, unsigned int); |
1202 | res = isdecGCmodegen(g) ? LUA_GCGEN : LUA_GCINC; | 1206 | res = (g->gckind == KGC_INC) ? LUA_GCINC : LUA_GCGEN; |
1203 | if (minormul != 0) | 1207 | if (minormul != 0) |
1204 | g->genminormul = minormul; | 1208 | setgcparam(g, genminormul, minormul); |
1205 | if (majormul != 0) | 1209 | if (majormul != 0) |
1206 | setgcparam(g->genmajormul, majormul); | 1210 | setgcparam(g, genmajormul, majormul); |
1207 | luaC_changemode(L, KGC_GEN); | 1211 | luaC_changemode(L, KGC_GEN); |
1208 | break; | 1212 | break; |
1209 | } | 1213 | } |
1210 | case LUA_GCINC: { | 1214 | case LUA_GCINC: { |
1211 | int pause = va_arg(argp, int); | 1215 | unsigned int pause = va_arg(argp, unsigned int); |
1212 | int stepmul = va_arg(argp, int); | 1216 | unsigned int stepmul = va_arg(argp, unsigned int); |
1213 | int stepsize = va_arg(argp, int); | 1217 | unsigned int stepsize = va_arg(argp, unsigned int); |
1214 | res = isdecGCmodegen(g) ? LUA_GCGEN : LUA_GCINC; | 1218 | res = (g->gckind == KGC_INC) ? LUA_GCINC : LUA_GCGEN; |
1215 | if (pause != 0) | 1219 | if (pause != 0) |
1216 | setgcparam(g->gcpause, pause); | 1220 | setgcparam(g, gcpause, pause); |
1217 | if (stepmul != 0) | 1221 | if (stepmul != 0) |
1218 | setgcparam(g->gcstepmul, stepmul); | 1222 | setgcparam(g, gcstepmul, stepmul); |
1219 | if (stepsize != 0) | 1223 | if (stepsize != 0) |
1220 | g->gcstepsize = stepsize; | 1224 | g->gcstepsize = (stepsize <= log2maxs(l_obj)) ? stepsize |
1225 | : log2maxs(l_obj); | ||
1221 | luaC_changemode(L, KGC_INC); | 1226 | luaC_changemode(L, KGC_INC); |
1222 | break; | 1227 | break; |
1223 | } | 1228 | } |
@@ -1285,13 +1290,14 @@ LUA_API void lua_toclose (lua_State *L, int idx) { | |||
1285 | LUA_API void lua_concat (lua_State *L, int n) { | 1290 | LUA_API void lua_concat (lua_State *L, int n) { |
1286 | lua_lock(L); | 1291 | lua_lock(L); |
1287 | api_checknelems(L, n); | 1292 | api_checknelems(L, n); |
1288 | if (n > 0) | 1293 | if (n > 0) { |
1289 | luaV_concat(L, n); | 1294 | luaV_concat(L, n); |
1295 | luaC_checkGC(L); | ||
1296 | } | ||
1290 | else { /* nothing to concatenate */ | 1297 | else { /* nothing to concatenate */ |
1291 | setsvalue2s(L, L->top.p, luaS_newlstr(L, "", 0)); /* push empty string */ | 1298 | setsvalue2s(L, L->top.p, luaS_newlstr(L, "", 0)); /* push empty string */ |
1292 | api_incr_top(L); | 1299 | api_incr_top(L); |
1293 | } | 1300 | } |
1294 | luaC_checkGC(L); | ||
1295 | lua_unlock(L); | 1301 | lua_unlock(L); |
1296 | } | 1302 | } |
1297 | 1303 | ||