Skip to content

Commit aeaa0bf

Browse files
committed
Func: Add support for arrays by converting them to slices
1 parent d787646 commit aeaa0bf

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

func.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func RegisterFunc(fptr interface{}, cfn uintptr) {
143143
panic("purego: CDecl must be the first argument")
144144
}
145145
}
146-
case reflect.String, reflect.Uintptr, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
146+
case reflect.Array, reflect.String, reflect.Uintptr, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
147147
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Ptr, reflect.UnsafePointer,
148148
reflect.Slice, reflect.Bool:
149149
if ints < numOfIntegerRegisters() {
@@ -285,6 +285,12 @@ func RegisterFunc(fptr interface{}, cfn uintptr) {
285285
addInt(uintptr(v.Uint()))
286286
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
287287
addInt(uintptr(v.Int()))
288+
case reflect.Array:
289+
sliceT := reflect.SliceOf(v.Type().Elem())
290+
slice := reflect.MakeSlice(sliceT, v.Len(), v.Len())
291+
reflect.Copy(slice, v)
292+
v = slice
293+
fallthrough
288294
case reflect.Ptr, reflect.UnsafePointer, reflect.Slice:
289295
if g, ok := v.Interface().([]string); ok {
290296
res := strings.ByteSlice(g)

0 commit comments

Comments
 (0)