lua-users home
lua-l archive

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

In my previous mail to the list I posed questions about having a segmentation fault on using dynamically loaded modules:

My question: can anyone more versed in the internals of Lua tell me if
this could indeed be the case?
Is there a solution or must I absolutely refrain from calling other
modules during the gc cleanup phase?

Some further research revealed more cases where faults arise. As far as I can see my tests indeed seem to point at premature removal of my userdata items (from my point of view, of course) by the garbage collector.

The cause could be that the userdata were made in C-code with lua_newuserdata. I have a doubly linked list of these that got garbage- collected while an operation on the list was still running. Although the holder of the chain resides in lua-code, the chain is held entirely by C-pointers therein: no special significance for Lua, I am afraid. It might well be possible that the memory system doesn't know enough about my data structures to be able to keep them as long as needed.

Therefore I think I can narrow the problem to the following question: if I allocate userdata with lua_newuserdata and keep them through C- pointers only, how do I let the Lua-system know when to collect and when not?

Thanks in advance
Hans van der Meer