<!DOCTYPE html>
<html data-lt-installed="true">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body style="padding-bottom: 1px;">
<p>Hi, Sergey</p>
<p>thanks for the patch! LGTM with a nit below.<br>
</p>
<div class="moz-cite-prefix">On 03.06.2024 17:34, Sergey Kaplun
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:034b0afe429e672809ec8192ff1fb41a7bfd2937.1717424008.git.skaplun@tarantool.org">
<pre class="moz-quote-pre" wrap="">From: Mike Pall <mike>
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</pre>
</blockquote>
extra whitespace above<br>
<blockquote type="cite"
cite="mid:034b0afe429e672809ec8192ff1fb41a7bfd2937.1717424008.git.skaplun@tarantool.org">
<pre class="moz-quote-pre" wrap="">
`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)
</pre>
</blockquote>
</body>
<lt-container></lt-container>
</html>