Re: ffi initializer bit me today

  • From: Kaj Eijlers <bizziboi@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Sat, 8 Sep 2012 22:46:20 -0700

>>I think in your first case, I'd rather FFI didn't do any real magic,
particularly where it will result in overwriting a buffer, whose size it
already knows.

But the way I see it, it isn't doing any magic, except from type
coercion,which is more a lua feature than a ffi feature. You are telling it
to initialize with one argument, which isn't a char, so it must be a string
(instead of separate characters). If it's a string it needs to be zero
terminated, that's again not magic, that's C.

I would be most curious about

local cdata = ffi.new('unsigned char[?]', 1, 'a')

...as that one is truly ambiguous imo regarding whether it's a single char,
or a string of length 1 (and thus would copy 2 bytes)

Kaj

.

Other related posts: