aboutsummaryrefslogtreecommitdiffstats
path: root/notifier_darwin.go
diff options
context:
space:
mode:
authorTeddy Wing2020-03-11 00:00:22 +0100
committerTeddy Wing2020-03-11 00:44:31 +0100
commit5e1b28caa8d81dee0e9ac7b29fe5621259e15e50 (patch)
tree3e926ef822feaba5232ef6cd5c4752da209d0f1a /notifier_darwin.go
parent428fb6dcab1377dd887d65eb2a496f6d5bbe1b6c (diff)
downloadgo-notifier-update-to-build-against-go1.14.tar.bz2
Correct macOS >= 10.13, Go >= 1.10 CoreFoundation pointer type errorsupdate-to-build-against-go1.14
When building the project on macOS 10.15 with Go 1.13, I ended up with the following errors: # github.com/keybase/go-notifier ./corefoundation.go:25:9: cannot convert nil to type _Ctype_CFTypeRef ./corefoundation.go:34:3: cannot use nil as type _Ctype_CFDataRef in return argument ./corefoundation.go:40:26: cannot use nil as type _Ctype_CFAllocatorRef in argument to _Cfunc_CFDataCreate ./corefoundation.go:41:12: cannot convert nil to type _Ctype_CFDataRef ./corefoundation.go:42:3: cannot use nil as type _Ctype_CFDataRef in return argument ./corefoundation.go:66:47: cannot use nil as type _Ctype_CFAllocatorRef in assignment ./corefoundation.go:67:12: cannot convert nil to type _Ctype_CFDictionaryRef ./corefoundation.go:68:3: cannot use nil as type _Ctype_CFDictionaryRef in return argument ./corefoundation.go:79:59: cannot convert &(*_cgoIndex1)[0] (type *_Ctype_CFTypeRef) to type *unsafe.Pointer ./corefoundation.go:79:88: cannot convert &(*_cgoIndex2)[0] (type *_Ctype_CFTypeRef) to type *unsafe.Pointer ./corefoundation.go:92:3: cannot use nil as type _Ctype_CFStringRef in return argument ./corefoundation.go:95:3: cannot use nil as type _Ctype_CFStringRef in return argument ./corefoundation.go:103:34: cannot use nil as type _Ctype_CFAllocatorRef in argument to _Cfunc_CFStringCreateWithBytes ./corefoundation.go:138:39: cannot use nil as type _Ctype_CFAllocatorRef in assignment ./corefoundation.go:146:69: cannot convert &(*_cgoIndex2)[0] (type *_Ctype_CFTypeRef) to type *unsafe.Pointer ./corefoundation.go:157:4: cannot use nil as type _Ctype_CFArrayRef in return argument ./corefoundation.go:178:4: cannot use nil as type _Ctype_CFDictionaryRef in return argument ./corefoundation.go:190:5: cannot use nil as type _Ctype_CFDictionaryRef in return argument ./corefoundation.go:197:5: cannot use nil as type _Ctype_CFDictionaryRef in return argument ./corefoundation.go:204:5: cannot use nil as type _Ctype_CFDictionaryRef in return argument ./corefoundation.go:211:4: cannot use nil as type _Ctype_CFDictionaryRef in return argument ./corefoundation.go:218:3: cannot use nil as type _Ctype_CFDictionaryRef in return argument ./notifier_darwin.go:57:38: cannot use nil as type _Ctype_CFStringRef in assignment ./notifier_darwin.go:58:3: cannot use nil as type _Ctype_CFStringRef in assignment Found similar errors reported on the 'fsevents' project: https://github.com/fsnotify/fsevents/issues/33 , https://github.com/golang/go/issues/23317 It turns out that Cgo handles CoreFoundation types differently starting in Go 1.10: > Cgo now translates some C types that would normally map to a pointer > type in Go, to a uintptr instead. These types include the CFTypeRef > hierarchy in Darwin's CoreFoundation framework and the jobject > hierarchy in Java's JNI interface. > > These types must be uintptr on the Go side because they would > otherwise confuse the Go garbage collector; they are sometimes not > really pointers but data structures encoded in a pointer-sized > integer. Pointers to Go memory must not be stored in these uintptr > values. > > Because of this change, values of the affected types need to be > zero-initialized with the constant 0 instead of the constant nil. https://tip.golang.org/doc/go1.10#cgo For the "cannot convert" errors, use xlab's (https://github.com/xlab) suggestion: > The workaround is to pass it as ptr := > (*unsafe.Pointer)(unsafe.Pointer(arg)) which looks strange but works. https://github.com/golang/go/issues/13830#issuecomment-169139332
Diffstat (limited to 'notifier_darwin.go')
-rw-r--r--notifier_darwin.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/notifier_darwin.go b/notifier_darwin.go
index e6f9c07..45d61f0 100644
--- a/notifier_darwin.go
+++ b/notifier_darwin.go
@@ -54,8 +54,8 @@ func (n darwinNotifier) DeliverNotification(notification Notification) error {
actionsRef := StringsToCFArray(notification.Actions)
defer Release(C.CFTypeRef(actionsRef))
- C.deliverNotification(titleRef, nil, messageRef, appIconURLStringRef, actionsRef,
- bundleIDRef, nil, C.NSTimeInterval(notification.Timeout), false)
+ C.deliverNotification(titleRef, 0, messageRef, appIconURLStringRef, actionsRef,
+ bundleIDRef, 0, C.NSTimeInterval(notification.Timeout), false)
return nil
}