Skip to content

Commit d687c38

Browse files
committed
Properly handle struct return in AArch64 FFI
1 parent 6660765 commit d687c38

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

BeefLibs/corlib/src/Reflection/MethodInfo.bf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,10 +543,22 @@ namespace System.Reflection
543543
FFIType* ffiRetType = null;
544544
if (retType.IsStruct)
545545
{
546+
#if BF_MACHINE_AARCH64
547+
let ffiRetElements = scope:: List<FFIType*>(8);
548+
for (let fi in retType.GetFields(.Instance | .DeclaredOnly))
549+
{
550+
let ffiType = GetFFIType!::(fi.FieldType);
551+
ffiRetElements.Add(ffiType);
552+
}
553+
ffiRetElements.Add(null);
554+
ffiRetType = scope::FFIType(0, 0, .Struct);
555+
ffiRetType.mElements = ffiRetElements.Ptr;
556+
#else
546557
ffiRetType = &FFIType.Void;
547558
ffiParamList.Add(&FFIType.Pointer);
548559
ffiArgList.Add(&variantData);
549560
retData = &unusedRetVal;
561+
#endif
550562
}
551563
else
552564
ffiRetType = GetFFIType!::(retType);
@@ -947,10 +959,22 @@ namespace System.Reflection
947959
FFIType* ffiRetType = null;
948960
if (retType.IsStruct)
949961
{
962+
#if BF_MACHINE_AARCH64
963+
let ffiRetElements = scope:: List<FFIType*>(8);
964+
for (let fi in retType.GetFields(.Instance | .DeclaredOnly))
965+
{
966+
let ffiType = GetFFIType!::(fi.FieldType);
967+
ffiRetElements.Add(ffiType);
968+
}
969+
ffiRetElements.Add(null);
970+
ffiRetType = scope::FFIType(0, 0, .Struct);
971+
ffiRetType.mElements = ffiRetElements.Ptr;
972+
#else
950973
ffiRetType = &FFIType.Void;
951974
ffiParamList.Add(&FFIType.Pointer);
952975
ffiArgList.Add(&variantData);
953976
retData = &unusedRetVal;
977+
#endif
954978
}
955979
else
956980
ffiRetType = GetFFIType!::(retType);

0 commit comments

Comments
 (0)