[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: coroutine library can cause panic with low memory
- From: Patrick Donnelly <batrick@...>
- Date: Mon, 2 Mar 2009 13:01:51 -0700
On Mon, Mar 2, 2009 at 12:07 PM, M Joonas Pihlaja
> On Mon, 2 Mar 2009, Patrick Donnelly wrote:
>> Using the attached script one can cause Lua to panic. The problem is
>> the API call lua_checkstack which may throw a memory error.
>> lua_checkstack should probably not throw memory errors because it
>> cannot knowingly throw the error on the currently running thread. The
>> thread you are checking stack space for may not actually be running!
> Uhm.. sorry if I'm being dense, but isn't growing stack and possibly
> throwing a memory error the very reason for calling lua_checkstack in
> the first place? What on earth is it supposed to do if it can't throw
> memory errors when it can't grow the stack?
Because, in preparation for lua_xmove, you will want to ensure stack
space on the coroutine you are moving values to. However, there is no
method of checking the stack space on that coroutine without
_possibly_ causing a panic due to an out of memory error.
On Mon, Mar 2, 2009 at 12:19 PM, Roberto Ierusalimschy
>> Uhm.. sorry if I'm being dense, but isn't growing stack and possibly
>> throwing a memory error the very reason for calling lua_checkstack in
>> the first place? What on earth is it supposed to do if it can't throw
>> memory errors when it can't grow the stack?
> Probably a better correction would be to throw memory errors on the
> main thread, if the current thread does not have one.
I don't feel this is the right way to go either. It bypasses, to the
bewilderment of the programmer, all the error protection measures, a
potentially large chain of pcalls and resumes, and may still cause a
panic if the main thread has no error handler.
"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."