From 96c13e095f6dcb536eb54dd8cfcd75a5ee02dbf8 Mon Sep 17 00:00:00 2001 From: Christian Whitehead <34224458+taxmancw@users.noreply.github.com> Date: Sat, 17 May 2025 03:05:57 +1000 Subject: [PATCH] Changed FFI API to handle user case where BF_CRT_DISABLE is defined --- BeefLibs/corlib/src/FFI/Function.bf | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/BeefLibs/corlib/src/FFI/Function.bf b/BeefLibs/corlib/src/FFI/Function.bf index 0846ad7a..3a30a87c 100644 --- a/BeefLibs/corlib/src/FFI/Function.bf +++ b/BeefLibs/corlib/src/FFI/Function.bf @@ -131,7 +131,8 @@ namespace System.FFI { OK, BadTypeDef, - BadABI + BadABI, + NoBeefCRT, } #if BF_PLATFORM_WINDOWS @@ -199,9 +200,11 @@ namespace System.FFI uint32 mFlags; } +#if !BF_CRT_DISABLE public static extern void* ClosureAlloc(int size, void** outFunc); public static extern FFIResult PrepCif(FFICIF* cif, FFIABI abi, int32 nargs, FFIType* rtype, FFIType** argTypes); public static extern void Call(FFICIF* cif, void* funcPtr, void* rvalue, void** args); +#endif } struct FFICaller @@ -210,15 +213,23 @@ namespace System.FFI public Result Prep(FFIABI abi, int32 nargs, FFIType* rtype, FFIType** argTypes) mut { +#if !BF_CRT_DISABLE let res = FFILIB.PrepCif(&mCIF, abi, nargs, rtype, argTypes); if (res == .OK) return .Ok; return .Err(res); +#else + return .Err(.NoBeefCRT); +#endif } public void Call(void* funcPtr, void* rvalue, void** args) mut { +#if !BF_CRT_DISABLE FFILIB.Call(&mCIF, funcPtr, rvalue, args); +#else + Internal.FatalError("FFI requires Beef runtime."); +#endif } } }