possible corner-case bug

  • From: Ronan Collobert <ronan@xxxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Fri, 31 Oct 2014 17:59:45 -0700

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

Other related posts: