lua-users home
lua-l archive

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


Roberto wrote:
> >     union L_Umaxalign { double d; void *s; long l; };
> >
> > should probably be:
> >
> >     union L_Umaxalign { lua_Number d; void *s; long l; };
>
> This double is to ensure proper alignment for userdata and strings
> *outside* Lua. (Notice that strings will always be aligned, too.)

I don't quite understand the distinction of "outside Lua".  Isn't userdata
always allocated from C?  Can't C make references to strings inside Lua?

Anyway, I think that union is not generally sufficient.  On my machine the
largest data type requiring alignment is 16 bytes (a vector).  (By no
coincidence this is also the alignment of the stack and heap.)  Maybe you
could make it a build option, something like:

    #ifdef LUA_ALIGNMENT
        union L_Umaxalign { char[LUA_ALIGNMENT]; };
    #else
        union L_Umaxalign { double d; void *s; long l; };
    #endif

-John