[cfe-dev] __weak_capture implementation cleanup
Remy Demarest
remy.demarest at gmail.com
Sat Jan 7 20:30:29 PST 2012
Hello everyone,
I'm still trying to build my __weak_capture, the original implementation "worked" but I want to improve it, especially to be able to __weak_capture __weak variables.
For those who don't know what it is, __weak_capture allow you to capture in a block a locally declared ObjC object variable from the parent scope. The block structure would capture that variable as if it was __weak. When the block is executed, the object is retained as if it was stored into a __strong variable in the scope of the block, which means that a nested block would capture a __strong and not whatever the variable as been declared as before.
I've came to the conclusion that, to keep the implementation simple, I had to shadow the __weak_captured variables with a local declaration with the same type but different qualifiers.
As an example, with this code:
__autoreleasing id obj = someValue;
^{
__weak_capture(obj);
if(obj == nil) return;
}
With the __weak_capture, the "obj" variable in the if would be defined as "const __strong id obj", const coming from the normal block capture, and the __strong coming from the __weak_capture. However, I'm not sure how to build that VarDecl so that other parts of the program can find it.
Can anyone tell me where I should start looking in order to define a proper local declaration in the block ?
____________________________________
Remy "Psy" Demarest
remy.demarest at gmail.com
+1 (647) 862-1779
More information about the cfe-dev
mailing list