Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions struct_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 15 additions & 2 deletions struct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
{
Expand Down Expand Up @@ -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) {
Expand Down
15 changes: 14 additions & 1 deletion testdata/structtest/struct_test.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2024 The Ebitengine Authors

#include "stdint.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

#if defined(__x86_64__) || defined(__aarch64__)
typedef int64_t GoInt;
Expand Down Expand Up @@ -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;
}