lua-users home
lua-l archive

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

 On 09/10/10 23:22, Martin Voigt wrote:
Hi *,

background: I'm currently writing Lua bindings for a rather big
project, the project itself is written in plain C. But every part and
library of it uses Hans Boehm's gc
( It saves some hassle
as you trade chasing memory leaks for chasing non-visible references,
which brings me to my question:

Is it save to use Lua (a version based on lua-5.2.0-work4) with the
boehm gc? While it should work (and it does so far) to set lua_Alloc
to our own allocator, does Lua somewhere make assumptions about the
behaviour of it's own gc implementation?

Thanks in advance,
In order to fool Boehm's GC, you'd have to store pointers at unaligned memory addresses (undefined behaviour), increment or decrement all the pointers to a block so that they point outside an allocated block (undefined behaviour, except for one-past-the-end) or convert a pointer to an integer (undefined behaviour) and change the integer's value (such as with the XOR linked list:

These all involve invoking undefined behaviour, so if Lua is written in well-defined ANSI C, there will be no problem as far as I can tell. If Lua does make use of undefined behaviour, then arguably it ought to be fixed.