From 65d3825cad7b1aaf6bb5ab5c4b50046791a7cea5 Mon Sep 17 00:00:00 2001 From: Virgil Date: Fri, 3 Apr 2026 19:30:32 +0000 Subject: [PATCH] feat(cgo): support common C integer types in Call Co-Authored-By: Virgil --- call_test.go | 8 ++++++++ call_test_support.go | 20 ++++++++++++++++++++ string_conversion.go | 14 ++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/call_test.go b/call_test.go index 12dc38a..8b88b5e 100644 --- a/call_test.go +++ b/call_test.go @@ -161,6 +161,14 @@ func TestCallSupportsBufferArgument(t *testing.T) { } } +func TestCallSupportsCommonCIntegerTypes(t *testing.T) { + t.Parallel() + + if err := callSupportsCIntegerArguments(); err != nil { + t.Fatalf("expected success, got error: %v", err) + } +} + func TestErrnoMapping(t *testing.T) { t.Parallel() diff --git a/call_test_support.go b/call_test_support.go index 44e2fb1..aefd2a3 100644 --- a/call_test_support.go +++ b/call_test_support.go @@ -75,6 +75,13 @@ int call_buffer_argument(uintptr_t value) { return value == 0 ? 13 : 0; } +int call_c_types_arguments(long a0, unsigned long a1, long long a2, unsigned long long a3) { + if (a0 == 10 && a1 == 11 && a2 == 12 && a3 == 13) { + return 0; + } + return 13; +} + uintptr_t call_sum_length_ptr(void) { return (uintptr_t)&call_sum_length; } @@ -119,6 +126,10 @@ uintptr_t call_buffer_argument_ptr(void) { return (uintptr_t)&call_buffer_argument; } +uintptr_t call_c_types_arguments_ptr(void) { + return (uintptr_t)&call_c_types_arguments; +} + */ import "C" @@ -179,6 +190,11 @@ func callBufferArgumentFunction() unsafe.Pointer { return *(*unsafe.Pointer)(unsafe.Pointer(&function)) } +func callCTypeArgumentFunction() unsafe.Pointer { + function := C.call_c_types_arguments_ptr() + return *(*unsafe.Pointer)(unsafe.Pointer(&function)) +} + func callWithErrnoZero() (int, error) { return WithErrno(func() C.int { return 0 @@ -190,3 +206,7 @@ func callWithErrnoFailure() (int, error) { return 2 }) } + +func callSupportsCIntegerArguments() error { + return Call(callCTypeArgumentFunction(), C.long(10), C.ulong(11), C.longlong(12), C.ulonglong(13)) +} diff --git a/string_conversion.go b/string_conversion.go index 5a1c4bc..734ac1e 100644 --- a/string_conversion.go +++ b/string_conversion.go @@ -757,8 +757,22 @@ func toSyscallArg(value interface{}) (uintptr, bool) { return uintptr(typed), true case C.char: return uintptr(typed), true + case C.schar: + return uintptr(typed), true + case C.uchar: + return uintptr(typed), true + case C.short: + return uintptr(typed), true + case C.ushort: + return uintptr(typed), true case C.int: return uintptr(typed), true + case C.long: + return uintptr(typed), true + case C.longlong: + return uintptr(typed), true + case C.ulonglong: + return uintptr(typed), true case C.size_t: return uintptr(typed), true case *C.char: