浏览代码

'collectgarbage' returns old mode when changing mode

Roberto Ierusalimschy 7 年之前
父节点
当前提交
56e50e8bc5
共有 2 个文件被更改,包括 14 次插入6 次删除
  1. 5 1
      lapi.c
  2. 9 5
      lbaselib.c

+ 5 - 1
lapi.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lapi.c,v 2.281 2018/01/28 15:13:26 roberto Exp roberto $
+** $Id: lapi.c,v 2.282 2018/01/29 16:21:35 roberto Exp roberto $
 ** Lua API
 ** Lua API
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -1121,6 +1121,7 @@ LUA_API int lua_gc (lua_State *L, int what, ...) {
       break;
       break;
     }
     }
     case LUA_GCGEN: {
     case LUA_GCGEN: {
+      int oldmode = g->gckind;
       int minormul = va_arg(argp, int);
       int minormul = va_arg(argp, int);
       int majormul = va_arg(argp, int);
       int majormul = va_arg(argp, int);
       if (minormul != 0)
       if (minormul != 0)
@@ -1128,9 +1129,11 @@ LUA_API int lua_gc (lua_State *L, int what, ...) {
       if (majormul != 0)
       if (majormul != 0)
         setgcparam(g->genmajormul, majormul);
         setgcparam(g->genmajormul, majormul);
       luaC_changemode(L, KGC_GEN);
       luaC_changemode(L, KGC_GEN);
+      res = (oldmode == KGC_GEN) ? LUA_GCGEN : LUA_GCINC;
       break;
       break;
     }
     }
     case LUA_GCINC: {
     case LUA_GCINC: {
+      int oldmode = g->gckind;
       int pause = va_arg(argp, int);
       int pause = va_arg(argp, int);
       int stepmul = va_arg(argp, int);
       int stepmul = va_arg(argp, int);
       int stepsize = va_arg(argp, int);
       int stepsize = va_arg(argp, int);
@@ -1141,6 +1144,7 @@ LUA_API int lua_gc (lua_State *L, int what, ...) {
       if (stepsize != 0)
       if (stepsize != 0)
         g->gcstepsize = stepsize;
         g->gcstepsize = stepsize;
       luaC_changemode(L, KGC_INC);
       luaC_changemode(L, KGC_INC);
+      res = (oldmode == KGC_GEN) ? LUA_GCGEN : LUA_GCINC;
       break;
       break;
     }
     }
     default: res = -1;  /* invalid option */
     default: res = -1;  /* invalid option */

+ 9 - 5
lbaselib.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lbaselib.c,v 1.317 2017/06/27 18:32:49 roberto Exp roberto $
+** $Id: lbaselib.c,v 1.318 2017/11/16 13:19:06 roberto Exp roberto $
 ** Basic library
 ** Basic library
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -170,6 +170,12 @@ static int luaB_rawset (lua_State *L) {
 }
 }
 
 
 
 
+static int pushmode (lua_State *L, int oldmode) {
+  lua_pushstring(L, (oldmode == LUA_GCINC) ? "incremental" : "generational");
+  return 1;
+}
+
+
 static int luaB_collectgarbage (lua_State *L) {
 static int luaB_collectgarbage (lua_State *L) {
   static const char *const opts[] = {"stop", "restart", "collect",
   static const char *const opts[] = {"stop", "restart", "collect",
     "count", "step", "setpause", "setstepmul",
     "count", "step", "setpause", "setstepmul",
@@ -206,15 +212,13 @@ static int luaB_collectgarbage (lua_State *L) {
     case LUA_GCGEN: {
     case LUA_GCGEN: {
       int minormul = (int)luaL_optinteger(L, 2, 0);
       int minormul = (int)luaL_optinteger(L, 2, 0);
       int majormul = (int)luaL_optinteger(L, 3, 0);
       int majormul = (int)luaL_optinteger(L, 3, 0);
-      lua_gc(L, o, minormul, majormul);
-      return 0;
+      return pushmode(L, lua_gc(L, o, minormul, majormul));
     }
     }
     case LUA_GCINC: {
     case LUA_GCINC: {
       int pause = (int)luaL_optinteger(L, 2, 0);
       int pause = (int)luaL_optinteger(L, 2, 0);
       int stepmul = (int)luaL_optinteger(L, 3, 0);
       int stepmul = (int)luaL_optinteger(L, 3, 0);
       int stepsize = (int)luaL_optinteger(L, 4, 0);
       int stepsize = (int)luaL_optinteger(L, 4, 0);
-      lua_gc(L, o, pause, stepmul, stepsize);
-      return 0;
+      return pushmode(L, lua_gc(L, o, pause, stepmul, stepsize));
     }
     }
     default: {
     default: {
       int res = lua_gc(L, o);
       int res = lua_gc(L, o);