feat(cgo): support common C integer types in Call

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-03 19:30:32 +00:00
parent d3e2f7da1e
commit 65d3825cad
3 changed files with 42 additions and 0 deletions

View file

@ -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()

View file

@ -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))
}

View file

@ -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: