Re: possible corner-case bug

  • From: Mike Pall <mike-1411@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 3 Nov 2014 21:44:55 +0100

Ronan Collobert wrote:
> 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.

Actually, you're not indexing an incomplete struct. You can't
create an instance of an incomplete struct, so this won't happen.

You're indexing a pointer to a struct. Which is a pre-defined
operation, so this is always tried first before deferring to a
ctype metamethod.

> 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 inconsistency was that it mistakenly deferred to the
metamethod in the interpreter, but not in the JIT compiler. I've
fixed the code in the git repository to follow the documentation.
Now it always raises an error when indexing an incomplete struct.

Thank you for the bug report and the test case!

--Mike

Other related posts: