Re: Passing param by reference then using within block throws exception
On Sep 22, 2016, at 02:45 PM, "Gary L. Wade" wrote: Look at these two lines: __block NSString* noFillMeIn; ... *noFillMeIn = @"wow"; Unless the original code is correct, you've got mismatched pointers, and you should try turning on more warnings and reading what they say, as well as trying the analyzer. Copy & paste mistake. The quoted syntax won't even compile. Sent from iCloud's ridiculous UI, so, sorry about the formatting ___ 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: Re: Passing param by reference then using within block throws exception
On Sep 22, 2016, at 02:31 PM, Kyle Sluder wrote: Are you able to reproduce this in a sample app? I tried the following but got no crash: I haven't tried. The real method this came from is much more complex than my simplified example; 6 enumerate* loop blocks on dicts and arrays (a couple nested), another parameter before the reference parameter, lots of object allocation. After spending the bulk of my day on tracking down the problem, I don't want to waste more trying to come up with a sample that duplicates it. I'm sure you understand. If ARC can't do the right thing, it should be flagged as something that the user should change. Sent from iCloud's ridiculous UI, so, sorry about the formatting ___ 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: Passing param by reference then using within block throws exception
Look at these two lines: >__block NSString* noFillMeIn; ... > *noFillMeIn = @"wow"; Unless the original code is correct, you've got mismatched pointers, and you should try turning on more warnings and reading what they say, as well as trying the analyzer. -- Gary L. Wade (Sent from my iPhone) http://www.garywade.com/ > On Sep 20, 2016, at 2:06 PM, Steve Mills wrote: > > I'm turning on ARC for a project (yay) and have run into a problem I can't > wrap my head around. It always worked fine before ARC. When I turn zombies > on, doing "memory history 0x610004279ac0" can't find it in the history. > Here's the method and the call to it: > > -(void) doStuff:(NSString**)fillMeIn > { >[array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL* stop) { > if(obj.flag) { > *stop = YES; > *fillMeIn = @"wow"; > } >}]; > } > > NSString* getFilledIn; > > [thing doStuff:&getFilledIn]; > > The call to doStuff: results in EXC_BAD_ACCESS, or "*** -[CFString retain]: > message sent to deallocated instance 0x610004279ac0" if I turn zombies on. > > I tried changing the param type to (NSString** _Nonnull), thinking it was > confused about my knowing that the reference will never be nil, but it didn't > help. Then I got to thinking about the reference being assigned inside the > block and changed it to: > > -(void) doStuff:(NSString** _Nonnull)fillMeIn > { >__block NSString* noFillMeIn; > >[array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL* stop) { > if(obj.flag) { > *stop = YES; > *noFillMeIn = @"wow"; > } >}]; > >*fillMeIn = noFillMeIn; > } > > That seems to fix it. Is there a better way to deref and assign to the param > from within the block? > > Sent from iCloud's ridiculous UI, so, sorry about the formatting ___ 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: Re: Passing param by reference then using within block throws exception
On Wed, Sep 21, 2016, at 09:22 AM, Steve Mills wrote: > On Sep 21, 2016, at 08:53 AM, Alex Zavatone wrote: > > Stab in the dark here, but I'm stabbing blank. Is there an Instruments > tool or debugging option to detect this? > > Thanks for getting stabby. Fourvel appreciates it (only relevant if > you're a CBB fan). It doesn't appear that anything will detect this. When > zombies is on, it says an address is attempting to be retained but was > previously released. That's a bit of a red herring, since the only 2 > variables being uses have just been declared and initialized right before > the call to the method. If anything, the process of converting to ARC or > the static analyzer should've flagged this as a problem. Are you able to reproduce this in a sample app? I tried the following but got no crash: #include #import static void foo(NSString **fillMeIn) { [@[@"a"] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { *fillMeIn = obj; *stop = YES; }]; } int main(int argc, char **argv) { @autoreleasepool { NSString *out; foo(&out); printf("%s", out.UTF8String); } return 0; } --Kyle ___ 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: Passing param by reference then using within block throws exception
On Sep 21, 2016, at 08:53 AM, Alex Zavatone wrote: Stab in the dark here, but I'm stabbing blank. Is there an Instruments tool or debugging option to detect this? Thanks for getting stabby. Fourvel appreciates it (only relevant if you're a CBB fan). It doesn't appear that anything will detect this. When zombies is on, it says an address is attempting to be retained but was previously released. That's a bit of a red herring, since the only 2 variables being uses have just been declared and initialized right before the call to the method. If anything, the process of converting to ARC or the static analyzer should've flagged this as a problem. Sent from iCloud's ridiculous UI, so, sorry about the formatting ___ 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: Passing param by reference then using within block throws exception
Stab in the dark here, but I'm stabbing blank. Is there an Instruments tool or debugging option to detect this? On Sep 21, 2016, at 7:53 AM, Steve Mills wrote: > On Sep 21, 2016, at 01:29:37, Jens Alfke wrote: >> >> I think the real problem is that the -enumerateObjectsUsingBlock: method has >> an autorelease pool. If your real code is assigning something other than a >> string constant to *fillMeIn, that string will probably get dealloced when >> the autorelease pool drains. Your workaround is correct, since assigning the >> string to noFillMeIn causes it to be retained. > > Perhaps, but that couldn't be the cause of the crash. I might not have been > totally clear, but the crash happens while setting up to call the method, not > inside the method or after it returns. > > -- > Steve Mills > Drummer, Mac geek > > > ___ > > 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/zav%40mac.com > > This email sent to z...@mac.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: Passing param by reference then using within block throws exception
On Sep 21, 2016, at 01:29:37, Jens Alfke wrote: > > I think the real problem is that the -enumerateObjectsUsingBlock: method has > an autorelease pool. If your real code is assigning something other than a > string constant to *fillMeIn, that string will probably get dealloced when > the autorelease pool drains. Your workaround is correct, since assigning the > string to noFillMeIn causes it to be retained. Perhaps, but that couldn't be the cause of the crash. I might not have been totally clear, but the crash happens while setting up to call the method, not inside the method or after it returns. -- Steve Mills Drummer, Mac geek ___ 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: Passing param by reference then using within block throws exception
I think the real problem is that the -enumerateObjectsUsingBlock: method has an autorelease pool. If your real code is assigning something other than a string constant to *fillMeIn, that string will probably get dealloced when the autorelease pool drains. Your workaround is correct, since assigning the string to noFillMeIn causes it to be retained. —Jens ___ 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: Passing param by reference then using within block throws exception
I think this is the exact solution. As I'm sure you've tried, you can't use the __block modifier on method parameters, as you will get the following compiler error: __block attribute not allowed, only allowed on local variables So, you're doing the right thing creating the local as a temporary to eventually assign to the method parameter. Doug Hill > On Sep 20, 2016, at 2:06 PM, Steve Mills wrote: > > I'm turning on ARC for a project (yay) and have run into a problem I can't > wrap my head around. It always worked fine before ARC. When I turn zombies > on, doing "memory history 0x610004279ac0" can't find it in the history. > Here's the method and the call to it: > > -(void) doStuff:(NSString**)fillMeIn > { >[array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL* stop) { > if(obj.flag) { > *stop = YES; > *fillMeIn = @"wow"; > } >}]; > } > > NSString* getFilledIn; > > [thing doStuff:&getFilledIn]; > > The call to doStuff: results in EXC_BAD_ACCESS, or "*** -[CFString retain]: > message sent to deallocated instance 0x610004279ac0" if I turn zombies on. > > I tried changing the param type to (NSString** _Nonnull), thinking it was > confused about my knowing that the reference will never be nil, but it didn't > help. Then I got to thinking about the reference being assigned inside the > block and changed it to: > > -(void) doStuff:(NSString** _Nonnull)fillMeIn > { >__block NSString* noFillMeIn; > >[array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL* stop) { > if(obj.flag) { > *stop = YES; > *noFillMeIn = @"wow"; > } >}]; > >*fillMeIn = noFillMeIn; > } > > That seems to fix it. Is there a better way to deref and assign to the param > from within the block? ___ 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