NSInvocation crashes in AutoreleasePool
NSInvocation crashes in AutoreleasePool
- Subject: NSInvocation crashes in AutoreleasePool
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Tue, 21 Oct 2014 16:44:19 +0700
10.10, Xcode 6.1, using Arc.
The following code works fine, with USE_INVOCATION defined or not:
#define USE_INVOCATION (or commented out)
- (NSSet *)doSomethingWith: (NSArray *)listOfActions onSet: (NSSet *)originSet
{
NSSet *inputSet = originSet;
for( NSString *curSelectorName in listOfActions )
{
SEL theSelector = NSSelectorFromString( curSelectorName );
#ifdef USE_INVOCATION
NSMethodSignature *signature = [ [self class] instanceMethodSignatureForSelector: theSelector ];
NSInvocation *iv = [ NSInvocation invocationWithMethodSignature: signature ];
iv.target = self;
iv.selector = theSelector;
#endif // USE_INVOCATION
NSMutableSet *outputSet = [ NSMutableSet set ];
for( NSDictionary *dict in inputSet )
{
#ifdef USE_INVOCATION
[ iv setArgument: (void *)&dict atIndex: 2 ]; // ← any bridging to be done?
[ iv invoke ];
NSDictionary *new;
[ iv getReturnValue: &new ]; // ← any bridging to be done?
#else // use performSelector
NSDictionary *new = [ self performSelector: theSelector withObject: dict ];
#endif // USE_INVOCATION
[ outputSet addObject: new ];
};
inputSet = outputSet;
};
return inputSet;
}
Without USE_INVOCATION defined, I get some compiler warning about potential leaks, because selector is unknown.
But with USE_INVOCATION defined, it will crash later (when all has been done), obviously while cleaning an AutoreleasePool:
(lldb) bt
* thread #1: tid = 0x145595, 0x00007fff8a090acf libobjc.A.dylib`objc_release + 15, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
frame #0: 0x00007fff8a090acf libobjc.A.dylib`objc_release + 15
frame #1: 0x00007fff8a08f91f libobjc.A.dylib`(anonymous namespace)::AutoreleasePoolPage::pop(void*) + 575
frame #2: 0x00007fff8e0301f9 CFNetwork`-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 240
frame #3: 0x00007fff8e030396 CFNetwork`-[NSURLConnectionInternal _withConnectionAndDelegate:] + 45
frame #4: 0x00007fff8e016acb CFNetwork`_NSURLConnectionDidFail(_CFURLConnection*, __CFError*, void const*) + 95
frame #5: 0x00007fff8dfcc64c CFNetwork`___ZN27URLConnectionClient_Classic17_delegate_didFailEP9__CFErrorU13block_pointerFvvE_block_invoke + 118
frame #6: 0x00007fff8dfca3b3 CFNetwork`___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 94
frame #7: 0x00007fff8deec7cc CFNetwork`RunloopBlockContext::_invoke_block(void const*, void*) + 72
frame #8: 0x00007fff8fdac1e4 CoreFoundation`CFArrayApplyFunction + 68
frame #9: 0x00007fff8deec68d CFNetwork`RunloopBlockContext::perform() + 133
frame #10: 0x00007fff8deec52e CFNetwork`MultiplexerSource::perform() + 282
frame #11: 0x00007fff8deec350 CFNetwork`MultiplexerSource::_perform(void*) + 72
frame #12: 0x00007fff8fde0661 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
frame #13: 0x00007fff8fdd27ed CoreFoundation`__CFRunLoopDoSources0 + 269
frame #14: 0x00007fff8fdd1e1f CoreFoundation`__CFRunLoopRun + 927
frame #15: 0x00007fff8fdd1838 CoreFoundation`CFRunLoopRunSpecific + 296
frame #16: 0x00007fff8e10243f HIToolbox`RunCurrentEventLoopInMode + 235
frame #17: 0x00007fff8e1021ba HIToolbox`ReceiveNextEventCommon + 431
frame #18: 0x00007fff8e101ffb HIToolbox`_BlockUntilNextEventMatchingListInModeWithFilter + 71
frame #19: 0x00007fff8e416821 AppKit`_DPSNextEvent + 964
frame #20: 0x00007fff8e415fd0 AppKit`-[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 194
frame #21: 0x00007fff8e409f73 AppKit`-[NSApplication run] + 594
frame #22: 0x00007fff8e3f5424 AppKit`NSApplicationMain + 1832
* frame #23: 0x0000000100001c12 Royal5`main(argc=3, argv=0x00007fff5fbff758) + 34 at main.m:13
frame #24: 0x00007fff8819e5c9 libdyld.dylib`start + 1
Seems like Arc (or I) is somehow confused.
Any help would be greatly appreciated.
Gerriet.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden