]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
FFI: Fix ffi.alignof() for reference types.
authorMike Pall <mike>
Tue, 12 Jul 2022 22:32:04 +0000 (00:32 +0200)
committerMike Pall <mike>
Tue, 12 Jul 2022 22:32:04 +0000 (00:32 +0200)
Reported by Eric Gouyer.

src/lib_ffi.c
src/lj_ctype.c
src/lj_ctype.h

index 6eaec71c18408a65167d88f84c674c5964cddd0b..654e71a289370c753604262e3b40502d939ca8bd 100644 (file)
@@ -615,7 +615,7 @@ LJLIB_CF(ffi_alignof)       LJLIB_REC(ffi_xof FF_ffi_alignof)
   CTState *cts = ctype_cts(L);
   CTypeID id = ffi_checkctype(L, cts, NULL);
   CTSize sz = 0;
-  CTInfo info = lj_ctype_info(cts, id, &sz);
+  CTInfo info = lj_ctype_info_raw(cts, id, &sz);
   setintV(L->top-1, 1 << ctype_align(info));
   return 1;
 }
index 68edb2873db5f3b8cf419c45d405422bee8e574c..7ef00521cb3cb440986fedd59858ecc5bb89f2a7 100644 (file)
@@ -328,6 +328,14 @@ CTInfo lj_ctype_info(CTState *cts, CTypeID id, CTSize *szp)
   return qual;
 }
 
+/* Ditto, but follow a reference. */
+CTInfo lj_ctype_info_raw(CTState *cts, CTypeID id, CTSize *szp)
+{
+  CType *ct = ctype_get(cts, id);
+  if (ctype_isref(ct->info)) id = ctype_cid(ct->info);
+  return lj_ctype_info(cts, id, szp);
+}
+
 /* Get ctype metamethod. */
 cTValue *lj_ctype_meta(CTState *cts, CTypeID id, MMS mm)
 {
index 77551e763fbb54a42df2353e38a320b8e3ebda7a..4979a7aca7cb3ba7592dcc23a0cef7c81cbe4600 100644 (file)
@@ -449,6 +449,7 @@ LJ_FUNC CType *lj_ctype_rawref(CTState *cts, CTypeID id);
 LJ_FUNC CTSize lj_ctype_size(CTState *cts, CTypeID id);
 LJ_FUNC CTSize lj_ctype_vlsize(CTState *cts, CType *ct, CTSize nelem);
 LJ_FUNC CTInfo lj_ctype_info(CTState *cts, CTypeID id, CTSize *szp);
+LJ_FUNC CTInfo lj_ctype_info_raw(CTState *cts, CTypeID id, CTSize *szp);
 LJ_FUNC cTValue *lj_ctype_meta(CTState *cts, CTypeID id, MMS mm);
 LJ_FUNC GCstr *lj_ctype_repr(lua_State *L, CTypeID id, GCstr *name);
 LJ_FUNC GCstr *lj_ctype_repr_int64(lua_State *L, uint64_t n, int isunsigned);