Hi, Sergey thanks for the patch! LGTM with a nit below. On 03.06.2024 17:34, Sergey Kaplun wrote: > From: Mike Pall > > Reported by Eric Gouyer. > > (cherry picked from commit 27a6fee82e91319bbed8c3aa443aa2b0f1b0a470) > > Before the patch, `ffi.metatype()` raises an error when calling it on > ctype with attributes. This patch fixes the behaviour by using extra whitespace above > `ctype_raw()` instead of `ctype_get()` to follow child ctypes unless > there are no attributes on the ctype. > > Sergey Kaplun: > * added the description and the test for the problem > > Part of tarantool/tarantool#9924 > --- > src/lib_ffi.c | 2 +- > test/tarantool-tests/lj-861-ctype-attributes.test.lua | 10 +++++++--- > 2 files changed, 8 insertions(+), 4 deletions(-) > > diff --git a/src/lib_ffi.c b/src/lib_ffi.c > index 2bfca25a..dfb01658 100644 > --- a/src/lib_ffi.c > +++ b/src/lib_ffi.c > @@ -770,7 +770,7 @@ LJLIB_CF(ffi_metatype) > CTypeID id = ffi_checkctype(L, cts, NULL); > GCtab *mt = lj_lib_checktab(L, 2); > GCtab *t = cts->miscmap; > - CType *ct = ctype_get(cts, id); /* Only allow raw types. */ > + CType *ct = ctype_raw(cts, id); > TValue *tv; > GCcdata *cd; > if (!(ctype_isstruct(ct->info) || ctype_iscomplex(ct->info) || > diff --git a/test/tarantool-tests/lj-861-ctype-attributes.test.lua b/test/tarantool-tests/lj-861-ctype-attributes.test.lua > index e8b29d67..a407fae0 100644 > --- a/test/tarantool-tests/lj-861-ctype-attributes.test.lua > +++ b/test/tarantool-tests/lj-861-ctype-attributes.test.lua > @@ -7,14 +7,14 @@ local tap = require('tap') > local test = tap.test('lj-861-ctype-attributes') > local ffi = require('ffi') > > -test:plan(4) > +test:plan(5) > > local EXPECTED_ALIGN = 4 > > ffi.cdef([[ > -struct __attribute__((aligned($))) s_aligned { > +typedef struct __attribute__((aligned($))) s_aligned { > uint8_t a; > -}; > +} s_aligned; > > struct test_parsing_sizeof { > char a[sizeof(struct s_aligned &)]; > @@ -37,4 +37,8 @@ test:is(ffi.sizeof('struct test_parsing_sizeof'), EXPECTED_ALIGN, > test:is(ffi.sizeof('struct test_parsing_alignof'), EXPECTED_ALIGN, > 'correct alignof during C parsing') > > +local ok, _ = pcall(ffi.metatype, 's_aligned', {}) > + > +test:ok(ok, 'ffi.metatype is called at the structure with attributes') > + > test:done(true)