mirror of
https://github.com/lua/lua
synced 2024-11-22 04:41:23 +03:00
Removed compatibility option LUA_COMPAT_GCPARAMS
The meaning of different GC parameters changed, so there is point in supporting old values for them. The new code simply ignores the parameters when changing the GC mode, so the incompatibility is small.
This commit is contained in:
parent
e2cc179454
commit
e81f586001
14
lapi.c
14
lapi.c
@ -1186,25 +1186,11 @@ LUA_API int lua_gc (lua_State *L, int what, ...) {
|
||||
break;
|
||||
}
|
||||
case LUA_GCGEN: {
|
||||
#if defined(LUA_COMPAT_GCPARAMS)
|
||||
int minormul = va_arg(argp, int);
|
||||
int minormajor = va_arg(argp, int);
|
||||
if (minormul > 0) setgcparam(g, MINORMUL, minormul);
|
||||
if (minormajor > 0) setgcparam(g, MINORMAJOR, minormajor);
|
||||
#endif
|
||||
res = (g->gckind == KGC_INC) ? LUA_GCINC : LUA_GCGEN;
|
||||
luaC_changemode(L, KGC_GENMINOR);
|
||||
break;
|
||||
}
|
||||
case LUA_GCINC: {
|
||||
#if defined(LUA_COMPAT_GCPARAMS)
|
||||
int pause = va_arg(argp, int);
|
||||
int stepmul = va_arg(argp, int);
|
||||
int stepsize = va_arg(argp, int);
|
||||
if (pause > 0) setgcparam(g, PAUSE, pause);
|
||||
if (stepmul > 0) setgcparam(g, STEPMUL, stepmul);
|
||||
if (stepsize > 0) setgcparam(g, STEPSIZE, 1u << stepsize);
|
||||
#endif
|
||||
res = (g->gckind == KGC_INC) ? LUA_GCINC : LUA_GCGEN;
|
||||
luaC_changemode(L, KGC_INC);
|
||||
break;
|
||||
|
23
lbaselib.c
23
lbaselib.c
@ -213,8 +213,7 @@ static int luaB_collectgarbage (lua_State *L) {
|
||||
return 1;
|
||||
}
|
||||
case LUA_GCSTEP: {
|
||||
int step = (int)luaL_optinteger(L, 2, 0);
|
||||
int res = lua_gc(L, o, step);
|
||||
int res = lua_gc(L, o);
|
||||
checkvalres(res);
|
||||
lua_pushboolean(L, res);
|
||||
return 1;
|
||||
@ -226,26 +225,10 @@ static int luaB_collectgarbage (lua_State *L) {
|
||||
return 1;
|
||||
}
|
||||
case LUA_GCGEN: {
|
||||
#if defined(LUA_COMPAT_GCPARAMS)
|
||||
int minormul = (int)luaL_optinteger(L, 2, -1);
|
||||
int majorminor = (int)luaL_optinteger(L, 3, -1);
|
||||
#else
|
||||
int minormul = 0;
|
||||
int majorminor = 0;
|
||||
#endif
|
||||
return pushmode(L, lua_gc(L, o, minormul, majorminor));
|
||||
return pushmode(L, lua_gc(L, o));
|
||||
}
|
||||
case LUA_GCINC: {
|
||||
#if defined(LUA_COMPAT_GCPARAMS)
|
||||
int pause = (int)luaL_optinteger(L, 2, -1);
|
||||
int stepmul = (int)luaL_optinteger(L, 3, -1);
|
||||
int stepsize = (int)luaL_optinteger(L, 4, -1);
|
||||
#else
|
||||
int pause = 0;
|
||||
int stepmul = 0;
|
||||
int stepsize = 0;
|
||||
#endif
|
||||
return pushmode(L, lua_gc(L, o, pause, stepmul, stepsize));
|
||||
return pushmode(L, lua_gc(L, o));
|
||||
}
|
||||
case LUA_GCSETPARAM: {
|
||||
static const char *const params[] = {
|
||||
|
2
ltests.h
2
ltests.h
@ -15,8 +15,6 @@
|
||||
#define LUA_COMPAT_MATHLIB
|
||||
#define LUA_COMPAT_LT_LE
|
||||
|
||||
#define LUA_COMPAT_GCPARAMS
|
||||
|
||||
|
||||
#define LUA_DEBUG
|
||||
|
||||
|
2
lua.c
2
lua.c
@ -646,7 +646,7 @@ static int pmain (lua_State *L) {
|
||||
luai_openlibs(L); /* open standard libraries */
|
||||
createargtable(L, argv, argc, script); /* create table 'arg' */
|
||||
lua_gc(L, LUA_GCRESTART); /* start GC... */
|
||||
lua_gc(L, LUA_GCGEN, 0, 0); /* ...in generational mode */
|
||||
lua_gc(L, LUA_GCGEN); /* ...in generational mode */
|
||||
if (!(args & has_E)) { /* no option '-E'? */
|
||||
if (handle_luainit(L) != LUA_OK) /* run LUA_INIT */
|
||||
return 0; /* error running LUA_INIT */
|
||||
|
@ -504,7 +504,7 @@ end
|
||||
do
|
||||
collectgarbage()
|
||||
collectgarbage"stop"
|
||||
collectgarbage("step", 0) -- steps should not unblock the collector
|
||||
collectgarbage("step") -- steps should not unblock the collector
|
||||
local x = gcinfo()
|
||||
repeat
|
||||
for i=1,1000 do _ENV.a = {} end -- no collection during the loop
|
||||
|
@ -24,12 +24,12 @@ do
|
||||
assert(not T or (T.gcage(U) == "touched1" and T.gcage(U[1]) == "new"))
|
||||
|
||||
-- both U and the table survive one more collection
|
||||
collectgarbage("step", 0)
|
||||
collectgarbage("step")
|
||||
assert(not T or (T.gcage(U) == "touched2" and T.gcage(U[1]) == "survival"))
|
||||
|
||||
-- both U and the table survive yet another collection
|
||||
-- now everything is old
|
||||
collectgarbage("step", 0)
|
||||
collectgarbage("step")
|
||||
assert(not T or (T.gcage(U) == "old" and T.gcage(U[1]) == "old1"))
|
||||
|
||||
-- data was not corrupted
|
||||
@ -46,10 +46,10 @@ do
|
||||
assert(not T or T.gcage(old) == "old")
|
||||
setmetatable(old, {}) -- new table becomes OLD0 (barrier)
|
||||
assert(not T or T.gcage(getmetatable(old)) == "old0")
|
||||
collectgarbage("step", 0) -- new table becomes OLD1 and firstold1
|
||||
collectgarbage("step") -- new table becomes OLD1 and firstold1
|
||||
assert(not T or T.gcage(getmetatable(old)) == "old1")
|
||||
setmetatable(getmetatable(old), {__gc = foo}) -- get it out of allgc list
|
||||
collectgarbage("step", 0) -- should not seg. fault
|
||||
collectgarbage("step") -- should not seg. fault
|
||||
end
|
||||
|
||||
|
||||
@ -65,18 +65,18 @@ do -- bug in 5.4.0
|
||||
A[1] = obj -- anchor object
|
||||
assert(not T or T.gcage(obj) == "old1")
|
||||
obj = nil -- remove it from the stack
|
||||
collectgarbage("step", 0) -- do a young collection
|
||||
collectgarbage("step") -- do a young collection
|
||||
print(getmetatable(A[1]).x) -- metatable was collected
|
||||
end
|
||||
|
||||
collectgarbage() -- make A old
|
||||
local obj = {} -- create a new object
|
||||
collectgarbage("step", 0) -- make it a survival
|
||||
collectgarbage("step") -- make it a survival
|
||||
assert(not T or T.gcage(obj) == "survival")
|
||||
setmetatable(obj, {__gc = gcf, x = "+"}) -- create its metatable
|
||||
assert(not T or T.gcage(getmetatable(obj)) == "new")
|
||||
obj = nil -- clear object
|
||||
collectgarbage("step", 0) -- will call obj's finalizer
|
||||
collectgarbage("step") -- will call obj's finalizer
|
||||
end
|
||||
|
||||
|
||||
@ -94,13 +94,13 @@ do -- another bug in 5.4.0
|
||||
end
|
||||
)
|
||||
local _, f = coroutine.resume(co) -- create closure over 'x' in coroutine
|
||||
collectgarbage("step", 0) -- make upvalue a survival
|
||||
collectgarbage("step") -- make upvalue a survival
|
||||
old[1] = {"hello"} -- 'old' go to grayagain as 'touched1'
|
||||
coroutine.resume(co, {123}) -- its value will be new
|
||||
co = nil
|
||||
collectgarbage("step", 0) -- hit the barrier
|
||||
collectgarbage("step") -- hit the barrier
|
||||
assert(f() == 123 and old[1][1] == "hello")
|
||||
collectgarbage("step", 0) -- run the collector once more
|
||||
collectgarbage("step") -- run the collector once more
|
||||
-- make sure old[1] was not collected
|
||||
assert(f() == 123 and old[1][1] == "hello")
|
||||
end
|
||||
@ -112,12 +112,12 @@ do -- bug introduced in commit 9cf3299fa
|
||||
assert(not T or T.gcage(t) == "old")
|
||||
t[1] = {10}
|
||||
assert(not T or (T.gcage(t) == "touched1" and T.gccolor(t) == "gray"))
|
||||
collectgarbage("step", 0) -- minor collection
|
||||
collectgarbage("step") -- minor collection
|
||||
assert(not T or (T.gcage(t) == "touched2" and T.gccolor(t) == "black"))
|
||||
collectgarbage("step", 0) -- minor collection
|
||||
collectgarbage("step") -- minor collection
|
||||
assert(not T or T.gcage(t) == "old") -- t should be black, but it was gray
|
||||
t[1] = {10} -- no barrier here, so t was still old
|
||||
collectgarbage("step", 0) -- minor collection
|
||||
collectgarbage("step") -- minor collection
|
||||
-- t, being old, is ignored by the collection, so it is not cleared
|
||||
assert(t[1] == nil) -- fails with the bug
|
||||
end
|
||||
@ -144,13 +144,13 @@ do
|
||||
T.gcage(debug.getuservalue(U)) == "new")
|
||||
|
||||
-- both U and the table survive one more collection
|
||||
collectgarbage("step", 0)
|
||||
collectgarbage("step")
|
||||
assert(T.gcage(U) == "touched2" and
|
||||
T.gcage(debug.getuservalue(U)) == "survival")
|
||||
|
||||
-- both U and the table survive yet another collection
|
||||
-- now everything is old
|
||||
collectgarbage("step", 0)
|
||||
collectgarbage("step")
|
||||
assert(T.gcage(U) == "old" and
|
||||
T.gcage(debug.getuservalue(U)) == "old1")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user