aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-12-22 14:57:43 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-12-22 14:57:43 -0300
commite81f586001d767c8de9b760ae2e2c3b5da1542c6 (patch)
tree26032fb57c824d62a4c1547159d58f5d5c223e96
parente2cc179454c6aa6cde5f98954bd3783e0d5d53a3 (diff)
downloadlua-e81f586001d767c8de9b760ae2e2c3b5da1542c6.tar.gz
lua-e81f586001d767c8de9b760ae2e2c3b5da1542c6.tar.bz2
lua-e81f586001d767c8de9b760ae2e2c3b5da1542c6.zip
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.
Diffstat (limited to '')
-rw-r--r--lapi.c14
-rw-r--r--lbaselib.c23
-rw-r--r--ltests.h2
-rw-r--r--lua.c2
-rw-r--r--testes/gc.lua2
-rw-r--r--testes/gengc.lua30
6 files changed, 20 insertions, 53 deletions
diff --git a/lapi.c b/lapi.c
index aa2ee735..dcdc1cd3 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1186,25 +1186,11 @@ LUA_API int lua_gc (lua_State *L, int what, ...) {
1186 break; 1186 break;
1187 } 1187 }
1188 case LUA_GCGEN: { 1188 case LUA_GCGEN: {
1189#if defined(LUA_COMPAT_GCPARAMS)
1190 int minormul = va_arg(argp, int);
1191 int minormajor = va_arg(argp, int);
1192 if (minormul > 0) setgcparam(g, MINORMUL, minormul);
1193 if (minormajor > 0) setgcparam(g, MINORMAJOR, minormajor);
1194#endif
1195 res = (g->gckind == KGC_INC) ? LUA_GCINC : LUA_GCGEN; 1189 res = (g->gckind == KGC_INC) ? LUA_GCINC : LUA_GCGEN;
1196 luaC_changemode(L, KGC_GENMINOR); 1190 luaC_changemode(L, KGC_GENMINOR);
1197 break; 1191 break;
1198 } 1192 }
1199 case LUA_GCINC: { 1193 case LUA_GCINC: {
1200#if defined(LUA_COMPAT_GCPARAMS)
1201 int pause = va_arg(argp, int);
1202 int stepmul = va_arg(argp, int);
1203 int stepsize = va_arg(argp, int);
1204 if (pause > 0) setgcparam(g, PAUSE, pause);
1205 if (stepmul > 0) setgcparam(g, STEPMUL, stepmul);
1206 if (stepsize > 0) setgcparam(g, STEPSIZE, 1u << stepsize);
1207#endif
1208 res = (g->gckind == KGC_INC) ? LUA_GCINC : LUA_GCGEN; 1194 res = (g->gckind == KGC_INC) ? LUA_GCINC : LUA_GCGEN;
1209 luaC_changemode(L, KGC_INC); 1195 luaC_changemode(L, KGC_INC);
1210 break; 1196 break;
diff --git a/lbaselib.c b/lbaselib.c
index 03df57f8..a9d39e9f 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -213,8 +213,7 @@ static int luaB_collectgarbage (lua_State *L) {
213 return 1; 213 return 1;
214 } 214 }
215 case LUA_GCSTEP: { 215 case LUA_GCSTEP: {
216 int step = (int)luaL_optinteger(L, 2, 0); 216 int res = lua_gc(L, o);
217 int res = lua_gc(L, o, step);
218 checkvalres(res); 217 checkvalres(res);
219 lua_pushboolean(L, res); 218 lua_pushboolean(L, res);
220 return 1; 219 return 1;
@@ -226,26 +225,10 @@ static int luaB_collectgarbage (lua_State *L) {
226 return 1; 225 return 1;
227 } 226 }
228 case LUA_GCGEN: { 227 case LUA_GCGEN: {
229#if defined(LUA_COMPAT_GCPARAMS) 228 return pushmode(L, lua_gc(L, o));
230 int minormul = (int)luaL_optinteger(L, 2, -1);
231 int majorminor = (int)luaL_optinteger(L, 3, -1);
232#else
233 int minormul = 0;
234 int majorminor = 0;
235#endif
236 return pushmode(L, lua_gc(L, o, minormul, majorminor));
237 } 229 }
238 case LUA_GCINC: { 230 case LUA_GCINC: {
239#if defined(LUA_COMPAT_GCPARAMS) 231 return pushmode(L, lua_gc(L, o));
240 int pause = (int)luaL_optinteger(L, 2, -1);
241 int stepmul = (int)luaL_optinteger(L, 3, -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
248 return pushmode(L, lua_gc(L, o, pause, stepmul, stepsize));
249 } 232 }
250 case LUA_GCSETPARAM: { 233 case LUA_GCSETPARAM: {
251 static const char *const params[] = { 234 static const char *const params[] = {
diff --git a/ltests.h b/ltests.h
index 70afa7a3..da773d6e 100644
--- a/ltests.h
+++ b/ltests.h
@@ -15,8 +15,6 @@
15#define LUA_COMPAT_MATHLIB 15#define LUA_COMPAT_MATHLIB
16#define LUA_COMPAT_LT_LE 16#define LUA_COMPAT_LT_LE
17 17
18#define LUA_COMPAT_GCPARAMS
19
20 18
21#define LUA_DEBUG 19#define LUA_DEBUG
22 20
diff --git a/lua.c b/lua.c
index 1e884b07..e574ec9b 100644
--- a/lua.c
+++ b/lua.c
@@ -646,7 +646,7 @@ static int pmain (lua_State *L) {
646 luai_openlibs(L); /* open standard libraries */ 646 luai_openlibs(L); /* open standard libraries */
647 createargtable(L, argv, argc, script); /* create table 'arg' */ 647 createargtable(L, argv, argc, script); /* create table 'arg' */
648 lua_gc(L, LUA_GCRESTART); /* start GC... */ 648 lua_gc(L, LUA_GCRESTART); /* start GC... */
649 lua_gc(L, LUA_GCGEN, 0, 0); /* ...in generational mode */ 649 lua_gc(L, LUA_GCGEN); /* ...in generational mode */
650 if (!(args & has_E)) { /* no option '-E'? */ 650 if (!(args & has_E)) { /* no option '-E'? */
651 if (handle_luainit(L) != LUA_OK) /* run LUA_INIT */ 651 if (handle_luainit(L) != LUA_OK) /* run LUA_INIT */
652 return 0; /* error running LUA_INIT */ 652 return 0; /* error running LUA_INIT */
diff --git a/testes/gc.lua b/testes/gc.lua
index 61b5da9c..8bacffa0 100644
--- a/testes/gc.lua
+++ b/testes/gc.lua
@@ -504,7 +504,7 @@ end
504do 504do
505 collectgarbage() 505 collectgarbage()
506 collectgarbage"stop" 506 collectgarbage"stop"
507 collectgarbage("step", 0) -- steps should not unblock the collector 507 collectgarbage("step") -- steps should not unblock the collector
508 local x = gcinfo() 508 local x = gcinfo()
509 repeat 509 repeat
510 for i=1,1000 do _ENV.a = {} end -- no collection during the loop 510 for i=1,1000 do _ENV.a = {} end -- no collection during the loop
diff --git a/testes/gengc.lua b/testes/gengc.lua
index cae07285..51872cc1 100644
--- a/testes/gengc.lua
+++ b/testes/gengc.lua
@@ -24,12 +24,12 @@ do
24 assert(not T or (T.gcage(U) == "touched1" and T.gcage(U[1]) == "new")) 24 assert(not T or (T.gcage(U) == "touched1" and T.gcage(U[1]) == "new"))
25 25
26 -- both U and the table survive one more collection 26 -- both U and the table survive one more collection
27 collectgarbage("step", 0) 27 collectgarbage("step")
28 assert(not T or (T.gcage(U) == "touched2" and T.gcage(U[1]) == "survival")) 28 assert(not T or (T.gcage(U) == "touched2" and T.gcage(U[1]) == "survival"))
29 29
30 -- both U and the table survive yet another collection 30 -- both U and the table survive yet another collection
31 -- now everything is old 31 -- now everything is old
32 collectgarbage("step", 0) 32 collectgarbage("step")
33 assert(not T or (T.gcage(U) == "old" and T.gcage(U[1]) == "old1")) 33 assert(not T or (T.gcage(U) == "old" and T.gcage(U[1]) == "old1"))
34 34
35 -- data was not corrupted 35 -- data was not corrupted
@@ -46,10 +46,10 @@ do
46 assert(not T or T.gcage(old) == "old") 46 assert(not T or T.gcage(old) == "old")
47 setmetatable(old, {}) -- new table becomes OLD0 (barrier) 47 setmetatable(old, {}) -- new table becomes OLD0 (barrier)
48 assert(not T or T.gcage(getmetatable(old)) == "old0") 48 assert(not T or T.gcage(getmetatable(old)) == "old0")
49 collectgarbage("step", 0) -- new table becomes OLD1 and firstold1 49 collectgarbage("step") -- new table becomes OLD1 and firstold1
50 assert(not T or T.gcage(getmetatable(old)) == "old1") 50 assert(not T or T.gcage(getmetatable(old)) == "old1")
51 setmetatable(getmetatable(old), {__gc = foo}) -- get it out of allgc list 51 setmetatable(getmetatable(old), {__gc = foo}) -- get it out of allgc list
52 collectgarbage("step", 0) -- should not seg. fault 52 collectgarbage("step") -- should not seg. fault
53end 53end
54 54
55 55
@@ -65,18 +65,18 @@ do -- bug in 5.4.0
65 A[1] = obj -- anchor object 65 A[1] = obj -- anchor object
66 assert(not T or T.gcage(obj) == "old1") 66 assert(not T or T.gcage(obj) == "old1")
67 obj = nil -- remove it from the stack 67 obj = nil -- remove it from the stack
68 collectgarbage("step", 0) -- do a young collection 68 collectgarbage("step") -- do a young collection
69 print(getmetatable(A[1]).x) -- metatable was collected 69 print(getmetatable(A[1]).x) -- metatable was collected
70 end 70 end
71 71
72 collectgarbage() -- make A old 72 collectgarbage() -- make A old
73 local obj = {} -- create a new object 73 local obj = {} -- create a new object
74 collectgarbage("step", 0) -- make it a survival 74 collectgarbage("step") -- make it a survival
75 assert(not T or T.gcage(obj) == "survival") 75 assert(not T or T.gcage(obj) == "survival")
76 setmetatable(obj, {__gc = gcf, x = "+"}) -- create its metatable 76 setmetatable(obj, {__gc = gcf, x = "+"}) -- create its metatable
77 assert(not T or T.gcage(getmetatable(obj)) == "new") 77 assert(not T or T.gcage(getmetatable(obj)) == "new")
78 obj = nil -- clear object 78 obj = nil -- clear object
79 collectgarbage("step", 0) -- will call obj's finalizer 79 collectgarbage("step") -- will call obj's finalizer
80end 80end
81 81
82 82
@@ -94,13 +94,13 @@ do -- another bug in 5.4.0
94 end 94 end
95 ) 95 )
96 local _, f = coroutine.resume(co) -- create closure over 'x' in coroutine 96 local _, f = coroutine.resume(co) -- create closure over 'x' in coroutine
97 collectgarbage("step", 0) -- make upvalue a survival 97 collectgarbage("step") -- make upvalue a survival
98 old[1] = {"hello"} -- 'old' go to grayagain as 'touched1' 98 old[1] = {"hello"} -- 'old' go to grayagain as 'touched1'
99 coroutine.resume(co, {123}) -- its value will be new 99 coroutine.resume(co, {123}) -- its value will be new
100 co = nil 100 co = nil
101 collectgarbage("step", 0) -- hit the barrier 101 collectgarbage("step") -- hit the barrier
102 assert(f() == 123 and old[1][1] == "hello") 102 assert(f() == 123 and old[1][1] == "hello")
103 collectgarbage("step", 0) -- run the collector once more 103 collectgarbage("step") -- run the collector once more
104 -- make sure old[1] was not collected 104 -- make sure old[1] was not collected
105 assert(f() == 123 and old[1][1] == "hello") 105 assert(f() == 123 and old[1][1] == "hello")
106end 106end
@@ -112,12 +112,12 @@ do -- bug introduced in commit 9cf3299fa
112 assert(not T or T.gcage(t) == "old") 112 assert(not T or T.gcage(t) == "old")
113 t[1] = {10} 113 t[1] = {10}
114 assert(not T or (T.gcage(t) == "touched1" and T.gccolor(t) == "gray")) 114 assert(not T or (T.gcage(t) == "touched1" and T.gccolor(t) == "gray"))
115 collectgarbage("step", 0) -- minor collection 115 collectgarbage("step") -- minor collection
116 assert(not T or (T.gcage(t) == "touched2" and T.gccolor(t) == "black")) 116 assert(not T or (T.gcage(t) == "touched2" and T.gccolor(t) == "black"))
117 collectgarbage("step", 0) -- minor collection 117 collectgarbage("step") -- minor collection
118 assert(not T or T.gcage(t) == "old") -- t should be black, but it was gray 118 assert(not T or T.gcage(t) == "old") -- t should be black, but it was gray
119 t[1] = {10} -- no barrier here, so t was still old 119 t[1] = {10} -- no barrier here, so t was still old
120 collectgarbage("step", 0) -- minor collection 120 collectgarbage("step") -- minor collection
121 -- t, being old, is ignored by the collection, so it is not cleared 121 -- t, being old, is ignored by the collection, so it is not cleared
122 assert(t[1] == nil) -- fails with the bug 122 assert(t[1] == nil) -- fails with the bug
123end 123end
@@ -144,13 +144,13 @@ do
144 T.gcage(debug.getuservalue(U)) == "new") 144 T.gcage(debug.getuservalue(U)) == "new")
145 145
146 -- both U and the table survive one more collection 146 -- both U and the table survive one more collection
147 collectgarbage("step", 0) 147 collectgarbage("step")
148 assert(T.gcage(U) == "touched2" and 148 assert(T.gcage(U) == "touched2" and
149 T.gcage(debug.getuservalue(U)) == "survival") 149 T.gcage(debug.getuservalue(U)) == "survival")
150 150
151 -- both U and the table survive yet another collection 151 -- both U and the table survive yet another collection
152 -- now everything is old 152 -- now everything is old
153 collectgarbage("step", 0) 153 collectgarbage("step")
154 assert(T.gcage(U) == "old" and 154 assert(T.gcage(U) == "old" and
155 T.gcage(debug.getuservalue(U)) == "old1") 155 T.gcage(debug.getuservalue(U)) == "old1")
156 156