lua-users home
lua-l archive

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


Roberto Ierusalimschy wrote:
> * LUA_ERRGCMM is not related to emergency collections. (Actually
> it cannot be called in an emergency collection, because emergency
> collections do not run finalizers.) It is just an indication that
> the error occured in a finalizer, not in the "regular" code that was
> running. (Finalizers should never throw errors, so this status code may
> mean that something bad is happening.)

The question is whether propagating the error to unrelated code
which invoked the GC as a side-effect is helpful at all. Simply
suppressing the error is not good, because one would never notice
a bug in a finalizer then. But unsuspecting user code may suppress
the error, too, or do other bad things. This is hard to diagnose
in general, because the GC can happen at unpredictable times.

With the new LuaJIT GC I'm tending towards running finalizers only
from a separate coroutine (a bit like Java, which runs them in a
separate thread). This simplifies quite a few things and isolates
the effects of finalizers (e.g. they cannot peek into or mess up
the current stack). Alas, there's no easy way to propagate the
error to user code, so it relies on a user-supplied handler which
currently prints a full backtrace to stderr (but continues
execution). IMHO this is a cleaner way to handle this problem.

--Mike