summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2022-07-13 00:32:04 +0200
committerMike Pall <mike>2022-07-13 00:32:04 +0200
commit36b2962d400db3981a7d7322f85c469240eb6f3b (patch)
tree705ef5d0959e112f895b2df78e579c0a6ddf9314
parent27a6fee82e91319bbed8c3aa443aa2b0f1b0a470 (diff)
downloadluajit2-36b2962d400db3981a7d7322f85c469240eb6f3b.tar.gz
FFI: Fix ffi.alignof() for reference types.
Reported by Eric Gouyer.
-rw-r--r--src/lib_ffi.c2
-rw-r--r--src/lj_ctype.c8
-rw-r--r--src/lj_ctype.h1
3 files changed, 10 insertions, 1 deletions
diff --git a/src/lib_ffi.c b/src/lib_ffi.c
index 6eaec71c..654e71a2 100644
--- a/src/lib_ffi.c
+++ b/src/lib_ffi.c
@@ -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;
}
diff --git a/src/lj_ctype.c b/src/lj_ctype.c
index 68edb287..7ef00521 100644
--- a/src/lj_ctype.c
+++ b/src/lj_ctype.c
@@ -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)
{
diff --git a/src/lj_ctype.h b/src/lj_ctype.h
index 77551e76..4979a7ac 100644
--- a/src/lj_ctype.h
+++ b/src/lj_ctype.h
@@ -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);