mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-31 15:43:01 +00:00 
			
		
		
		
	Make sure void return types work as expected.
This commit is contained in:
		| @@ -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); | ||||
| } | ||||
|   | ||||
| @@ -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)) | ||||
|   | ||||
| @@ -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: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Calvin Rose
					Calvin Rose