lua-users home
lua-l archive

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


In addition to my previous posts, I think I can now pinpoint what is causing the crashes (segmentation fault) that may occur when libraries are loaded from C-modules.

A crash occurs under these circumstances:
- a program is in the final phase of its execution where its state is closed
- a library module (=userdata) is unloaded in the cleanup (__gc=gctm)
- a userdata calls its __gc method where it needs a function in the library just unloaded
- segmentation fault results

In terms of function calls within Lua:
- lua_close() [lstate.c] called
--- luaC-separateudata() [lgc.c] collects userdata with __gc functions
--- close_state() [lstate.c] called
------ luaC_freeall() [lgc.c] called

It would not have been a problem if luaC-separateudata() had split the udata in two sets: first removing the non-libraries and thereafter the libraries.

QUESTION: can this be changed in the Lua code in the next bugfix update?

The only rapid kludge I see now is killing ll_unloadlib()'s action:
  static void ll_unloadlib (void *lib) { /* dlclose(lib); */ }
And indeed, then the crash disappears!

But perhaps there is a better (interim) solution?

Hans van der Meer