Closed lePereT closed 1 year ago
i'm not sure how you got it to work to that point, as broken handling of variable-length structs (https://github.com/q66/cffi-lua/commit/c9fa529ac5c33ff18b1d5fb63df323f5e956e0d1) would prevent it from even allocating properly (it would initialize read_idx to 16 and leave the buffer empty, leading to assertion errors)
that said, after that fix, i was able to reproduce your condition and pushed some fixes, can you test that on your side?
Could it be the Arm64 architecture that I'm using? Will test asap :)
there is also an issue i just discovered; cdata on most platforms must be 16-aligned, but lua_newuserdata returns pointers that are 8-aligned; in practice this will usually not manifest (hence no failing tests in CI even on platforms with strict alignment requirements) but UBsan (rightly) complains about that (so i need to figure out some way to fix it, and probably add UBsan to CI)
the obvious way is to overallocate by 16 bytes and then align the pointer (while making sure to adjust any potential calls to userdata rawlen, because that needs the original pointer and may return wrong size), but that's both a waste and bug-prone, so i'll need to think about this
and no, i don't think so
Hey q66 can confirm that your fixes enable the tests to work, as well as other code that relies on the library. Thank you! Unless you wanna keep this issue open for the lua_newuserdata
alignment issue, happy to close.
(I've two other short questions but I'll make separate issues to help discoverability).
On Wed, 4 Jan 2023, 17:33 q66, @.***> wrote:
and no, i don't think so
— Reply to this email directly, view it on GitHub https://github.com/q66/cffi-lua/issues/36#issuecomment-1371221859, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABFUW5ENNQEKCEBWGOMQIMTWQWX53ANCNFSM6AAAAAATQNRASU . You are receiving this because you authored the thread.Message ID: @.***>
landed the big memory management rework, so i will close this
Hi! Thanks for this lib. Here's some code that I'm porting that implements a ring buffer. It errors on
cffi
but not luajit/other pure lua ffi implementations:With luajit's
ffi
or https://github.com/jmckaskill/luaffi I get the following:But with
cffi
theselftest()
causes the interpreter to abort