Skip to content

Commit

Permalink
all: replace interface{} with any (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
TotallyGamerJet authored Oct 18, 2024
1 parent 0196f2d commit 1f4eb8c
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 20 deletions.
12 changes: 6 additions & 6 deletions func.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var thePool = sync.Pool{New: func() any {

// RegisterLibFunc is a wrapper around RegisterFunc that uses the C function returned from Dlsym(handle, name).
// It panics if it can't find the name symbol.
func RegisterLibFunc(fptr interface{}, handle uintptr, name string) {
func RegisterLibFunc(fptr any, handle uintptr, name string) {
sym, err := loadSymbol(handle, name)
if err != nil {
panic(err)
Expand Down Expand Up @@ -65,7 +65,7 @@ func RegisterLibFunc(fptr interface{}, handle uintptr, name string) {
//
// There is a special case when the last argument of fptr is a variadic interface (or []interface}
// it will be expanded into a call to the C function as if it had the arguments in that slice.
// This means that using arg ...interface{} is like a cast to the function with the arguments inside arg.
// This means that using arg ...any is like a cast to the function with the arguments inside arg.
// This is not the same as C variadic.
//
// # Memory
Expand Down Expand Up @@ -110,7 +110,7 @@ func RegisterLibFunc(fptr interface{}, handle uintptr, name string) {
// defer free(mustFree)
//
// [Cgo rules]: https://pkg.go.dev/cmd/cgo#hdr-Go_references_to_C
func RegisterFunc(fptr interface{}, cfn uintptr) {
func RegisterFunc(fptr any, cfn uintptr) {
fn := reflect.ValueOf(fptr).Elem()
ty := fn.Type()
if ty.Kind() != reflect.Func {
Expand Down Expand Up @@ -248,7 +248,7 @@ func RegisterFunc(fptr interface{}, cfn uintptr) {
addFloat = addStack
}

var keepAlive []interface{}
var keepAlive []any
defer func() {
runtime.KeepAlive(keepAlive)
runtime.KeepAlive(args)
Expand All @@ -271,7 +271,7 @@ func RegisterFunc(fptr interface{}, cfn uintptr) {
}
}
for i, v := range args {
if variadic, ok := args[i].Interface().([]interface{}); ok {
if variadic, ok := args[i].Interface().([]any); ok {
if i != len(args)-1 {
panic("purego: can only expand last parameter")
}
Expand Down Expand Up @@ -347,7 +347,7 @@ func RegisterFunc(fptr interface{}, cfn uintptr) {
fn.Set(v)
}

func addValue(v reflect.Value, keepAlive []interface{}, addInt func(x uintptr), addFloat func(x uintptr), addStack func(x uintptr), numInts *int, numFloats *int, numStack *int) []interface{} {
func addValue(v reflect.Value, keepAlive []any, addInt func(x uintptr), addFloat func(x uintptr), addStack func(x uintptr), numInts *int, numFloats *int, numStack *int) []any {
switch v.Kind() {
case reflect.String:
ptr := strings.CString(v.String())
Expand Down
12 changes: 6 additions & 6 deletions objc/objc_runtime_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
var (
objc_msgSend_fn uintptr
objc_msgSend_stret_fn uintptr
objc_msgSend func(obj ID, cmd SEL, args ...interface{}) ID
objc_msgSend func(obj ID, cmd SEL, args ...any) ID
objc_msgSendSuper2_fn uintptr
objc_msgSendSuper2_stret_fn uintptr
objc_msgSendSuper2 func(super *objc_super, cmd SEL, args ...interface{}) ID
objc_msgSendSuper2 func(super *objc_super, cmd SEL, args ...any) ID
objc_getClass func(name string) Class
objc_getProtocol func(name string) *Protocol
objc_allocateClassPair func(super Class, name string, extraBytes uintptr) Class
Expand Down Expand Up @@ -103,7 +103,7 @@ func (id ID) Class() Class {
// Send is a convenience method for sending messages to objects. This function takes a SEL
// instead of a string since RegisterName grabs the global Objective-C lock. It is best to cache the result
// of RegisterName.
func (id ID) Send(sel SEL, args ...interface{}) ID {
func (id ID) Send(sel SEL, args ...any) ID {
return objc_msgSend(id, sel, args...)
}

Expand Down Expand Up @@ -147,7 +147,7 @@ type objc_super struct {
// SendSuper is a convenience method for sending message to object's super. This function takes a SEL
// instead of a string since RegisterName grabs the global Objective-C lock. It is best to cache the result
// of RegisterName.
func (id ID) SendSuper(sel SEL, args ...interface{}) ID {
func (id ID) SendSuper(sel SEL, args ...any) ID {
super := &objc_super{
receiver: id,
superClass: id.Class(),
Expand Down Expand Up @@ -449,7 +449,7 @@ func encodeType(typ reflect.Type, insidePtr bool) (string, error) {
}

// encodeFunc returns a functions type as if it was given to @encode(fn)
func encodeFunc(fn interface{}) (string, error) {
func encodeFunc(fn any) (string, error) {
typ := reflect.TypeOf(fn)
if typ.Kind() != reflect.Func {
return "", errors.New("not a func")
Expand Down Expand Up @@ -551,7 +551,7 @@ type IMP uintptr
// It returns an IMP function pointer that can be called by Objective-C code.
// The function panics if an error occurs.
// The function pointer is never deallocated.
func NewIMP(fn interface{}) IMP {
func NewIMP(fn any) IMP {
ty := reflect.TypeOf(fn)
if ty.Kind() != reflect.Func {
panic("objc: not a function")
Expand Down
2 changes: 1 addition & 1 deletion struct_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const (
_MEMORY = 0b1111
)

func addStruct(v reflect.Value, numInts, numFloats, numStack *int, addInt, addFloat, addStack func(uintptr), keepAlive []interface{}) []interface{} {
func addStruct(v reflect.Value, numInts, numFloats, numStack *int, addInt, addFloat, addStack func(uintptr), keepAlive []any) []any {
if v.Type().Size() == 0 {
return keepAlive
}
Expand Down
4 changes: 2 additions & 2 deletions struct_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const (
_INT = 0b11
)

func addStruct(v reflect.Value, numInts, numFloats, numStack *int, addInt, addFloat, addStack func(uintptr), keepAlive []interface{}) []interface{} {
func addStruct(v reflect.Value, numInts, numFloats, numStack *int, addInt, addFloat, addStack func(uintptr), keepAlive []any) []any {
if v.Type().Size() == 0 {
return keepAlive
}
Expand Down Expand Up @@ -187,7 +187,7 @@ func placeRegisters(v reflect.Value, addFloat func(uintptr), addInt func(uintptr
}
}

func placeStack(v reflect.Value, keepAlive []interface{}, addInt func(uintptr)) []interface{} {
func placeStack(v reflect.Value, keepAlive []any, addInt func(uintptr)) []any {
// Struct is too big to be placed in registers.
// Copy to heap and place the pointer in register
ptrStruct := reflect.New(v.Type())
Expand Down
2 changes: 1 addition & 1 deletion struct_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package purego

import "reflect"

func addStruct(v reflect.Value, numInts, numFloats, numStack *int, addInt, addFloat, addStack func(uintptr), keepAlive []interface{}) []interface{} {
func addStruct(v reflect.Value, numInts, numFloats, numStack *int, addInt, addFloat, addStack func(uintptr), keepAlive []any) []any {
panic("purego: struct arguments are not supported")
}

Expand Down
2 changes: 1 addition & 1 deletion syscall_cgo_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ func syscall_syscall15X(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a
return cgo.Syscall15X(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15)
}

func NewCallback(_ interface{}) uintptr {
func NewCallback(_ any) uintptr {
panic("purego: NewCallback on Linux is only supported on amd64/arm64")
}
4 changes: 2 additions & 2 deletions syscall_sysv.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func syscall_syscall15X(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a
// of uintptr. Only a limited number of callbacks may be created in a single Go process, and any memory allocated
// for these callbacks is never released. At least 2000 callbacks can always be created. Although this function
// provides similar functionality to windows.NewCallback it is distinct.
func NewCallback(fn interface{}) uintptr {
func NewCallback(fn any) uintptr {
ty := reflect.TypeOf(fn)
for i := 0; i < ty.NumIn(); i++ {
in := ty.In(i)
Expand Down Expand Up @@ -71,7 +71,7 @@ type callbackArgs struct {
result uintptr
}

func compileCallback(fn interface{}) uintptr {
func compileCallback(fn any) uintptr {
val := reflect.ValueOf(fn)
if val.Kind() != reflect.Func {
panic("purego: the type must be a function but was not")
Expand Down
2 changes: 1 addition & 1 deletion syscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func syscall_syscall15X(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a
// allocated for these callbacks is never released. Between NewCallback and NewCallbackCDecl, at least 1024
// callbacks can always be created. Although this function is similiar to the darwin version it may act
// differently.
func NewCallback(fn interface{}) uintptr {
func NewCallback(fn any) uintptr {
isCDecl := false
ty := reflect.TypeOf(fn)
for i := 0; i < ty.NumIn(); i++ {
Expand Down

0 comments on commit 1f4eb8c

Please sign in to comment.