Re: when __bridge isn't required
On Jul 27, 2013, at 2:05 PM, Zac Bowling z...@zacbowling.com wrote: The first one is a NSConstantString string. It's not like a malloc'd NSString. It's effectively a singleton. It doesn't mater how it's bridged because it can't be released. The second is a new NSURL that is allocated on the heap. It needs to be released so it needs to be bridged correctly to handle things properly. CFStringGetIntValue() is passed an NSString * variable (casted to a CFStringRef). The fact that a constant string was assigned to it earlier is neither here nor there. As far as that function knows, that variable could contain an NSConstantString, an NSMutableString, an NSCFString, an NSPathStore2, or any other subclass of NSString. For the record, I tried his example, assigning an NSMutableString to the answer variable and got the same result. On Jul 27, 2013, at 2:16 PM, Matt Neuburg m...@tidbits.com wrote: Argh. Okay, I'll ask this on devforums when it comes back up, in case it depends on, uh, the thing I'm using that I can't talk about. m. I seem to be able to reproduce it in 4.6.3, so it's not solely dependent on The IDE Who Must Not Be Named. Charles ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
when __bridge isn't required
I feel like I've asked this before, but I don't feel I'm grasping the answer. Why don't these work the same way under ARC: NSString* answer = @42; int ans = CFStringGetIntValue((CFStringRef)answer); and NSURL* imageSource = [NSURL new]; CGImageSourceRef src = CGImageSourceCreateWithURL((CFURLRef)imageSource, nil); The first one compiles (with no explicit __bridge). The second one doesn't; you must say __bridge explicitly. But why? They look completely parallel to me. The mystery is compounded by the fact that if you omit the cast entirely in the first example, the compiler claims that you need a bridged cast. But you don't; you just need a cast. That feels like a bug; if a mere cast is sufficient, the compiler should say so (and Fix-It should offer it as a possible fix). m. -- matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/ pantes anthropoi tou eidenai oregontai phusei Programming iOS 6! http://shop.oreilly.com/product/0636920029717.do RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html TidBITS, Mac news and reviews since 1990, http://www.tidbits.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: when __bridge isn't required
My take: __bridge means 'do not transfer the retain count of whatever on the RHS to the LHS'. If the RHS involves some kind of create or new, then you'll get a leak since ARC won't release it. __bridge_transfer means 'transfer the retain count of whatever on the RHS to the LHS'. If the RHS involves some kind of create or new, then you can just rely on ARC, or you'll have to release via CFRelease(). Since CFStringGetIntValue() does not return an object, you don't need __bridge at all - there's no 'retaining' going on behind the scenes. ARC sees you're getting back a scalar, and the compiler sees no ambiguity or error. But CGImageSourceCreateWithURL() includes the keyword 'create' - so the object you get back has a retain count of 1. ARC will insist that you cast with __bridge or __bridge_transfer. Under ARC, you have to let the compiler know whether you are taking responsibility (__bridge_transfer, ARC will release when it goes out of scope), or not (__bridge, followed by a CFRelease()) for ultimately releasing the newly created object. I'm probably wrong, but this is how I've been working with ARC, based on the docs and blogs. Rob On Jul 27, 2013, at 2:31 PM, Matt Neuburg m...@tidbits.com wrote: I feel like I've asked this before, but I don't feel I'm grasping the answer. Why don't these work the same way under ARC: NSString* answer = @42; int ans = CFStringGetIntValue((CFStringRef)answer); and NSURL* imageSource = [NSURL new]; CGImageSourceRef src = CGImageSourceCreateWithURL((CFURLRef)imageSource, nil); The first one compiles (with no explicit __bridge). The second one doesn't; you must say __bridge explicitly. But why? They look completely parallel to me. The mystery is compounded by the fact that if you omit the cast entirely in the first example, the compiler claims that you need a bridged cast. But you don't; you just need a cast. That feels like a bug; if a mere cast is sufficient, the compiler should say so (and Fix-It should offer it as a possible fix). m. -- matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/ pantes anthropoi tou eidenai oregontai phusei Programming iOS 6! http://shop.oreilly.com/product/0636920029717.do RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html TidBITS, Mac news and reviews since 1990, http://www.tidbits.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/robmartin%40frontiernet.net This email sent to robmar...@frontiernet.net ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: when __bridge isn't required
The first gives me the following error: Implicit conversion of Objective-C pointer type 'NSString *' to C pointer type 'CFStringRef' (aka 'const struct __CFString *') requires a bridged cast Tom Davie On Jul 27, 2013, at 8:31 PM, Matt Neuburg m...@tidbits.com wrote: I feel like I've asked this before, but I don't feel I'm grasping the answer. Why don't these work the same way under ARC: NSString* answer = @42; int ans = CFStringGetIntValue((CFStringRef)answer); and NSURL* imageSource = [NSURL new]; CGImageSourceRef src = CGImageSourceCreateWithURL((CFURLRef)imageSource, nil); The first one compiles (with no explicit __bridge). The second one doesn't; you must say __bridge explicitly. But why? They look completely parallel to me. The mystery is compounded by the fact that if you omit the cast entirely in the first example, the compiler claims that you need a bridged cast. But you don't; you just need a cast. That feels like a bug; if a mere cast is sufficient, the compiler should say so (and Fix-It should offer it as a possible fix). m. -- matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/ pantes anthropoi tou eidenai oregontai phusei Programming iOS 6! http://shop.oreilly.com/product/0636920029717.do RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html TidBITS, Mac news and reviews since 1990, http://www.tidbits.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/tom.davie%40gmail.com This email sent to tom.da...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: when __bridge isn't required
The first one is a NSConstantString string. It's not like a malloc'd NSString. It's effectively a singleton. It doesn't mater how it's bridged because it can't be released. The second is a new NSURL that is allocated on the heap. It needs to be released so it needs to be bridged correctly to handle things properly. Apple has made this more and more friendly since the WWDC beta of ARC over time with things like flags for constants from system headers and other basically constant things so don't have to bridge as much. Things like #pragma clang system_header and system_prefix in clang. Zac On Jul 27, 2013, at 11:31 AM, Matt Neuburg m...@tidbits.com wrote: I feel like I've asked this before, but I don't feel I'm grasping the answer. Why don't these work the same way under ARC: NSString* answer = @42; int ans = CFStringGetIntValue((CFStringRef)answer); and NSURL* imageSource = [NSURL new]; CGImageSourceRef src = CGImageSourceCreateWithURL((CFURLRef)imageSource, nil); The first one compiles (with no explicit __bridge). The second one doesn't; you must say __bridge explicitly. But why? They look completely parallel to me. The mystery is compounded by the fact that if you omit the cast entirely in the first example, the compiler claims that you need a bridged cast. But you don't; you just need a cast. That feels like a bug; if a mere cast is sufficient, the compiler should say so (and Fix-It should offer it as a possible fix). m. -- matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/ pantes anthropoi tou eidenai oregontai phusei Programming iOS 6! http://shop.oreilly.com/product/0636920029717.do RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html TidBITS, Mac news and reviews since 1990, http://www.tidbits.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/zac%40zacbowling.com This email sent to z...@zacbowling.com smime.p7s Description: S/MIME cryptographic signature ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: when __bridge isn't required
On Jul 27, 2013, at 11:54 , Robert Martin robmar...@frontiernet.net wrote: But CGImageSourceCreateWithURL() includes the keyword 'create' - so the object you get back has a retain count of 1. ARC will insist that you cast with __bridge or __bridge_transfer. ARC isn't involved with the return value in either case. In the first one, it's a scalar, as you noted. In the second, it's a core foundation object, which isn't managed by ARC … … unless the CGImageSourceCreateWithURL is marked (in the SDK) with the attribute that that says it can be managed by ARC (a fairly recent addition to Clang) … … but that wouldn't be it anyway, since there's no cast needed on the return value, let alone a __bridge. On Jul 27, 2013, at 11:31 , Matt Neuburg m...@tidbits.com wrote: The first one compiles (with no explicit __bridge). The second one doesn't; you must say __bridge explicitly. I tried both your examples in Xcode 4.6.3 and OS X 10.8 SDK, and neither produced an error or a warning. The answer to your question probably depends on: -- the version of Clang you're using -- the particular SDK you're using -- the compiler options you're using ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: when __bridge isn't required
Argh. Okay, I'll ask this on devforums when it comes back up, in case it depends on, uh, the thing I'm using that I can't talk about. m. On Jul 27, 2013, at 12:10 PM, Quincey Morris quinceymor...@rivergatesoftware.com wrote: I tried both your examples in Xcode 4.6.3 and OS X 10.8 SDK, and neither produced an error or a warning. The answer to your question probably depends on: -- the version of Clang you're using -- the particular SDK you're using -- the compiler options you're using -- matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/ pantes anthropoi tou eidenai oregontai phusei Programming iOS 6! http://shop.oreilly.com/product/0636920029717.do RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html TidBITS, Mac news and reviews since 1990, http://www.tidbits.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com