feat(call): support numeric C alias args in Call conversion
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
9f267f4c05
commit
665456c7e7
3 changed files with 38 additions and 0 deletions
|
|
@ -169,6 +169,14 @@ func TestCallSupportsCommonCIntegerTypes(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestCallSupportsCUintptrArgument(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if err := callSupportsCUintptrArgument(); err != nil {
|
||||
t.Fatalf("expected success, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestErrnoMapping(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
|
|
|||
|
|
@ -82,6 +82,10 @@ int call_c_types_arguments(long a0, unsigned long a1, long long a2, unsigned lon
|
|||
return 13;
|
||||
}
|
||||
|
||||
int call_uintptr_argument(uintptr_t value) {
|
||||
return value == 42 ? 0 : 13;
|
||||
}
|
||||
|
||||
uintptr_t call_sum_length_ptr(void) {
|
||||
return (uintptr_t)&call_sum_length;
|
||||
}
|
||||
|
|
@ -130,6 +134,10 @@ uintptr_t call_c_types_arguments_ptr(void) {
|
|||
return (uintptr_t)&call_c_types_arguments;
|
||||
}
|
||||
|
||||
uintptr_t call_uintptr_argument_ptr(void) {
|
||||
return (uintptr_t)&call_uintptr_argument;
|
||||
}
|
||||
|
||||
*/
|
||||
import "C"
|
||||
|
||||
|
|
@ -195,6 +203,11 @@ func callCTypeArgumentFunction() unsafe.Pointer {
|
|||
return *(*unsafe.Pointer)(unsafe.Pointer(&function))
|
||||
}
|
||||
|
||||
func callCUintptrArgumentFunction() unsafe.Pointer {
|
||||
function := C.call_uintptr_argument_ptr()
|
||||
return *(*unsafe.Pointer)(unsafe.Pointer(&function))
|
||||
}
|
||||
|
||||
func callWithErrnoZero() (int, error) {
|
||||
return WithErrno(func() C.int {
|
||||
return 0
|
||||
|
|
@ -210,3 +223,7 @@ func callWithErrnoFailure() (int, error) {
|
|||
func callSupportsCIntegerArguments() error {
|
||||
return Call(callCTypeArgumentFunction(), C.long(10), C.ulong(11), C.longlong(12), C.ulonglong(13))
|
||||
}
|
||||
|
||||
func callSupportsCUintptrArgument() error {
|
||||
return Call(callCUintptrArgumentFunction(), C.uintptr_t(42))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ int cgo_call_16(uintptr_t fn, uintptr_t a0, uintptr_t a1, uintptr_t a2, uintptr_
|
|||
import "C"
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strconv"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
|
@ -805,6 +806,18 @@ func toSyscallArg(value interface{}) (uintptr, bool) {
|
|||
case uint64:
|
||||
return uintptr(typed), true
|
||||
default:
|
||||
reflected := reflect.ValueOf(value)
|
||||
switch reflected.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return uintptr(reflected.Int()), true
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
return uintptr(reflected.Uint()), true
|
||||
case reflect.Bool:
|
||||
if reflected.Bool() {
|
||||
return 1, true
|
||||
}
|
||||
return 0, true
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue