aboutsummaryrefslogtreecommitdiff
path: root/lbaselib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-12-22 14:48:07 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-12-22 14:48:07 -0300
commite2cc179454c6aa6cde5f98954bd3783e0d5d53a3 (patch)
tree1770fb2eded15ad53211693b19eb2a8698cbf192 /lbaselib.c
parentad0ea7813b39e76b377983138ca995189e22054f (diff)
downloadlua-e2cc179454c6aa6cde5f98954bd3783e0d5d53a3.tar.gz
lua-e2cc179454c6aa6cde5f98954bd3783e0d5d53a3.tar.bz2
lua-e2cc179454c6aa6cde5f98954bd3783e0d5d53a3.zip
New option "setparms" for 'collectgarbage'
The generational mode also uses the parameters for the incremental mode in its major collections, so it should be easy to change those parameters without having to change the GC mode.
Diffstat (limited to 'lbaselib.c')
-rw-r--r--lbaselib.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/lbaselib.c b/lbaselib.c
index 9ad84dcf..03df57f8 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -198,9 +198,11 @@ static int pushmode (lua_State *L, int oldmode) {
198 198
199static int luaB_collectgarbage (lua_State *L) { 199static int luaB_collectgarbage (lua_State *L) {
200 static const char *const opts[] = {"stop", "restart", "collect", 200 static const char *const opts[] = {"stop", "restart", "collect",
201 "count", "step", "isrunning", "generational", "incremental", NULL}; 201 "count", "step", "isrunning", "generational", "incremental",
202 static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT, 202 "setparam", NULL};
203 LUA_GCCOUNT, LUA_GCSTEP, LUA_GCISRUNNING, LUA_GCGEN, LUA_GCINC}; 203 static const char optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
204 LUA_GCCOUNT, LUA_GCSTEP, LUA_GCISRUNNING, LUA_GCGEN, LUA_GCINC,
205 LUA_GCSETPARAM};
204 int o = optsnum[luaL_checkoption(L, 1, "collect", opts)]; 206 int o = optsnum[luaL_checkoption(L, 1, "collect", opts)];
205 switch (o) { 207 switch (o) {
206 case LUA_GCCOUNT: { 208 case LUA_GCCOUNT: {
@@ -224,17 +226,39 @@ static int luaB_collectgarbage (lua_State *L) {
224 return 1; 226 return 1;
225 } 227 }
226 case LUA_GCGEN: { 228 case LUA_GCGEN: {
229#if defined(LUA_COMPAT_GCPARAMS)
227 int minormul = (int)luaL_optinteger(L, 2, -1); 230 int minormul = (int)luaL_optinteger(L, 2, -1);
228 int majorminor = (int)luaL_optinteger(L, 3, -1); 231 int majorminor = (int)luaL_optinteger(L, 3, -1);
229 int minormajor = (int)luaL_optinteger(L, 4, -1); 232#else
230 return pushmode(L, lua_gc(L, o, minormul, majorminor, minormajor)); 233 int minormul = 0;
234 int majorminor = 0;
235#endif
236 return pushmode(L, lua_gc(L, o, minormul, majorminor));
231 } 237 }
232 case LUA_GCINC: { 238 case LUA_GCINC: {
239#if defined(LUA_COMPAT_GCPARAMS)
233 int pause = (int)luaL_optinteger(L, 2, -1); 240 int pause = (int)luaL_optinteger(L, 2, -1);
234 int stepmul = (int)luaL_optinteger(L, 3, -1); 241 int stepmul = (int)luaL_optinteger(L, 3, -1);
235 int stepsize = (int)luaL_optinteger(L, 4, -1); 242 int stepsize = (int)luaL_optinteger(L, 4, -1);
243#else
244 int pause = 0;
245 int stepmul = 0;
246 int stepsize = 0;
247#endif
236 return pushmode(L, lua_gc(L, o, pause, stepmul, stepsize)); 248 return pushmode(L, lua_gc(L, o, pause, stepmul, stepsize));
237 } 249 }
250 case LUA_GCSETPARAM: {
251 static const char *const params[] = {
252 "minormul", "majorminor", "minormajor",
253 "pause", "stepmul", "stepsize", NULL};
254 static const char pnum[] = {
255 LUA_GCPMINORMUL, LUA_GCPMAJORMINOR, LUA_GCPMINORMAJOR,
256 LUA_GCPPAUSE, LUA_GCPSTEPMUL, LUA_GCPSTEPSIZE};
257 int p = pnum[luaL_checkoption(L, 2, NULL, params)];
258 lua_Integer value = luaL_checkinteger(L, 3);
259 lua_pushinteger(L, lua_gc(L, o, p, value));
260 return 1;
261 }
238 default: { 262 default: {
239 int res = lua_gc(L, o); 263 int res = lua_gc(L, o);
240 checkvalres(res); 264 checkvalres(res);