Hi, I am hitting a possible corner-case bug. It is related to indexing a hidden cdata struct through a custom __index() function, when JIT is on, and in an upvalue situation. I am considering the particular case of having a C struct where contents are hidden in ffi.cdef(). Note that in that particular case, LuaJIT seems to call the user __index function if it exists, even for numbers (which sounds logical, given it does not know the size of the struct!). The bug occurs only if (1) the JIT is on (2) if one plays with the cdata as an upvalue in a function. It occurs with LuaJIT 2.0 git-head or 2.1 git-head. One can circumvent the “bug” if one uses a reference on the cdata (which one would have to do anyways if the struct contents were available in ffi.cdef()). See the files in attachment for a simple example. Best, Ronan.
Attachment:
debug.lua
Description: Binary data
Attachment:
foobar.c
Description: Binary data