summaryrefslogtreecommitdiff
path: root/testes/api.lua
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-11-29 16:02:44 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-11-29 16:02:44 -0200
commit6d04537ea660fd12fc16c328366b701fabaf4919 (patch)
tree41eab6e4d87552e29731db552f7d58d679c56973 /testes/api.lua
parent7696c6474fe51ed59fee324e78c1233af74febdd (diff)
downloadlua-github-6d04537ea660fd12fc16c328366b701fabaf4919.tar.gz
A to-be-closed variable must have a closable value (or be nil)
It is an error for a to-be-closed variable to have a non-closable non-nil value when it is being closed. This situation does not seem to be useful and often hints to an error. (Particularly in the C API, it is easy to change a to-be-closed index by mistake.)
Diffstat (limited to 'testes/api.lua')
-rw-r--r--testes/api.lua21
1 files changed, 14 insertions, 7 deletions
diff --git a/testes/api.lua b/testes/api.lua
index ed857fd0..6f35e132 100644
--- a/testes/api.lua
+++ b/testes/api.lua
@@ -366,7 +366,7 @@ do
-- "argerror" without frames
assert(T.checkpanic("loadstring 4") ==
"bad argument #4 (string expected, got no value)")
-
+
-- memory error
T.totalmem(T.totalmem()+10000) -- set low memory limit (+10k)
@@ -987,12 +987,12 @@ do
local a, b = T.testC([[
call 0 1 # create resource
- pushint 34
+ pushnil
toclose -2 # mark call result to be closed
- toclose -1 # mark number to be closed (will be ignored)
+ toclose -1 # mark nil to be closed (will be ignored)
return 2
]], newresource)
- assert(a[1] == 11 and b == 34)
+ assert(a[1] == 11 and b == nil)
assert(#openresource == 0) -- was closed
-- repeat the test, but calling function in a 'multret' context
@@ -1005,7 +1005,7 @@ do
assert(#openresource == 0) -- was closed
-- error
- local a, b = pcall(T.testC, [[
+ local a, b = pcall(T.makeCfunc[[
call 0 1 # create resource
toclose -1 # mark it to be closed
error # resource is the error object
@@ -1038,6 +1038,13 @@ do
]], newresource, check)
assert(a == 3) -- no extra items left in the stack
+ -- non-closable value
+ local a, b = pcall(T.makeCfunc[[
+ pushint 32
+ toclose -1
+ ]])
+ assert(not a and string.find(b, "(C temporary)"))
+
end
@@ -1249,9 +1256,9 @@ do -- closing state with no extra memory
T.closestate(L)
T.alloccount()
end
-
+
do -- garbage collection with no extra memory
- local L = T.newstate()
+ local L = T.newstate()
T.loadlib(L)
local res = (T.doremote(L, [[
_ENV = require"_G"