[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: luaL_Buffer initial storage alignment.
- From: Duane Leslie <parakleta@...>
- Date: Wed, 12 Apr 2017 11:42:03 +1000
Hi,
The storage alignment of strings and userdata are both enforced
through a union with the `L_Umaxalign` structure. For luaL_Buffer, an
allocated buffer must be aligned by the `allocf` (as are strings and
userdata), but there is the case where luaL_Buffer is a static
variable or on the stack, and in this case there is no enforcement.
With the current definition it must be at least 4 byte aligned on 32
bit systems (8 byte on 64 bit) because it follows a pointer.
Given that we can store binary data in strings in Lua, and this can
safely be extracted from a string due to its alignment requirement,
can we please have the same alignment guarantee on the luaL_Buffer
`initb` field so that we can build binary structures for storage in
strings through this API.
For my use I just converted the `char initb[LUAL_BUFFERSIZE];` field
to `union { L_Umaxalign dummy; char b[LUAL_BUFFERSIZE]; } init;` but I
had to shuffle some header file definitions to make everything visible
as required. I then just changed any occurrence of `initb` with
`init.b`. Not sure if this is the best solution.
Regards,
Duane.