From f835712e163254115b3244cbc8b3e09d92032a47 Mon Sep 17 00:00:00 2001 From: Virgil Date: Fri, 3 Apr 2026 19:20:31 +0000 Subject: [PATCH] feat(cgo): support *Buffer as Call argument Co-Authored-By: Virgil --- call_test.go | 11 +++++++++++ call_test_support.go | 14 ++++++++++++++ string_conversion.go | 5 +++++ 3 files changed, 30 insertions(+) diff --git a/call_test.go b/call_test.go index e7284c9..8379efb 100644 --- a/call_test.go +++ b/call_test.go @@ -94,6 +94,17 @@ func TestCallSupportsSixArguments(t *testing.T) { } } +func TestCallSupportsBufferArgument(t *testing.T) { + t.Parallel() + + buffer := NewBuffer(4) + defer buffer.Free() + + if err := Call(callBufferArgumentFunction(), buffer); 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 c23d173..23b130f 100644 --- a/call_test_support.go +++ b/call_test_support.go @@ -22,6 +22,10 @@ int call_six_args(uintptr_t a0, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintpt return 13; } +int call_buffer_argument(uintptr_t value) { + return value == 0 ? 13 : 0; +} + uintptr_t call_sum_length_ptr(void) { return (uintptr_t)&call_sum_length; } @@ -33,6 +37,11 @@ uintptr_t call_failure_ptr(void) { uintptr_t call_six_args_ptr(void) { return (uintptr_t)&call_six_args; } + +uintptr_t call_buffer_argument_ptr(void) { + return (uintptr_t)&call_buffer_argument; +} + */ import "C" @@ -53,6 +62,11 @@ func callSixArgumentFunction() unsafe.Pointer { return *(*unsafe.Pointer)(unsafe.Pointer(&function)) } +func callBufferArgumentFunction() unsafe.Pointer { + function := C.call_buffer_argument_ptr() + return *(*unsafe.Pointer)(unsafe.Pointer(&function)) +} + func callWithErrnoZero() (int, error) { return WithErrno(func() C.int { return 0 diff --git a/string_conversion.go b/string_conversion.go index f276b48..6d86e4d 100644 --- a/string_conversion.go +++ b/string_conversion.go @@ -215,6 +215,11 @@ func toSyscallArg(value interface{}) (uintptr, bool) { return 0, true case uintptr: return typed, true + case *Buffer: + if typed == nil { + return 0, true + } + return uintptr(typed.Ptr()), true case unsafe.Pointer: return uintptr(typed), true case C.char: -- 2.45.3