lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hey all,

I'm currently exploring the next assertion and found some unrelated
unexpected behavior that I can't quite track down yet.

For both of these:  Is this expected / intentional or not?

-- begin testcase #1 --
local function trace( str )  return io.stderr:write( str )  end
local body = function( )
  trace 'B'
  while true do  trace '.' ; t = { }  end
  trace 'X1'
local handler = function( )  trace "H"  end
-- set up delayed error
t = setmetatable( {}, {
  __gc = function()  trace "E" error "blergh!" trace "X2"  end
} )
-- run
trace "A"
xpcall( body, handler )
trace "Z"
-- end testcase #1 --

There's three possible results that I'd expect

E1: AB....(forever)
E2: AB....(exit)
E3: AB....(etc.)....EHZ

But what I actually get is:

A1: AB....(etc.)....EZ

i.e. the error handler doesn't run.

Another weird thing happens when changing

-- begin diff to testcase #2 --
<   while true do  trace '.' ; t = { }  end
>   while true do  trace '.' ; local t = { }  end
-- end diff to testcase #2 --

(or alternatively saying `local t` in 'body' before entering the loop.)

Now I get (with and without HARDMEMTESTS, even when adding an additional
explicit `collectgarbage "collect"` in the loop)


i.e. the GC doesn't run while Lua merrily allocates gigabytes of memory.

If I interrupt (^C), it's


(same (minus the ^C) when limiting available memory, e.g. by using the
test lib's T.totalmem) - i.e. the GC runs only after leaving the loop.

-- Marco