diff --git a/struct_arm64.go b/struct_arm64.go index b11983f3..8605e77b 100644 --- a/struct_arm64.go +++ b/struct_arm64.go @@ -117,6 +117,8 @@ func placeRegisters(v reflect.Value, addFloat func(uintptr), addInt func(uintptr } else { addInt(uintptr(val)) } + val = 0 + class = _NO_CLASS } switch f.Type().Kind() { case reflect.Struct: diff --git a/struct_test.go b/struct_test.go index b7347e09..4e3483b3 100644 --- a/struct_test.go +++ b/struct_test.go @@ -373,8 +373,9 @@ func TestRegisterFunc_structArgs(t *testing.T) { } var Array4CharsFn func(chars Array4Chars) int32 purego.RegisterLibFunc(&Array4CharsFn, lib, "Array4Chars") - if ret := Array4CharsFn(Array4Chars{a: [...]int8{100, -127, 4, -100}}); ret != expectedSigned { - t.Fatalf("Array4CharsFn returned %#x wanted %#x", ret, expectedSigned) + const expectedSum = 1 + 2 + 4 + 8 + if ret := Array4CharsFn(Array4Chars{a: [...]int8{1, 2, 4, 8}}); ret != expectedSum { + t.Fatalf("Array4CharsFn returned %d wanted %d", ret, expectedSum) } } { @@ -486,6 +487,18 @@ func TestRegisterFunc_structArgs(t *testing.T) { t.Fatalf("FloatAndBool(y: false) = %d, want 0", ret) } } + { + type FourInt32s struct { + f0, f1, f2, f3 int32 + } + var FourInt32sFn func(FourInt32s) int32 + purego.RegisterLibFunc(&FourInt32sFn, lib, "FourInt32s") + result := FourInt32sFn(FourInt32s{100, -127, 4, -100}) + const want = 100 - 127 + 4 - 100 + if result != want { + t.Fatalf("FourInt32s returned %d wanted %d", result, want) + } + } } func TestRegisterFunc_structReturns(t *testing.T) { diff --git a/testdata/structtest/struct_test.c b/testdata/structtest/struct_test.c index 5769f8d1..4cbf8060 100644 --- a/testdata/structtest/struct_test.c +++ b/testdata/structtest/struct_test.c @@ -1,7 +1,9 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2024 The Ebitengine Authors -#include "stdint.h" +#include +#include +#include #if defined(__x86_64__) || defined(__aarch64__) typedef int64_t GoInt; @@ -361,3 +363,14 @@ struct FloatAndBool { int FloatAndBool(struct FloatAndBool f) { return f.has_value; } + +struct FourInt32s { + int32_t f0; + int32_t f1; + int32_t f2; + int32_t f3; +}; + +int32_t FourInt32s(struct FourInt32s s) { + return s.f0 + s.f1 + s.f2 + s.f3; +}