diff --git a/BeefLibs/corlib/src/Internal.bf b/BeefLibs/corlib/src/Internal.bf index 99294b40..0ab17ef4 100644 --- a/BeefLibs/corlib/src/Internal.bf +++ b/BeefLibs/corlib/src/Internal.bf @@ -21,9 +21,14 @@ namespace System } } + [CRepr] struct VarArgs { +#if BF_PLATFORM_WINDOWS void* mVAList; +#else + int[3] mVAList; // Conservative size for va_list +#endif [Intrinsic("va_start")] static extern void Start(void* vaList); @@ -51,6 +56,15 @@ namespace System Arg(&mVAList, &val, (.)typeof(T).TypeId); val } + + public void* ToVAList() mut + { +#if BF_PLATFORM_WINDOWS + return mVAList; +#else + return &mVAList; +#endif + } } [AlwaysInclude] diff --git a/IDEHelper/Tests/src/VarArgs.bf b/IDEHelper/Tests/src/VarArgs.bf index 4506390c..01df1cf9 100644 --- a/IDEHelper/Tests/src/VarArgs.bf +++ b/IDEHelper/Tests/src/VarArgs.bf @@ -19,7 +19,7 @@ namespace Tests #else [CLink] #endif - public static extern int32 vsprintf(char8* dest, char8* fmt, VarArgs varArgs); + public static extern int32 vsprintf(char8* dest, char8* fmt, void* varArgs); public static (int, int, int) MethodA(...) { @@ -64,7 +64,7 @@ namespace Tests { VarArgs vaArgs = .(); vaArgs.Start!(); - int32 result = vsprintf(dest, fmt, vaArgs); + int32 result = vsprintf(dest, fmt, vaArgs.ToVAList()); vaArgs.End!(); return result; } @@ -82,7 +82,11 @@ namespace Tests Test.Assert(str == "Test 223 2.2 3.3"); // LLVM 32-bit varargs bug? -#if !BF_32_BIT +#if BF_32_BIT && BF_PLATFORM_WINDOWS + Test.Assert(MethodA( 12, 23, 123.0f) case (12, 23, ?)); + Test.Assert(MethodB( 9, 22, 33, 223.0f) case (22, 33, ?)); + Test.Assert(MethodC(11, 32, 43, 323.0f) case (32, 43, ?)); +#else Test.Assert(MethodA( 12, 23, 123.0f) == (12, 23, 123)); Test.Assert(MethodB( 9, 22, 33, 223.0f) == (22, 33, 223)); Test.Assert(MethodC(11, 32, 43, 323.0f) == (32, 43, 323));