diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-03-09 11:42:45 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-03-09 11:42:45 -0300 |
commit | 511d53a826760dd11cd82947184583e2d094e2d2 (patch) | |
tree | 60dc1a2da1198fc7c9e058b794b03c757e0c48f7 /testes | |
parent | f5df7f91f70234850484d26caf24e71e001e5304 (diff) | |
download | lua-511d53a826760dd11cd82947184583e2d094e2d2.tar.gz lua-511d53a826760dd11cd82947184583e2d094e2d2.tar.bz2 lua-511d53a826760dd11cd82947184583e2d094e2d2.zip |
lua_settop/lua_pop closes to-be-closed variables
The existence of 'lua_closeslot' is no reason for lua_pop not to close
to-be-closed variables too. It is too error-prone for lua_pop not to
close tbc variables being popped from the stack.
Diffstat (limited to 'testes')
-rw-r--r-- | testes/api.lua | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/testes/api.lua b/testes/api.lua index fb7e7085..c1bcb4b7 100644 --- a/testes/api.lua +++ b/testes/api.lua | |||
@@ -1130,7 +1130,7 @@ do | |||
1130 | -- closing resources with 'closeslot' | 1130 | -- closing resources with 'closeslot' |
1131 | _ENV.xxx = true | 1131 | _ENV.xxx = true |
1132 | local a = T.testC([[ | 1132 | local a = T.testC([[ |
1133 | pushvalue 2 # stack: S, NR, CH | 1133 | pushvalue 2 # stack: S, NR, CH, NR |
1134 | call 0 1 # create resource; stack: S, NR, CH, R | 1134 | call 0 1 # create resource; stack: S, NR, CH, R |
1135 | toclose -1 # mark it to be closed | 1135 | toclose -1 # mark it to be closed |
1136 | pushvalue 2 # stack: S, NR, CH, R, NR | 1136 | pushvalue 2 # stack: S, NR, CH, R, NR |
@@ -1151,6 +1151,30 @@ do | |||
1151 | ]], newresource, check) | 1151 | ]], newresource, check) |
1152 | assert(a == 3 and _ENV.xxx == nil) -- no extra items left in the stack | 1152 | assert(a == 3 and _ENV.xxx == nil) -- no extra items left in the stack |
1153 | 1153 | ||
1154 | -- closing resources with 'pop' | ||
1155 | local a = T.testC([[ | ||
1156 | pushvalue 2 # stack: S, NR, CH, NR | ||
1157 | call 0 1 # create resource; stack: S, NR, CH, R | ||
1158 | toclose -1 # mark it to be closed | ||
1159 | pushvalue 2 # stack: S, NR, CH, R, NR | ||
1160 | call 0 1 # create another resource; stack: S, NR, CH, R, R | ||
1161 | toclose -1 # mark it to be closed | ||
1162 | pushvalue 3 # stack: S, NR, CH, R, R, CH | ||
1163 | pushint 2 # there should be two open resources | ||
1164 | call 1 0 # stack: S, NR, CH, R, R | ||
1165 | pop 1 # pop second resource | ||
1166 | pushvalue 3 # stack: S, NR, CH, R, CH | ||
1167 | pushint 1 # there should be one open resource | ||
1168 | call 1 0 # stack: S, NR, CH, R | ||
1169 | pop 1 # pop other resource from the stack | ||
1170 | pushvalue 3 # stack: S, NR, CH, CH | ||
1171 | pushint 0 # there should be no open resources | ||
1172 | call 1 0 # stack: S, NR, CH | ||
1173 | pushint * | ||
1174 | return 1 # return stack size | ||
1175 | ]], newresource, check) | ||
1176 | assert(a == 3) -- no extra items left in the stack | ||
1177 | |||
1154 | -- non-closable value | 1178 | -- non-closable value |
1155 | local a, b = pcall(T.makeCfunc[[ | 1179 | local a, b = pcall(T.makeCfunc[[ |
1156 | pushint 32 | 1180 | pushint 32 |