lua-users home
lua-l archive

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


On Monday 09, Roberto Ierusalimschy wrote:
> > The following extension and Lua program crash both Lua 5.1 and Lua
> > 5.2.  From an strace it appears that the extension library is called
> > into after it was unloaded.  Perhaps this is a GC-related bug where
> > the loaded library is collected prematurely?
> 
> Unfortunatelly, this seems to be a "conceptual" bug. The loaded library
> is being collected exactly where the specification says it should be
> collected, but the resulting behavior allows client code to crash the
> interpreter, which is unacceptable.
> 
> I see three solutions:
> 
> 1) To disallow the unloading of dynamic libraries. (Very quick and dirty.)

This would not be good for embedded uses of Lua which open/close Lua states 
many times while the host program is running.

> 2) To handle dynamic libraries as a special case when running
> finalizers. (May be good for a patch.)

One simple way to do this would be to keep a list of module handles in a table 
stored in the registry.  The current __gc meta-method on the module's handle 
would need to be removed.  When the Lua state is being closed first process 
all finalizers, then go through the list of module handles unloading each one 
(in reverse order maybe?).

This will not support dynamic unloading of modules, only unloading when 
closing a Lua State.

When I have some time I will create a patch for this, but right now I have a 
backlog of things to do.

> 3) To change the specification in some way (e.g., introducing priorities
> for finalizers).

How would a finalizer's priority be set?

-- 
Robert G. Jakabosky