[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Missing error message in panic handler / calling luaD_throw without error message on stack
- From: Tim Hill <drtimhill@...>
- Date: Sun, 9 Nov 2014 09:49:17 -0800
> If lua_newuserdata() fails to allocate memory and no pcall/xpcall is
> active, then the panic handler will be called without pushing an error
> message on top of the stack (i.e. the value that has been on top of the
> stack prior to the lua_newuserdata() call will be where the error
> message ought to be).
>
> Is this behavior intended?
>
> Looking into the source code of Lua 5.2.3, I found that in line #93 of
> lmem.c, the function luaD_throw(L, LUA_ERRMEM) is called without
> pushing first an error message on top of the stack. Other calls of
> luaD_throw, however, push an error message to the stack, e.g. function
> lexerror() in llex.c, line #110 or function checkmode() in ldo.c,
> line #635.
>
> Is this a bug?
>
I can make a guess .. pushing an error message is going to require that you allocate heap space for that message. But you are processing an out of memory condition, and so the heap allocate may (will?) fail .. and then what do you do?
We also use a custom allocator (for other reasons), but we reserve a block of heap storage at startup. If an allocation fails, we release that reserved memory to the heap and retry the allocation. (We also begin a system shutdown since if memory is exhausted the best we can hope for is to perform a clean exit.)
—Tim