Say we want to create our own CFRetain
and CFRelease
functions, called MyRetain
and MyRelease
. For the latter, we can just write:
void MyRelease(CFTypeRef __attribute__((cf_consumed)) typeRef);
// or
void MyRelease(CFTypeRef CF_RELEASES_ARGUMENT typeRef);
However, for MyRetain
it seems we're out of luck. I would have suspected something like this to exist:
void MyRetain(CFTypeRef __attribute__((cf_retained)) typeRef);
// or
void MyRetain(CFTypeRef CF_RETAINS_ARGUMENT typeRef);
Is this simply an omission? Is there maybe an alternative I'm not seeing?
You most likely want to use
__attribute__((cf_returns_retained))
, which is often#define
’d asCF_RETURNS_RETAINED
.From the relevant lines in the CoreFoundation source:
… that file, CFBase.h, is worth perusing – it contains many of the more obscure CF-specific
#define
andtypedef
definitions.