Skip to content

Commit e49e529

Browse files
committed
purego: add FourInt32s struct argument test case
Adds test coverage for struct arguments containing four int32 fields to validate proper struct packing and argument marshalling. The test ensures that all four int32 values are correctly passed to the C function and can be retrieved and formatted as expected. This test case helps verify the Darwin ARM64 struct packing improvements handle multiple small integer fields within a single struct correctly.
1 parent 1bb4460 commit e49e529

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

struct_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,18 @@ func TestRegisterFunc_structArgs(t *testing.T) {
486486
t.Fatalf("FloatAndBool(y: false) = %d, want 0", ret)
487487
}
488488
}
489+
{
490+
type FourInt32s struct {
491+
f0, f1, f2, f3 int32
492+
}
493+
var FourInt32sFn func(FourInt32s) string
494+
purego.RegisterLibFunc(&FourInt32sFn, lib, "FourInt32s")
495+
result := FourInt32sFn(FourInt32s{1, 2, 3, 4})
496+
const want = "1:2:3:4"
497+
if result != want {
498+
t.Fatalf("FourInt32s returned %q wanted %q", result, want)
499+
}
500+
}
489501
}
490502

491503
func TestRegisterFunc_structReturns(t *testing.T) {

testdata/structtest/struct_test.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,3 +361,19 @@ struct FloatAndBool {
361361
int FloatAndBool(struct FloatAndBool f) {
362362
return f.has_value;
363363
}
364+
365+
struct FourInt32s {
366+
int32_t f0;
367+
int32_t f1;
368+
int32_t f2;
369+
int32_t f3;
370+
};
371+
372+
#include <stdio.h>
373+
#include <stdlib.h>
374+
375+
char* FourInt32s(struct FourInt32s s) {
376+
char* result = malloc(64);
377+
snprintf(result, 64, "%d:%d:%d:%d", s.f0, s.f1, s.f2, s.f3);
378+
return result;
379+
}

0 commit comments

Comments
 (0)