diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-01-11 15:03:01 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-01-11 15:03:01 -0300 |
commit | cc1692515e2a6aabc6d07159e7926656e38eda53 (patch) | |
tree | bc89a17cdc55a52897cc0d5a862cbc34314ada93 /testes | |
parent | ce101dcaf73ff6d610593230d41b63c163a91519 (diff) | |
download | lua-cc1692515e2a6aabc6d07159e7926656e38eda53.tar.gz lua-cc1692515e2a6aabc6d07159e7926656e38eda53.tar.bz2 lua-cc1692515e2a6aabc6d07159e7926656e38eda53.zip |
New API function 'lua_closeslot'
Closing a to-be-closed variable with 'lua_settop' is too restrictive,
as it erases all slots above the variable. Moreover, it adds side
effects to 'lua_settop', which should be a fairly basic function.
Diffstat (limited to 'testes')
-rw-r--r-- | testes/api.lua | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/testes/api.lua b/testes/api.lua index 95551481..fb7e7085 100644 --- a/testes/api.lua +++ b/testes/api.lua | |||
@@ -507,10 +507,12 @@ function checkerrnopro (code, msg) | |||
507 | end | 507 | end |
508 | 508 | ||
509 | if not _soft then | 509 | if not _soft then |
510 | collectgarbage("stop") -- avoid __gc with full stack | ||
510 | checkerrnopro("pushnum 3; call 0 0", "attempt to call") | 511 | checkerrnopro("pushnum 3; call 0 0", "attempt to call") |
511 | print"testing stack overflow in unprotected thread" | 512 | print"testing stack overflow in unprotected thread" |
512 | function f () f() end | 513 | function f () f() end |
513 | checkerrnopro("getglobal 'f'; call 0 0;", "stack overflow") | 514 | checkerrnopro("getglobal 'f'; call 0 0;", "stack overflow") |
515 | collectgarbage("restart") | ||
514 | end | 516 | end |
515 | print"+" | 517 | print"+" |
516 | 518 | ||
@@ -1125,26 +1127,29 @@ do | |||
1125 | assert(#openresource == n) | 1127 | assert(#openresource == n) |
1126 | end | 1128 | end |
1127 | 1129 | ||
1128 | -- closing resources with 'settop' | 1130 | -- closing resources with 'closeslot' |
1131 | _ENV.xxx = true | ||
1129 | local a = T.testC([[ | 1132 | local a = T.testC([[ |
1130 | pushvalue 2 | 1133 | pushvalue 2 # stack: S, NR, CH |
1131 | call 0 1 # create resource | 1134 | call 0 1 # create resource; stack: S, NR, CH, R |
1132 | toclose -1 # mark it to be closed | 1135 | toclose -1 # mark it to be closed |
1133 | pushvalue 2 | 1136 | pushvalue 2 # stack: S, NR, CH, R, NR |
1134 | call 0 1 # create another resource | 1137 | call 0 1 # create another resource; stack: S, NR, CH, R, R |
1135 | toclose -1 # mark it to be closed | 1138 | toclose -1 # mark it to be closed |
1136 | pushvalue 3 | 1139 | pushvalue 3 # stack: S, NR, CH, R, R, CH |
1137 | pushint 2 # there should be two open resources | 1140 | pushint 2 # there should be two open resources |
1138 | call 1 0 | 1141 | call 1 0 # stack: S, NR, CH, R, R |
1139 | pop 1 # pop second resource from the stack | 1142 | closeslot -1 # close second resource |
1140 | pushvalue 3 | 1143 | pushvalue 3 # stack: S, NR, CH, R, R, CH |
1141 | pushint 1 # there should be one open resource | 1144 | pushint 1 # there should be one open resource |
1142 | call 1 0 | 1145 | call 1 0 # stack: S, NR, CH, R, R |
1143 | pop 1 # pop second resource from the stack | 1146 | closeslot 4 |
1147 | setglobal "xxx" # previous op. erased the slot | ||
1148 | pop 1 # pop other resource from the stack | ||
1144 | pushint * | 1149 | pushint * |
1145 | return 1 # return stack size | 1150 | return 1 # return stack size |
1146 | ]], newresource, check) | 1151 | ]], newresource, check) |
1147 | assert(a == 3) -- no extra items left in the stack | 1152 | assert(a == 3 and _ENV.xxx == nil) -- no extra items left in the stack |
1148 | 1153 | ||
1149 | -- non-closable value | 1154 | -- non-closable value |
1150 | local a, b = pcall(T.makeCfunc[[ | 1155 | local a, b = pcall(T.makeCfunc[[ |