-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cannot use nil for CFType (Go 1.10+)
fixes #40 Cannot use nil for CFType (Go 1.10+), round 2 reducing code changes between Go versions conversions can occur in older Go versions too extract eventIDSinceNow constant to other files Go-version specific files. reworks #34 which resolves int overflow #31 minimize code differences between Go versions Work around bizarre bugs in 1.10.3 (not 1.10.4) golang/go#24161 use C.kCFAllocatorDefault instead of C.CFAllocatorRef(0) thanks to @havoc-io for the tip reduce duplication between go 1.10 before/after thanks to C.kCFAllocatorDefault change
- Loading branch information
Showing
8 changed files
with
102 additions
and
296 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// +build darwin,go1.10 | ||
|
||
package fsevents | ||
|
||
/* | ||
#include <CoreServices/CoreServices.h> | ||
*/ | ||
import "C" | ||
|
||
const ( | ||
nullCFStringRef = C.CFStringRef(0) | ||
nullCFUUIDRef = C.CFUUIDRef(0) | ||
) | ||
|
||
// NOTE: The following code is identical between go_1_10_after and go_1_10_before, | ||
// however versions of Go 1.10.x prior to 1.10.4 fail to compile when the code utilizing | ||
// the above constants is in a different file (wrap.go). | ||
|
||
// GetDeviceUUID retrieves the UUID required to identify an EventID | ||
// in the FSEvents database | ||
func GetDeviceUUID(deviceID int32) string { | ||
uuid := C.FSEventsCopyUUIDForDevice(C.dev_t(deviceID)) | ||
if uuid == nullCFUUIDRef { | ||
return "" | ||
} | ||
return cfStringToGoString(C.CFUUIDCreateString(C.kCFAllocatorDefault, uuid)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// +build darwin,!go1.10 | ||
|
||
package fsevents | ||
|
||
/* | ||
#include <CoreServices/CoreServices.h> | ||
*/ | ||
import "C" | ||
|
||
var ( | ||
nullCFStringRef = C.CFStringRef(nil) | ||
nullCFUUIDRef = C.CFUUIDRef(nil) | ||
) | ||
|
||
// NOTE: The following code is identical between go_1_10_after and go_1_10_before. | ||
|
||
// GetDeviceUUID retrieves the UUID required to identify an EventID | ||
// in the FSEvents database | ||
func GetDeviceUUID(deviceID int32) string { | ||
uuid := C.FSEventsCopyUUIDForDevice(C.dev_t(deviceID)) | ||
if uuid == nullCFUUIDRef { | ||
return "" | ||
} | ||
return cfStringToGoString(C.CFUUIDCreateString(C.kCFAllocatorDefault, uuid)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// +build darwin,go1.9.2 | ||
|
||
package fsevents | ||
|
||
/* | ||
#include <CoreServices/CoreServices.h> | ||
*/ | ||
import "C" | ||
|
||
// eventIDSinceNow is a sentinel to begin watching events "since now". | ||
const eventIDSinceNow = uint64(C.kFSEventStreamEventIdSinceNow) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// +build darwin,!go1.9.2 | ||
|
||
package fsevents | ||
|
||
// Prior to Go 1.9.2, converting C.kFSEventStreamEventIdSinceNow to a uint64 | ||
// results in the error: "constant -1 overflows uint64". | ||
// Related Go issue: https://github.com/golang/go/issues/21708 | ||
|
||
// Hardcoding the value here from FSEvents.h: | ||
// kFSEventStreamEventIdSinceNow = 0xFFFFFFFFFFFFFFFFULL | ||
|
||
// eventIDSinceNow is a sentinel to begin watching events "since now". | ||
const eventIDSinceNow = uint64(0xFFFFFFFFFFFFFFFF) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.