detached 1f4eb8c

all: replace interface{} with any (#283)

commit
1f4eb8c37f1752e5ec9754b70a277a2bcfb3d76b
author
TotallyGamerJet · · 2024-10-18 02:40 UTC
committer
GitHub · · 2024-10-18 02:40 UTC
parent
0196f2d
signature
GPG UnverifiedB5690EEEBB952194 The key is unknown
8 files · +20 -20
M func.go +6 -6
@@ -22,7 +22,7 @@ var thePool = sync.Pool{New: func() any {
2222
2323 // RegisterLibFunc is a wrapper around RegisterFunc that uses the C function returned from Dlsym(handle, name).
2424 // It panics if it can't find the name symbol.
25-func RegisterLibFunc(fptr interface{}, handle uintptr, name string) {
25+func RegisterLibFunc(fptr any, handle uintptr, name string) {
2626 sym, err := loadSymbol(handle, name)
2727 if err != nil {
2828 panic(err)
@@ -65,7 +65,7 @@ func RegisterLibFunc(fptr interface{}, handle uintptr, name string) {
6565 //
6666 // There is a special case when the last argument of fptr is a variadic interface (or []interface}
6767 // it will be expanded into a call to the C function as if it had the arguments in that slice.
68-// This means that using arg ...interface{} is like a cast to the function with the arguments inside arg.
68+// This means that using arg ...any is like a cast to the function with the arguments inside arg.
6969 // This is not the same as C variadic.
7070 //
7171 // # Memory
@@ -110,7 +110,7 @@ func RegisterLibFunc(fptr interface{}, handle uintptr, name string) {
110110 // defer free(mustFree)
111111 //
112112 // [Cgo rules]: https://pkg.go.dev/cmd/cgo#hdr-Go_references_to_C
113-func RegisterFunc(fptr interface{}, cfn uintptr) {
113+func RegisterFunc(fptr any, cfn uintptr) {
114114 fn := reflect.ValueOf(fptr).Elem()
115115 ty := fn.Type()
116116 if ty.Kind() != reflect.Func {
@@ -248,7 +248,7 @@ func RegisterFunc(fptr interface{}, cfn uintptr) {
248248 addFloat = addStack
249249 }
250250
251- var keepAlive []interface{}
251+ var keepAlive []any
252252 defer func() {
253253 runtime.KeepAlive(keepAlive)
254254 runtime.KeepAlive(args)
@@ -271,7 +271,7 @@ func RegisterFunc(fptr interface{}, cfn uintptr) {
271271 }
272272 }
273273 for i, v := range args {
274- if variadic, ok := args[i].Interface().([]interface{}); ok {
274+ if variadic, ok := args[i].Interface().([]any); ok {
275275 if i != len(args)-1 {
276276 panic("purego: can only expand last parameter")
277277 }
@@ -347,7 +347,7 @@ func RegisterFunc(fptr interface{}, cfn uintptr) {
347347 fn.Set(v)
348348 }
349349
350-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{} {
350+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 {
351351 switch v.Kind() {
352352 case reflect.String:
353353 ptr := strings.CString(v.String())
@@ -22,7 +22,7 @@ var thePool = sync.Pool{New: func() any {
22 22
23 // RegisterLibFunc is a wrapper around RegisterFunc that uses the C function returned from Dlsym(handle, name).23 // RegisterLibFunc is a wrapper around RegisterFunc that uses the C function returned from Dlsym(handle, name).
24 // It panics if it can't find the name symbol.24 // It panics if it can't find the name symbol.
25-func RegisterLibFunc(fptr interface{}, handle uintptr, name string) {25+func RegisterLibFunc(fptr any, handle uintptr, name string) {
26 sym, err := loadSymbol(handle, name)26 sym, err := loadSymbol(handle, name)
27 if err != nil {27 if err != nil {
28 panic(err)28 panic(err)
@@ -65,7 +65,7 @@ func RegisterLibFunc(fptr interface{}, handle uintptr, name string) {
65 //65 //
66 // There is a special case when the last argument of fptr is a variadic interface (or []interface}66 // There is a special case when the last argument of fptr is a variadic interface (or []interface}
67 // it will be expanded into a call to the C function as if it had the arguments in that slice.67 // it will be expanded into a call to the C function as if it had the arguments in that slice.
68-// This means that using arg ...interface{} is like a cast to the function with the arguments inside arg.68+// This means that using arg ...any is like a cast to the function with the arguments inside arg.
69 // This is not the same as C variadic.69 // This is not the same as C variadic.
70 //70 //
71 // # Memory71 // # Memory
@@ -110,7 +110,7 @@ func RegisterLibFunc(fptr interface{}, handle uintptr, name string) {
110 // defer free(mustFree)110 // defer free(mustFree)
111 //111 //
112 // [Cgo rules]: https://pkg.go.dev/cmd/cgo#hdr-Go_references_to_C112 // [Cgo rules]: https://pkg.go.dev/cmd/cgo#hdr-Go_references_to_C
113-func RegisterFunc(fptr interface{}, cfn uintptr) {113+func RegisterFunc(fptr any, cfn uintptr) {
114 fn := reflect.ValueOf(fptr).Elem()114 fn := reflect.ValueOf(fptr).Elem()
115 ty := fn.Type()115 ty := fn.Type()
116 if ty.Kind() != reflect.Func {116 if ty.Kind() != reflect.Func {
@@ -248,7 +248,7 @@ func RegisterFunc(fptr interface{}, cfn uintptr) {
248 addFloat = addStack248 addFloat = addStack
249 }249 }
250 250
251- var keepAlive []interface{}251+ var keepAlive []any
252 defer func() {252 defer func() {
253 runtime.KeepAlive(keepAlive)253 runtime.KeepAlive(keepAlive)
254 runtime.KeepAlive(args)254 runtime.KeepAlive(args)
@@ -271,7 +271,7 @@ func RegisterFunc(fptr interface{}, cfn uintptr) {
271 }271 }
272 }272 }
273 for i, v := range args {273 for i, v := range args {
274- if variadic, ok := args[i].Interface().([]interface{}); ok {274+ if variadic, ok := args[i].Interface().([]any); ok {
275 if i != len(args)-1 {275 if i != len(args)-1 {
276 panic("purego: can only expand last parameter")276 panic("purego: can only expand last parameter")
277 }277 }
@@ -347,7 +347,7 @@ func RegisterFunc(fptr interface{}, cfn uintptr) {
347 fn.Set(v)347 fn.Set(v)
348 }348 }
349 349
350-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{} {350+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 {
351 switch v.Kind() {351 switch v.Kind() {
352 case reflect.String:352 case reflect.String:
353 ptr := strings.CString(v.String())353 ptr := strings.CString(v.String())
M objc/objc_runtime_darwin.go +6 -6
@@ -23,10 +23,10 @@ import (
2323 var (
2424 objc_msgSend_fn uintptr
2525 objc_msgSend_stret_fn uintptr
26- objc_msgSend func(obj ID, cmd SEL, args ...interface{}) ID
26+ objc_msgSend func(obj ID, cmd SEL, args ...any) ID
2727 objc_msgSendSuper2_fn uintptr
2828 objc_msgSendSuper2_stret_fn uintptr
29- objc_msgSendSuper2 func(super *objc_super, cmd SEL, args ...interface{}) ID
29+ objc_msgSendSuper2 func(super *objc_super, cmd SEL, args ...any) ID
3030 objc_getClass func(name string) Class
3131 objc_getProtocol func(name string) *Protocol
3232 objc_allocateClassPair func(super Class, name string, extraBytes uintptr) Class
@@ -103,7 +103,7 @@ func (id ID) Class() Class {
103103 // Send is a convenience method for sending messages to objects. This function takes a SEL
104104 // instead of a string since RegisterName grabs the global Objective-C lock. It is best to cache the result
105105 // of RegisterName.
106-func (id ID) Send(sel SEL, args ...interface{}) ID {
106+func (id ID) Send(sel SEL, args ...any) ID {
107107 return objc_msgSend(id, sel, args...)
108108 }
109109
@@ -147,7 +147,7 @@ type objc_super struct {
147147 // SendSuper is a convenience method for sending message to object's super. This function takes a SEL
148148 // instead of a string since RegisterName grabs the global Objective-C lock. It is best to cache the result
149149 // of RegisterName.
150-func (id ID) SendSuper(sel SEL, args ...interface{}) ID {
150+func (id ID) SendSuper(sel SEL, args ...any) ID {
151151 super := &objc_super{
152152 receiver: id,
153153 superClass: id.Class(),
@@ -449,7 +449,7 @@ func encodeType(typ reflect.Type, insidePtr bool) (string, error) {
449449 }
450450
451451 // encodeFunc returns a functions type as if it was given to @encode(fn)
452-func encodeFunc(fn interface{}) (string, error) {
452+func encodeFunc(fn any) (string, error) {
453453 typ := reflect.TypeOf(fn)
454454 if typ.Kind() != reflect.Func {
455455 return "", errors.New("not a func")
@@ -551,7 +551,7 @@ type IMP uintptr
551551 // It returns an IMP function pointer that can be called by Objective-C code.
552552 // The function panics if an error occurs.
553553 // The function pointer is never deallocated.
554-func NewIMP(fn interface{}) IMP {
554+func NewIMP(fn any) IMP {
555555 ty := reflect.TypeOf(fn)
556556 if ty.Kind() != reflect.Func {
557557 panic("objc: not a function")
@@ -23,10 +23,10 @@ import (
23 var (23 var (
24 objc_msgSend_fn uintptr24 objc_msgSend_fn uintptr
25 objc_msgSend_stret_fn uintptr25 objc_msgSend_stret_fn uintptr
26- objc_msgSend func(obj ID, cmd SEL, args ...interface{}) ID26+ objc_msgSend func(obj ID, cmd SEL, args ...any) ID
27 objc_msgSendSuper2_fn uintptr27 objc_msgSendSuper2_fn uintptr
28 objc_msgSendSuper2_stret_fn uintptr28 objc_msgSendSuper2_stret_fn uintptr
29- objc_msgSendSuper2 func(super *objc_super, cmd SEL, args ...interface{}) ID29+ objc_msgSendSuper2 func(super *objc_super, cmd SEL, args ...any) ID
30 objc_getClass func(name string) Class30 objc_getClass func(name string) Class
31 objc_getProtocol func(name string) *Protocol31 objc_getProtocol func(name string) *Protocol
32 objc_allocateClassPair func(super Class, name string, extraBytes uintptr) Class32 objc_allocateClassPair func(super Class, name string, extraBytes uintptr) Class
@@ -103,7 +103,7 @@ func (id ID) Class() Class {
103 // Send is a convenience method for sending messages to objects. This function takes a SEL103 // Send is a convenience method for sending messages to objects. This function takes a SEL
104 // instead of a string since RegisterName grabs the global Objective-C lock. It is best to cache the result104 // instead of a string since RegisterName grabs the global Objective-C lock. It is best to cache the result
105 // of RegisterName.105 // of RegisterName.
106-func (id ID) Send(sel SEL, args ...interface{}) ID {106+func (id ID) Send(sel SEL, args ...any) ID {
107 return objc_msgSend(id, sel, args...)107 return objc_msgSend(id, sel, args...)
108 }108 }
109 109
@@ -147,7 +147,7 @@ type objc_super struct {
147 // SendSuper is a convenience method for sending message to object's super. This function takes a SEL147 // SendSuper is a convenience method for sending message to object's super. This function takes a SEL
148 // instead of a string since RegisterName grabs the global Objective-C lock. It is best to cache the result148 // instead of a string since RegisterName grabs the global Objective-C lock. It is best to cache the result
149 // of RegisterName.149 // of RegisterName.
150-func (id ID) SendSuper(sel SEL, args ...interface{}) ID {150+func (id ID) SendSuper(sel SEL, args ...any) ID {
151 super := &objc_super{151 super := &objc_super{
152 receiver: id,152 receiver: id,
153 superClass: id.Class(),153 superClass: id.Class(),
@@ -449,7 +449,7 @@ func encodeType(typ reflect.Type, insidePtr bool) (string, error) {
449 }449 }
450 450
451 // encodeFunc returns a functions type as if it was given to @encode(fn)451 // encodeFunc returns a functions type as if it was given to @encode(fn)
452-func encodeFunc(fn interface{}) (string, error) {452+func encodeFunc(fn any) (string, error) {
453 typ := reflect.TypeOf(fn)453 typ := reflect.TypeOf(fn)
454 if typ.Kind() != reflect.Func {454 if typ.Kind() != reflect.Func {
455 return "", errors.New("not a func")455 return "", errors.New("not a func")
@@ -551,7 +551,7 @@ type IMP uintptr
551 // It returns an IMP function pointer that can be called by Objective-C code.551 // It returns an IMP function pointer that can be called by Objective-C code.
552 // The function panics if an error occurs.552 // The function panics if an error occurs.
553 // The function pointer is never deallocated.553 // The function pointer is never deallocated.
554-func NewIMP(fn interface{}) IMP {554+func NewIMP(fn any) IMP {
555 ty := reflect.TypeOf(fn)555 ty := reflect.TypeOf(fn)
556 if ty.Kind() != reflect.Func {556 if ty.Kind() != reflect.Func {
557 panic("objc: not a function")557 panic("objc: not a function")
M struct_amd64.go +1 -1
@@ -85,7 +85,7 @@ const (
8585 _MEMORY = 0b1111
8686 )
8787
88-func addStruct(v reflect.Value, numInts, numFloats, numStack *int, addInt, addFloat, addStack func(uintptr), keepAlive []interface{}) []interface{} {
88+func addStruct(v reflect.Value, numInts, numFloats, numStack *int, addInt, addFloat, addStack func(uintptr), keepAlive []any) []any {
8989 if v.Type().Size() == 0 {
9090 return keepAlive
9191 }
@@ -85,7 +85,7 @@ const (
85 _MEMORY = 0b111185 _MEMORY = 0b1111
86 )86 )
87 87
88-func addStruct(v reflect.Value, numInts, numFloats, numStack *int, addInt, addFloat, addStack func(uintptr), keepAlive []interface{}) []interface{} {88+func addStruct(v reflect.Value, numInts, numFloats, numStack *int, addInt, addFloat, addStack func(uintptr), keepAlive []any) []any {
89 if v.Type().Size() == 0 {89 if v.Type().Size() == 0 {
90 return keepAlive90 return keepAlive
91 }91 }
M struct_arm64.go +2 -2
@@ -65,7 +65,7 @@ const (
6565 _INT = 0b11
6666 )
6767
68-func addStruct(v reflect.Value, numInts, numFloats, numStack *int, addInt, addFloat, addStack func(uintptr), keepAlive []interface{}) []interface{} {
68+func addStruct(v reflect.Value, numInts, numFloats, numStack *int, addInt, addFloat, addStack func(uintptr), keepAlive []any) []any {
6969 if v.Type().Size() == 0 {
7070 return keepAlive
7171 }
@@ -187,7 +187,7 @@ func placeRegisters(v reflect.Value, addFloat func(uintptr), addInt func(uintptr
187187 }
188188 }
189189
190-func placeStack(v reflect.Value, keepAlive []interface{}, addInt func(uintptr)) []interface{} {
190+func placeStack(v reflect.Value, keepAlive []any, addInt func(uintptr)) []any {
191191 // Struct is too big to be placed in registers.
192192 // Copy to heap and place the pointer in register
193193 ptrStruct := reflect.New(v.Type())
@@ -65,7 +65,7 @@ const (
65 _INT = 0b1165 _INT = 0b11
66 )66 )
67 67
68-func addStruct(v reflect.Value, numInts, numFloats, numStack *int, addInt, addFloat, addStack func(uintptr), keepAlive []interface{}) []interface{} {68+func addStruct(v reflect.Value, numInts, numFloats, numStack *int, addInt, addFloat, addStack func(uintptr), keepAlive []any) []any {
69 if v.Type().Size() == 0 {69 if v.Type().Size() == 0 {
70 return keepAlive70 return keepAlive
71 }71 }
@@ -187,7 +187,7 @@ func placeRegisters(v reflect.Value, addFloat func(uintptr), addInt func(uintptr
187 }187 }
188 }188 }
189 189
190-func placeStack(v reflect.Value, keepAlive []interface{}, addInt func(uintptr)) []interface{} {190+func placeStack(v reflect.Value, keepAlive []any, addInt func(uintptr)) []any {
191 // Struct is too big to be placed in registers.191 // Struct is too big to be placed in registers.
192 // Copy to heap and place the pointer in register192 // Copy to heap and place the pointer in register
193 ptrStruct := reflect.New(v.Type())193 ptrStruct := reflect.New(v.Type())
M struct_other.go +1 -1
@@ -7,7 +7,7 @@ package purego
77
88 import "reflect"
99
10-func addStruct(v reflect.Value, numInts, numFloats, numStack *int, addInt, addFloat, addStack func(uintptr), keepAlive []interface{}) []interface{} {
10+func addStruct(v reflect.Value, numInts, numFloats, numStack *int, addInt, addFloat, addStack func(uintptr), keepAlive []any) []any {
1111 panic("purego: struct arguments are not supported")
1212 }
1313
@@ -7,7 +7,7 @@ package purego
7 7
8 import "reflect"8 import "reflect"
9 9
10-func addStruct(v reflect.Value, numInts, numFloats, numStack *int, addInt, addFloat, addStack func(uintptr), keepAlive []interface{}) []interface{} {10+func addStruct(v reflect.Value, numInts, numFloats, numStack *int, addInt, addFloat, addStack func(uintptr), keepAlive []any) []any {
11 panic("purego: struct arguments are not supported")11 panic("purego: struct arguments are not supported")
12 }12 }
13 13
M syscall_cgo_linux.go +1 -1
@@ -16,6 +16,6 @@ func syscall_syscall15X(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a
1616 return cgo.Syscall15X(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15)
1717 }
1818
19-func NewCallback(_ interface{}) uintptr {
19+func NewCallback(_ any) uintptr {
2020 panic("purego: NewCallback on Linux is only supported on amd64/arm64")
2121 }
@@ -16,6 +16,6 @@ func syscall_syscall15X(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a
16 return cgo.Syscall15X(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15)16 return cgo.Syscall15X(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15)
17 }17 }
18 18
19-func NewCallback(_ interface{}) uintptr {19+func NewCallback(_ any) uintptr {
20 panic("purego: NewCallback on Linux is only supported on amd64/arm64")20 panic("purego: NewCallback on Linux is only supported on amd64/arm64")
21 }21 }
M syscall_sysv.go +2 -2
@@ -31,7 +31,7 @@ func syscall_syscall15X(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a
3131 // of uintptr. Only a limited number of callbacks may be created in a single Go process, and any memory allocated
3232 // for these callbacks is never released. At least 2000 callbacks can always be created. Although this function
3333 // provides similar functionality to windows.NewCallback it is distinct.
34-func NewCallback(fn interface{}) uintptr {
34+func NewCallback(fn any) uintptr {
3535 ty := reflect.TypeOf(fn)
3636 for i := 0; i < ty.NumIn(); i++ {
3737 in := ty.In(i)
@@ -71,7 +71,7 @@ type callbackArgs struct {
7171 result uintptr
7272 }
7373
74-func compileCallback(fn interface{}) uintptr {
74+func compileCallback(fn any) uintptr {
7575 val := reflect.ValueOf(fn)
7676 if val.Kind() != reflect.Func {
7777 panic("purego: the type must be a function but was not")
@@ -31,7 +31,7 @@ func syscall_syscall15X(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a
31 // of uintptr. Only a limited number of callbacks may be created in a single Go process, and any memory allocated31 // of uintptr. Only a limited number of callbacks may be created in a single Go process, and any memory allocated
32 // for these callbacks is never released. At least 2000 callbacks can always be created. Although this function32 // for these callbacks is never released. At least 2000 callbacks can always be created. Although this function
33 // provides similar functionality to windows.NewCallback it is distinct.33 // provides similar functionality to windows.NewCallback it is distinct.
34-func NewCallback(fn interface{}) uintptr {34+func NewCallback(fn any) uintptr {
35 ty := reflect.TypeOf(fn)35 ty := reflect.TypeOf(fn)
36 for i := 0; i < ty.NumIn(); i++ {36 for i := 0; i < ty.NumIn(); i++ {
37 in := ty.In(i)37 in := ty.In(i)
@@ -71,7 +71,7 @@ type callbackArgs struct {
71 result uintptr71 result uintptr
72 }72 }
73 73
74-func compileCallback(fn interface{}) uintptr {74+func compileCallback(fn any) uintptr {
75 val := reflect.ValueOf(fn)75 val := reflect.ValueOf(fn)
76 if val.Kind() != reflect.Func {76 if val.Kind() != reflect.Func {
77 panic("purego: the type must be a function but was not")77 panic("purego: the type must be a function but was not")
M syscall_windows.go +1 -1
@@ -22,7 +22,7 @@ func syscall_syscall15X(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a
2222 // allocated for these callbacks is never released. Between NewCallback and NewCallbackCDecl, at least 1024
2323 // callbacks can always be created. Although this function is similiar to the darwin version it may act
2424 // differently.
25-func NewCallback(fn interface{}) uintptr {
25+func NewCallback(fn any) uintptr {
2626 isCDecl := false
2727 ty := reflect.TypeOf(fn)
2828 for i := 0; i < ty.NumIn(); i++ {
@@ -22,7 +22,7 @@ func syscall_syscall15X(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a
22 // allocated for these callbacks is never released. Between NewCallback and NewCallbackCDecl, at least 102422 // allocated for these callbacks is never released. Between NewCallback and NewCallbackCDecl, at least 1024
23 // callbacks can always be created. Although this function is similiar to the darwin version it may act23 // callbacks can always be created. Although this function is similiar to the darwin version it may act
24 // differently.24 // differently.
25-func NewCallback(fn interface{}) uintptr {25+func NewCallback(fn any) uintptr {
26 isCDecl := false26 isCDecl := false
27 ty := reflect.TypeOf(fn)27 ty := reflect.TypeOf(fn)
28 for i := 0; i < ty.NumIn(); i++ {28 for i := 0; i < ty.NumIn(); i++ {

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close