how to access kCFRunLoopDefaultMode
Posted: Mon May 11, 2015 4:01 pm
I'm trying to do some fsevents work on the mac, and it's not working with me.
As soon as a file system event arrives, it takes a dump.
Below is stripped down version of my code trying to implement this
Assuming this code is in the notorious foo.pb, i run the following
In http://www.opensource.apple.com/source/ ... nLoop.h:68 is the following declaration
I have a working C sample for this, but it's using the original kCFRunLoopDefaultMode instead of my homegrown one.
Is there a way to access the original one?
When i did a home grown kCFRunLoopDefaultMode in the C sample, it failed to get events, but didn't crash.
Any other things, that stick out as sinfully wrong here?
I've been banging my head against this for 2 days now
As soon as a file system event arrives, it takes a dump.
Below is stripped down version of my code trying to implement this
Code: Select all
EnableExplicit
ImportC "-framework CoreServices"
CFStringCreateWithCharacters.i (*alloc, *bytes, numChars.i)
CFArrayCreate.i(*allocator, *values, numValues.i, *callBacks)
FSEventStreamCreate(*allocator, *callback, *context, *pathsToWatch, sinceWhen.q, latency.d, flags.l)
FSEventStreamScheduleWithRunLoop(*streamRef, *runLoop, *runLoopMode)
FSEventStreamStart(*streamRef)
CFRunLoopRun()
CFRunLoopGetCurrent.i()
FSEventStreamInvalidate(*streamRef)
FSEventStreamRelease(*streamRef)
EndImport
#kCFStringEncodingMacRoman = 0
#kFSEventStreamCreateFlagNone = $00000000
#kFSEventStreamEventIdSinceNow = $FFFFFFFFFFFFFFFF
Global kCFRunLoopDefaultModeStr.s = "kCFRunLoopDefaultMode"
Global kCFRunLoopDefaultMode.i = CFStringCreateWithCharacters(#Null,
@kCFRunLoopDefaultModeStr, Len(kCFRunLoopDefaultModeStr))
Procedure callback(*stream, *ctx, numEvents.i, *eventPaths, *eventFlags_l, *eventIds_q)
PrintN("callback")
EndProcedure
Procedure main(filePath.s)
PrintN("Watching " + filePath)
Protected *strRef = CFStringCreateWithCharacters(#Null, @filePath,
Len(filePath))
Protected *pathsToWatch = CFArrayCreate(#Null, @*strRef, 1, #Null)
Protected latency.d = 1.0 ; Latency in seconds
Protected *stream = FSEventStreamCreate(#Null, @callback(), #Null, *pathsToWatch,
#kFSEventStreamEventIdSinceNow, latency,
#kFSEventStreamCreateFlagNone)
FSEventStreamScheduleWithRunLoop(*stream, CFRunLoopGetCurrent(),
kCFRunLoopDefaultMode)
FSEventStreamStart(*stream)
PrintN("entering CFRunLoop");
CFRunLoopRun()
PrintN("exited CFRunLoop");
FSEventStreamInvalidate (*stream)
FSEventStreamRelease (*stream)
EndProcedure
main("/")
Code: Select all
$ pbcompiler -ds -c -u -t -e foo foo.pb && lldb foo
******************************************
PureBasic 5.24 LTS (MacOS X - x86)
******************************************
Loading external modules...
Starting compilation...
47 lines processed.
Creating the executable.
- Feel the ..PuRe.. Power -
Current executable set to 'foo' (i386).
(lldb) r
Process 65891 launched: '/Users/regify/src/apps/regibox/foo' (i386)
Watching /
entering CFRunLoop
callback
Process 65891 stopped
* thread #1: tid = 0x104cea, 0x00000001, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x1)
frame #0: 0x00000001
error: memory read failed for 0x0
(lldb) bt all
* thread #1: tid = 0x104cea, 0x00000001, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x1)
* frame #0: 0x00000001
thread #2: tid = 0x104d00, 0x90928992 libsystem_kernel.dylib`kevent64 + 10, queue = 'com.apple.libdispatch-manager'
frame #0: 0x90928992 libsystem_kernel.dylib`kevent64 + 10
frame #1: 0x984d9899 libdispatch.dylib`_dispatch_mgr_invoke + 238
frame #2: 0x984d9532 libdispatch.dylib`_dispatch_mgr_thread + 52
Code: Select all
CF_EXPORT const CFStringRef kCFRunLoopDefaultMode;
Is there a way to access the original one?
When i did a home grown kCFRunLoopDefaultMode in the C sample, it failed to get events, but didn't crash.
Any other things, that stick out as sinfully wrong here?
I've been banging my head against this for 2 days now
