From 8a35a82cfb726f570223e4d70d94640dd771ec9a Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Sun, 27 Dec 2020 16:57:54 +0000 Subject: [PATCH] fixed bugs in ffi.c --- moo/mod/ffi.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/moo/mod/ffi.c b/moo/mod/ffi.c index cd5fb6c..39c61a2 100644 --- a/moo/mod/ffi.c +++ b/moo/mod/ffi.c @@ -784,9 +784,22 @@ static moo_pfrc_t pf_call (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) } while (i < MOO_OBJ_GET_SIZE(sig) && MOO_OBJ_GET_CHAR_VAL(sig, i) == ' ') i++; /* skip all spaces after > */ - fmtc = (i >= MOO_OBJ_GET_SIZE(sig)? FMTC_NULL: MOO_OBJ_GET_CHAR_VAL(sig, i)); + if (fmtc == 'u') + { + _unsigned = 1; + i++; + fmtc = (i >= MOO_OBJ_GET_SIZE(sig)? FMTC_NULL: MOO_OBJ_GET_CHAR_VAL(sig, i)); + } + else + { + _unsigned = 0; + } + + #if defined(USE_LIBFFI) + if (!ffi->fmtc_to_type[0][fmtc]) goto inval; /* invalid return value signature */ + fs = (nfixedargs == j)? ffi_prep_cif(&ffi->cif, FFI_DEFAULT_ABI, j, ffi->fmtc_to_type[0][fmtc], ffi->arg_types): ffi_prep_cif_var(&ffi->cif, FFI_DEFAULT_ABI, nfixedargs, j, ffi->fmtc_to_type[0][fmtc], ffi->arg_types); if (fs != FFI_OK) @@ -798,15 +811,6 @@ static moo_pfrc_t pf_call (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs) ffi_call (&ffi->cif, FFI_FN(f), &ffi->ret_sv, ffi->arg_values); #endif - if (fmtc == 'u') - { - _unsigned = 1; - fmtc++; - } - else - { - _unsigned = 0; - } /* check the return value type in signature */ switch (fmtc)