1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 20:42:21 +02:00

varargs fixes

This commit is contained in:
Brian Fiete 2021-01-22 13:20:17 -08:00
parent 0ebd306d93
commit 1f42567339
2 changed files with 21 additions and 3 deletions

View file

@ -21,9 +21,14 @@ namespace System
} }
} }
[CRepr]
struct VarArgs struct VarArgs
{ {
#if BF_PLATFORM_WINDOWS
void* mVAList; void* mVAList;
#else
int[3] mVAList; // Conservative size for va_list
#endif
[Intrinsic("va_start")] [Intrinsic("va_start")]
static extern void Start(void* vaList); static extern void Start(void* vaList);
@ -51,6 +56,15 @@ namespace System
Arg(&mVAList, &val, (.)typeof(T).TypeId); Arg(&mVAList, &val, (.)typeof(T).TypeId);
val val
} }
public void* ToVAList() mut
{
#if BF_PLATFORM_WINDOWS
return mVAList;
#else
return &mVAList;
#endif
}
} }
[AlwaysInclude] [AlwaysInclude]

View file

@ -19,7 +19,7 @@ namespace Tests
#else #else
[CLink] [CLink]
#endif #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(...) public static (int, int, int) MethodA(...)
{ {
@ -64,7 +64,7 @@ namespace Tests
{ {
VarArgs vaArgs = .(); VarArgs vaArgs = .();
vaArgs.Start!(); vaArgs.Start!();
int32 result = vsprintf(dest, fmt, vaArgs); int32 result = vsprintf(dest, fmt, vaArgs.ToVAList());
vaArgs.End!(); vaArgs.End!();
return result; return result;
} }
@ -82,7 +82,11 @@ namespace Tests
Test.Assert(str == "Test 223 2.2 3.3"); Test.Assert(str == "Test 223 2.2 3.3");
// LLVM 32-bit varargs bug? // 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(MethodA( 12, 23, 123.0f) == (12, 23, 123));
Test.Assert(MethodB( 9, 22, 33, 223.0f) == (22, 33, 223)); Test.Assert(MethodB( 9, 22, 33, 223.0f) == (22, 33, 223));
Test.Assert(MethodC(11, 32, 43, 323.0f) == (32, 43, 323)); Test.Assert(MethodC(11, 32, 43, 323.0f) == (32, 43, 323));