aboutsummaryrefslogtreecommitdiff
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)
downloadluajit-36b2962d400db3981a7d7322f85c469240eb6f3b.tar.gz
luajit-36b2962d400db3981a7d7322f85c469240eb6f3b.tar.bz2
luajit-36b2962d400db3981a7d7322f85c469240eb6f3b.zip
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)
615 CTState *cts = ctype_cts(L); 615 CTState *cts = ctype_cts(L);
616 CTypeID id = ffi_checkctype(L, cts, NULL); 616 CTypeID id = ffi_checkctype(L, cts, NULL);
617 CTSize sz = 0; 617 CTSize sz = 0;
618 CTInfo info = lj_ctype_info(cts, id, &sz); 618 CTInfo info = lj_ctype_info_raw(cts, id, &sz);
619 setintV(L->top-1, 1 << ctype_align(info)); 619 setintV(L->top-1, 1 << ctype_align(info));
620 return 1; 620 return 1;
621} 621}
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)
328 return qual; 328 return qual;
329} 329}
330 330
331/* Ditto, but follow a reference. */
332CTInfo lj_ctype_info_raw(CTState *cts, CTypeID id, CTSize *szp)
333{
334 CType *ct = ctype_get(cts, id);
335 if (ctype_isref(ct->info)) id = ctype_cid(ct->info);
336 return lj_ctype_info(cts, id, szp);
337}
338
331/* Get ctype metamethod. */ 339/* Get ctype metamethod. */
332cTValue *lj_ctype_meta(CTState *cts, CTypeID id, MMS mm) 340cTValue *lj_ctype_meta(CTState *cts, CTypeID id, MMS mm)
333{ 341{
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);
449LJ_FUNC CTSize lj_ctype_size(CTState *cts, CTypeID id); 449LJ_FUNC CTSize lj_ctype_size(CTState *cts, CTypeID id);
450LJ_FUNC CTSize lj_ctype_vlsize(CTState *cts, CType *ct, CTSize nelem); 450LJ_FUNC CTSize lj_ctype_vlsize(CTState *cts, CType *ct, CTSize nelem);
451LJ_FUNC CTInfo lj_ctype_info(CTState *cts, CTypeID id, CTSize *szp); 451LJ_FUNC CTInfo lj_ctype_info(CTState *cts, CTypeID id, CTSize *szp);
452LJ_FUNC CTInfo lj_ctype_info_raw(CTState *cts, CTypeID id, CTSize *szp);
452LJ_FUNC cTValue *lj_ctype_meta(CTState *cts, CTypeID id, MMS mm); 453LJ_FUNC cTValue *lj_ctype_meta(CTState *cts, CTypeID id, MMS mm);
453LJ_FUNC GCstr *lj_ctype_repr(lua_State *L, CTypeID id, GCstr *name); 454LJ_FUNC GCstr *lj_ctype_repr(lua_State *L, CTypeID id, GCstr *name);
454LJ_FUNC GCstr *lj_ctype_repr_int64(lua_State *L, uint64_t n, int isunsigned); 455LJ_FUNC GCstr *lj_ctype_repr_int64(lua_State *L, uint64_t n, int isunsigned);