detached f88cc4c

objc: remove deprecated APIs (#226)

commit
f88cc4c6b4837eae57b41a0354377246e0920a6b
author
Hajime Hoshi · · 2024-04-06 11:50 UTC
committer
GitHub · · 2024-04-06 11:50 UTC
parent
d0aedd0
signature
GPG UnverifiedB5690EEEBB952194 The key is unknown
2 files · +92 -66
M objc/objc_runtime_darwin.go +0 -29
@@ -193,13 +193,6 @@ func GetClass(name string) Class {
193193 return objc_getClass(name)
194194 }
195195
196-// AllocateClassPair creates a new class and metaclass. Then returns the new class, or Nil if the class could not be created
197-//
198-// Deprecated: use RegisterClass instead
199-func AllocateClassPair(super Class, name string, extraBytes uintptr) Class {
200- return objc_allocateClassPair(super, name, extraBytes)
201-}
202-
203196 // MethodDef represents the Go function and the selector that ObjC uses to access that function.
204197 type MethodDef struct {
205198 Cmd SEL
@@ -506,20 +499,6 @@ func (c Class) AddMethod(name SEL, imp IMP, types string) bool {
506499 return class_addMethod(c, name, imp, types)
507500 }
508501
509-// AddIvar adds a new instance variable to a class.
510-// It may only be called after AllocateClassPair and before Register.
511-// Adding an instance variable to an existing class is not supported.
512-// The class must not be a metaclass. Adding an instance variable to a metaclass is not supported.
513-// It takes the instance of the type of the Ivar and a string representing the type.
514-//
515-// Deprecated: use RegisterClass instead
516-func (c Class) AddIvar(name string, ty interface{}, types string) bool {
517- typeOf := reflect.TypeOf(ty)
518- size := typeOf.Size()
519- alignment := uint8(math.Log2(float64(typeOf.Align())))
520- return class_addIvar(c, name, size, alignment, types)
521-}
522-
523502 // AddProtocol adds a protocol to a class.
524503 // Returns true if the protocol was added successfully, otherwise false (for example,
525504 // the class already conforms to that protocol).
@@ -537,14 +516,6 @@ func (c Class) InstanceVariable(name string) Ivar {
537516 return class_getInstanceVariable(c, name)
538517 }
539518
540-// Register registers a class that was allocated using AllocateClassPair.
541-// It can now be used to make objects by sending it either alloc and init or new.
542-//
543-// Deprecated: use RegisterClass instead
544-func (c Class) Register() {
545- objc_registerClassPair(c)
546-}
547-
548519 // Ivar an opaque type that represents an instance variable.
549520 type Ivar uintptr
550521
@@ -193,13 +193,6 @@ func GetClass(name string) Class {
193 return objc_getClass(name)193 return objc_getClass(name)
194 }194 }
195 195
196-// AllocateClassPair creates a new class and metaclass. Then returns the new class, or Nil if the class could not be created
197-//
198-// Deprecated: use RegisterClass instead
199-func AllocateClassPair(super Class, name string, extraBytes uintptr) Class {
200- return objc_allocateClassPair(super, name, extraBytes)
201-}
202-
203 // MethodDef represents the Go function and the selector that ObjC uses to access that function.196 // MethodDef represents the Go function and the selector that ObjC uses to access that function.
204 type MethodDef struct {197 type MethodDef struct {
205 Cmd SEL198 Cmd SEL
@@ -506,20 +499,6 @@ func (c Class) AddMethod(name SEL, imp IMP, types string) bool {
506 return class_addMethod(c, name, imp, types)499 return class_addMethod(c, name, imp, types)
507 }500 }
508 501
509-// AddIvar adds a new instance variable to a class.
510-// It may only be called after AllocateClassPair and before Register.
511-// Adding an instance variable to an existing class is not supported.
512-// The class must not be a metaclass. Adding an instance variable to a metaclass is not supported.
513-// It takes the instance of the type of the Ivar and a string representing the type.
514-//
515-// Deprecated: use RegisterClass instead
516-func (c Class) AddIvar(name string, ty interface{}, types string) bool {
517- typeOf := reflect.TypeOf(ty)
518- size := typeOf.Size()
519- alignment := uint8(math.Log2(float64(typeOf.Align())))
520- return class_addIvar(c, name, size, alignment, types)
521-}
522-
523 // AddProtocol adds a protocol to a class.502 // AddProtocol adds a protocol to a class.
524 // Returns true if the protocol was added successfully, otherwise false (for example,503 // Returns true if the protocol was added successfully, otherwise false (for example,
525 // the class already conforms to that protocol).504 // the class already conforms to that protocol).
@@ -537,14 +516,6 @@ func (c Class) InstanceVariable(name string) Ivar {
537 return class_getInstanceVariable(c, name)516 return class_getInstanceVariable(c, name)
538 }517 }
539 518
540-// Register registers a class that was allocated using AllocateClassPair.
541-// It can now be used to make objects by sending it either alloc and init or new.
542-//
543-// Deprecated: use RegisterClass instead
544-func (c Class) Register() {
545- objc_registerClassPair(c)
546-}
547-
548 // Ivar an opaque type that represents an instance variable.519 // Ivar an opaque type that represents an instance variable.
549 type Ivar uintptr520 type Ivar uintptr
550 521
M objc/objc_runtime_darwin_test.go +92 -37
@@ -12,15 +12,27 @@ import (
1212 "github.com/ebitengine/purego/objc"
1313 )
1414
15-func ExampleAllocateClassPair() {
16- class := objc.AllocateClassPair(objc.GetClass("NSObject"), "FooObject", 0)
17- class.AddMethod(objc.RegisterName("run"), objc.NewIMP(func(self objc.ID, _cmd objc.SEL) {
18- fmt.Println("Hello World!")
19- }), "v@:")
20- class.Register()
21-
22- fooObject := objc.ID(class).Send(objc.RegisterName("new"))
23- fooObject.Send(objc.RegisterName("run"))
15+func ExampleRegisterClass_helloworld() {
16+ class, err := objc.RegisterClass(
17+ "FooObject",
18+ objc.GetClass("NSObject"),
19+ nil,
20+ nil,
21+ []objc.MethodDef{
22+ {
23+ Cmd: objc.RegisterName("run"),
24+ Fn: func(self objc.ID, _cmd objc.SEL) {
25+ fmt.Println("Hello World!")
26+ },
27+ },
28+ },
29+ )
30+ if err != nil {
31+ panic(err)
32+ }
33+
34+ object := objc.ID(class).Send(objc.RegisterName("new"))
35+ object.Send(objc.RegisterName("run"))
2436 // Output: Hello World!
2537 }
2638
@@ -78,26 +90,48 @@ func ExampleIMP() {
7890 })
7991
8092 purego.SyscallN(uintptr(imp), 105, 567, 9, 2, 3, ^uintptr(4), 4, 8, 9)
81-
8293 // Output: IMP: 105 567 9 2 3 -5 4 8 9
8394 }
8495
8596 func ExampleID_SendSuper() {
86- super := objc.AllocateClassPair(objc.GetClass("NSObject"), "SuperObject", 0)
87- super.AddMethod(objc.RegisterName("doSomething"), objc.NewIMP(func(self objc.ID, _cmd objc.SEL) {
88- fmt.Println("In Super!")
89- }), "v@:")
90- super.Register()
91-
92- child := objc.AllocateClassPair(super, "ChildObject", 0)
93- child.AddMethod(objc.RegisterName("doSomething"), objc.NewIMP(func(self objc.ID, _cmd objc.SEL) {
94- fmt.Println("In Child")
95- self.SendSuper(_cmd)
96- }), "v@:")
97- child.Register()
97+ super, err := objc.RegisterClass(
98+ "SuperObject",
99+ objc.GetClass("NSObject"),
100+ nil,
101+ nil,
102+ []objc.MethodDef{
103+ {
104+ Cmd: objc.RegisterName("doSomething"),
105+ Fn: func(self objc.ID, _cmd objc.SEL) {
106+ fmt.Println("In Super!")
107+ },
108+ },
109+ },
110+ )
111+ if err != nil {
112+ panic(err)
113+ }
98114
99- objc.ID(child).Send(objc.RegisterName("new")).Send(objc.RegisterName("doSomething"))
115+ child, err := objc.RegisterClass(
116+ "ChildObject",
117+ super,
118+ nil,
119+ nil,
120+ []objc.MethodDef{
121+ {
122+ Cmd: objc.RegisterName("doSomething"),
123+ Fn: func(self objc.ID, _cmd objc.SEL) {
124+ fmt.Println("In Child")
125+ self.SendSuper(_cmd)
126+ },
127+ },
128+ },
129+ )
130+ if err != nil {
131+ panic(err)
132+ }
100133
134+ objc.ID(child).Send(objc.RegisterName("new")).Send(objc.RegisterName("doSomething"))
101135 // Output: In Child
102136 // In Super!
103137 }
@@ -129,27 +163,48 @@ func ExampleSend() {
129163 subString := objc.ID(class_NSString).Send(sel_stringWithUTF8String, "lo, Wor\x00")
130164
131165 r := objc.Send[NSRange](fullString, objc.RegisterName("rangeOfString:"), subString)
132-
133166 fmt.Println(r)
134-
135167 // Output: {3 7}
136168 }
137169
138170 func ExampleSendSuper() {
139- super := objc.AllocateClassPair(objc.GetClass("NSObject"), "SuperObject2", 0)
140- super.AddMethod(objc.RegisterName("doSomething"), objc.NewIMP(func(self objc.ID, _cmd objc.SEL) int {
141- return 16
142- }), "i@:")
143- super.Register()
144-
145- child := objc.AllocateClassPair(super, "ChildObject2", 0)
146- child.AddMethod(objc.RegisterName("doSomething"), objc.NewIMP(func(self objc.ID, _cmd objc.SEL) int {
147- return 24
148- }), "i@:")
149- child.Register()
171+ super, err := objc.RegisterClass(
172+ "SuperObject2",
173+ objc.GetClass("NSObject"),
174+ nil,
175+ nil,
176+ []objc.MethodDef{
177+ {
178+ Cmd: objc.RegisterName("doSomething"),
179+ Fn: func(self objc.ID, _cmd objc.SEL) int {
180+ return 16
181+ },
182+ },
183+ },
184+ )
185+ if err != nil {
186+ panic(err)
187+ }
150188
151- res := objc.SendSuper[int](objc.ID(child).Send(objc.RegisterName("new")), objc.RegisterName("doSomething"))
189+ child, err := objc.RegisterClass(
190+ "ChildObject2",
191+ super,
192+ nil,
193+ nil,
194+ []objc.MethodDef{
195+ {
196+ Cmd: objc.RegisterName("doSomething"),
197+ Fn: func(self objc.ID, _cmd objc.SEL) int {
198+ return 24
199+ },
200+ },
201+ },
202+ )
203+ if err != nil {
204+ panic(err)
205+ }
152206
207+ res := objc.SendSuper[int](objc.ID(child).Send(objc.RegisterName("new")), objc.RegisterName("doSomething"))
153208 fmt.Println(res)
154209 // Output: 16
155210 }
@@ -12,15 +12,27 @@ import (
12 "github.com/ebitengine/purego/objc"12 "github.com/ebitengine/purego/objc"
13 )13 )
14 14
15-func ExampleAllocateClassPair() {15+func ExampleRegisterClass_helloworld() {
16- class := objc.AllocateClassPair(objc.GetClass("NSObject"), "FooObject", 0)16+ class, err := objc.RegisterClass(
17- class.AddMethod(objc.RegisterName("run"), objc.NewIMP(func(self objc.ID, _cmd objc.SEL) {17+ "FooObject",
18- fmt.Println("Hello World!")18+ objc.GetClass("NSObject"),
19- }), "v@:")19+ nil,
20- class.Register()20+ nil,
21-21+ []objc.MethodDef{
22- fooObject := objc.ID(class).Send(objc.RegisterName("new"))22+ {
23- fooObject.Send(objc.RegisterName("run"))23+ Cmd: objc.RegisterName("run"),
24+ Fn: func(self objc.ID, _cmd objc.SEL) {
25+ fmt.Println("Hello World!")
26+ },
27+ },
28+ },
29+ )
30+ if err != nil {
31+ panic(err)
32+ }
33+
34+ object := objc.ID(class).Send(objc.RegisterName("new"))
35+ object.Send(objc.RegisterName("run"))
24 // Output: Hello World!36 // Output: Hello World!
25 }37 }
26 38
@@ -78,26 +90,48 @@ func ExampleIMP() {
78 })90 })
79 91
80 purego.SyscallN(uintptr(imp), 105, 567, 9, 2, 3, ^uintptr(4), 4, 8, 9)92 purego.SyscallN(uintptr(imp), 105, 567, 9, 2, 3, ^uintptr(4), 4, 8, 9)
81-
82 // Output: IMP: 105 567 9 2 3 -5 4 8 993 // Output: IMP: 105 567 9 2 3 -5 4 8 9
83 }94 }
84 95
85 func ExampleID_SendSuper() {96 func ExampleID_SendSuper() {
86- super := objc.AllocateClassPair(objc.GetClass("NSObject"), "SuperObject", 0)97+ super, err := objc.RegisterClass(
87- super.AddMethod(objc.RegisterName("doSomething"), objc.NewIMP(func(self objc.ID, _cmd objc.SEL) {98+ "SuperObject",
88- fmt.Println("In Super!")99+ objc.GetClass("NSObject"),
89- }), "v@:")100+ nil,
90- super.Register()101+ nil,
91-102+ []objc.MethodDef{
92- child := objc.AllocateClassPair(super, "ChildObject", 0)103+ {
93- child.AddMethod(objc.RegisterName("doSomething"), objc.NewIMP(func(self objc.ID, _cmd objc.SEL) {104+ Cmd: objc.RegisterName("doSomething"),
94- fmt.Println("In Child")105+ Fn: func(self objc.ID, _cmd objc.SEL) {
95- self.SendSuper(_cmd)106+ fmt.Println("In Super!")
96- }), "v@:")107+ },
97- child.Register()108+ },
109+ },
110+ )
111+ if err != nil {
112+ panic(err)
113+ }
98 114
99- objc.ID(child).Send(objc.RegisterName("new")).Send(objc.RegisterName("doSomething"))115+ child, err := objc.RegisterClass(
116+ "ChildObject",
117+ super,
118+ nil,
119+ nil,
120+ []objc.MethodDef{
121+ {
122+ Cmd: objc.RegisterName("doSomething"),
123+ Fn: func(self objc.ID, _cmd objc.SEL) {
124+ fmt.Println("In Child")
125+ self.SendSuper(_cmd)
126+ },
127+ },
128+ },
129+ )
130+ if err != nil {
131+ panic(err)
132+ }
100 133
134+ objc.ID(child).Send(objc.RegisterName("new")).Send(objc.RegisterName("doSomething"))
101 // Output: In Child135 // Output: In Child
102 // In Super!136 // In Super!
103 }137 }
@@ -129,27 +163,48 @@ func ExampleSend() {
129 subString := objc.ID(class_NSString).Send(sel_stringWithUTF8String, "lo, Wor\x00")163 subString := objc.ID(class_NSString).Send(sel_stringWithUTF8String, "lo, Wor\x00")
130 164
131 r := objc.Send[NSRange](fullString, objc.RegisterName("rangeOfString:"), subString)165 r := objc.Send[NSRange](fullString, objc.RegisterName("rangeOfString:"), subString)
132-
133 fmt.Println(r)166 fmt.Println(r)
134-
135 // Output: {3 7}167 // Output: {3 7}
136 }168 }
137 169
138 func ExampleSendSuper() {170 func ExampleSendSuper() {
139- super := objc.AllocateClassPair(objc.GetClass("NSObject"), "SuperObject2", 0)171+ super, err := objc.RegisterClass(
140- super.AddMethod(objc.RegisterName("doSomething"), objc.NewIMP(func(self objc.ID, _cmd objc.SEL) int {172+ "SuperObject2",
141- return 16173+ objc.GetClass("NSObject"),
142- }), "i@:")174+ nil,
143- super.Register()175+ nil,
144-176+ []objc.MethodDef{
145- child := objc.AllocateClassPair(super, "ChildObject2", 0)177+ {
146- child.AddMethod(objc.RegisterName("doSomething"), objc.NewIMP(func(self objc.ID, _cmd objc.SEL) int {178+ Cmd: objc.RegisterName("doSomething"),
147- return 24179+ Fn: func(self objc.ID, _cmd objc.SEL) int {
148- }), "i@:")180+ return 16
149- child.Register()181+ },
182+ },
183+ },
184+ )
185+ if err != nil {
186+ panic(err)
187+ }
150 188
151- res := objc.SendSuper[int](objc.ID(child).Send(objc.RegisterName("new")), objc.RegisterName("doSomething"))189+ child, err := objc.RegisterClass(
190+ "ChildObject2",
191+ super,
192+ nil,
193+ nil,
194+ []objc.MethodDef{
195+ {
196+ Cmd: objc.RegisterName("doSomething"),
197+ Fn: func(self objc.ID, _cmd objc.SEL) int {
198+ return 24
199+ },
200+ },
201+ },
202+ )
203+ if err != nil {
204+ panic(err)
205+ }
152 206
207+ res := objc.SendSuper[int](objc.ID(child).Send(objc.RegisterName("new")), objc.RegisterName("doSomething"))
153 fmt.Println(res)208 fmt.Println(res)
154 // Output: 16209 // Output: 16
155 }210 }

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