diff --git a/ffitest/so.c b/ffitest/so.c index c1ddda76..2d1cc818 100644 --- a/ffitest/so.c +++ b/ffitest/so.c @@ -77,3 +77,11 @@ big struct_big(int i, double d) { ret.c = ret.a + ret.b + 1000; return ret; } + +void void_fn(void) { + printf("void fn ran\n"); +} + +void void_ret_fn(int x) { + printf("void fn ran: %d\n", x); +} diff --git a/ffitest/test.janet b/ffitest/test.janet index e454fff7..bbfd6c09 100644 --- a/ffitest/test.janet +++ b/ffitest/test.janet @@ -62,10 +62,17 @@ [i d] (native-call struct-big-fn-pointer struct-big-fn-sig i d)) +(def void-fn-pointer (native-lookup module "void_fn")) +(def void-fn-sig (native-signature :default :void)) +(defn void-fn + [] + (native-call void-fn-pointer void-fn-sig)) + # # Call functions # +(pp (void-fn)) (pp (int-fn 10 20)) (pp (double-fn 1.5 2.5 3.5)) (pp (double-many 1 2 3 4 5 6)) diff --git a/src/core/ffi.c b/src/core/ffi.c index 36f03fa8..5a1b35cf 100644 --- a/src/core/ffi.c +++ b/src/core/ffi.c @@ -473,6 +473,7 @@ static JanetFFIWordSpec sysv64_classify(JanetFFIType type) { return clazz; } case JANET_FFI_TYPE_VOID: + return JANET_SYSV64_NO_CLASS; default: janet_panic("nyi"); return JANET_SYSV64_NO_CLASS; @@ -519,6 +520,9 @@ JANET_CORE_FN(cfun_ffi_signature, mappings[i].type = decode_ffi_type(argv[i + 2]); mappings[i].offset = 0; mappings[i].spec = sysv64_classify(mappings[i].type); + if (mappings[i].spec == JANET_SYSV64_NO_CLASS) { + janet_panic("unexpected void parameter"); + } size_t el_size = (type_size(mappings[i].type) + 7) / 8; switch (mappings[i].spec) { default: