Skip to content

Commit

Permalink
objc: add support for NSKVONotifying_ subclasses. closes #104
Browse files Browse the repository at this point in the history
  • Loading branch information
progrium committed Mar 12, 2023
1 parent 737d9c1 commit f94fcc8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions objc/call_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import "C"
import (
"math"
"reflect"
"strings"
"unsafe"
)

Expand Down Expand Up @@ -142,7 +143,17 @@ func goMethodCallEntryPoint(p uintptr) uintptr {
sel := stringFromSelector(unsafe.Pointer(fetcher.Int()))

clsName := object{ptr: getObjectClass(obj).Pointer()}.className()
// Sometimes newer versions of macOS dynamically create a "NSKVONotifying_"
// prefixed subclass, which we won't have registered in classMap. However,
// since it's a subclass, we can probably get away with looking up the class
// that was inherited from based on the name part after the prefix.
if strings.HasPrefix(clsName, "NSKVONotifying_") {
clsName = strings.Replace(clsName, "NSKVONotifying_", "", 1)
}
clsInfo := classMap[clsName]
if clsInfo.typ == nil {
panic("unable to find registered class: " + clsName)
}
method := clsInfo.MethodForSelector(sel)

// Check if we have an internal pointer set for this object.
Expand Down
10 changes: 10 additions & 0 deletions objc/call_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,17 @@ func goMethodCallEntryPoint(p uintptr) uintptr {
sel := stringFromSelector(unsafe.Pointer(fetcher.Int()))

clsName := object{ptr: getObjectClass(obj).Pointer()}.className()
// Sometimes newer versions of macOS dynamically create a "NSKVONotifying_"
// prefixed subclass, which we won't have registered in classMap. However,
// since it's a subclass, we can probably get away with looking up the class
// that was inherited from based on the name part after the prefix.
if strings.HasPrefix(clsName, "NSKVONotifying_") {
clsName = strings.Replace(clsName, "NSKVONotifying_", "", 1)
}
clsInfo := classMap[clsName]
if clsInfo.typ == nil {
panic("unable to find registered class: " + clsName)
}
method := clsInfo.MethodForSelector(sel)

// Check if we have an internal pointer set for this object.
Expand Down

0 comments on commit f94fcc8

Please sign in to comment.