January 2012
1 post
YOU MUST EXEC, a Core Foundation fork safety tale
Mike Ash has recently published a post about fork safety. This promptly reminded me of an error message that I, like possibly other developers jumping from Unix into Cocoa, stumbled upon when trying to use fork() in Mac OS X:
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on...
December 2011
1 post
3 tags
Testing closures (aka Blocks) for equality
(In which @bbum slaps me around a bit with a large trout. Or a leg of lamb.)
A couple of days ago, @kongtomorrow asked on Twitter whether there were a function to test the equality of two closures:
Is there a func like Block_equals such that Block_equals(block, Block_copy(block)) is true? I could have sworn Block_equals existed…
There doesn’t seem to exist such a function in either...
October 2011
1 post
CFLite, Core Foundation’s little cousin
Apple Open Source is the Web site where Apple publish releases of part of the software that’s bundled in Mac OS X, iOS and the developer tools. One of the available open source components is CFLite, a subset of Core Foundation. In this post, I describe how I’ve built CFLite on Mac OS X and implemented a minor optimisation.
Obtaining CFLite
Mac OS X open source releases are grouped into OS...
September 2011
1 post
1 tag
Would you please crash my out of scope stack...
Programmers who’ve used Apple/Objective-C closures are probably aware that a literal closure should be copied from the stack to the heap via Block_copy() or -copy if it is to be used outside its enclosing block. The documentation says so, Bill Bumgarner has a post explaining it, and dispatch/queue.h even has a warning for this:
// The declaration of a block allocates storage on the stack.
//...
August 2011
1 post
1 tag
A CHOCKING MYSTERY: po [NSNumber...
Craig Hockenberry posted this on Twitter:
(gdb) po [NSNumber numberWithBool:NO]
1
Does not inspire confidence…
Jens Ayton cleverly noted that NO is a macro, so where would GDB be getting a value from?
A few comments ensued, including speculations about tagged pointers, until Cédric Luthi mentioned how to correctly handle it:
That’s unfortunate but Foundation exports YES and...
July 2011
1 post
1 tag
Tagged pointers and fast-pathed CFNumber integers...
Tagged pointers are a new feature in Lion and the OS X v10.7 SDK. They provide an alternative representation of objects based on the fact that not every integer can represent the memory address of an arbitrary Objective-C object since allocators return 16-byte aligned addresses.
In Lion, the Objective-C runtime and Core Foundation tag pointers as follows:
Every tagged pointer has its lowest...
February 2011
1 post
1 tag
Name spaces in Objective-C
One thing that might not be immediately clear for newcomers to Objective-C is the name spaces for the varying Objective-C constructs. For instance, is it possible for a class to have the same name as a protocol?
Let’s start by enumerating some of the elements that can be named:
C types
C variables
C functions
C structure members
Objective-C classes
Objective-C class methods
Objective-C...