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: 1 addition & 1 deletion func.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func RegisterFunc(fptr any, cfn uintptr) {

for j, val := range args[i:] {
if val.Kind() == reflect.String {
ptr := strings.CString(v.String())
ptr := strings.CString(val.String())
keepAlive = append(keepAlive, ptr)
val = reflect.ValueOf(ptr)
args[i+j] = val
Expand Down
12 changes: 12 additions & 0 deletions func_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ func TestABI(t *testing.T) {
t.Fatalf("%s: got %d, want %d", cName, res, expect)
}
}
{
const cName = "stack_8i32_3strings"
var fn func(*byte, uintptr, int32, int32, int32, int32, int32, int32, int32, int32, string, string, string)
purego.RegisterLibFunc(&fn, lib, cName)
buf := make([]byte, 256)
fn(&buf[0], uintptr(len(buf)), 1, 2, 3, 4, 5, 6, 7, 8, "foo", "bar", "baz")
res := string(buf[:strings.IndexByte(string(buf), 0)])
const want = "1:2:3:4:5:6:7:8:foo:bar:baz"
if res != want {
t.Fatalf("%s: got %q, want %q", cName, res, want)
}
}
}

func buildSharedLib(compilerEnv, libFile string, sources ...string) error {
Expand Down
4 changes: 4 additions & 0 deletions testdata/abitest/abi_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ uint32_t stack_string(uint32_t a, uint32_t b, uint32_t c, uint32_t d, uint32_t e
assert(strcmp(i, "test") == 0);
return a | b | c | d | e | f | g | h;
}

void stack_8i32_3strings(char* result, size_t size, int32_t a1, int32_t a2, int32_t a3, int32_t a4, int32_t a5, int32_t a6, int32_t a7, int32_t a8, const char* s1, const char* s2, const char* s3) {
snprintf(result, size, "%d:%d:%d:%d:%d:%d:%d:%d:%s:%s:%s", a1, a2, a3, a4, a5, a6, a7, a8, s1, s2, s3);
}