FFI: Fix ffi.alignof() for reference types.

Reported by Eric Gouyer.
master
Mike Pall 2022-07-13 00:32:04 +02:00
parent 27a6fee82e
commit 36b2962d40
3 changed files with 10 additions and 1 deletions

View 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;
}

View 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)
{

View 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);