Re: [Pyobjc-dev] Confusing crash that's fixed by adding NSBeep()
Brought to you by:
ronaldoussoren
From: Ronald O. <ron...@ma...> - 2010-05-21 05:45:07
|
On 20 May, 2010, at 21:52, Scott Harris wrote: > Thanks. Changing the method name to something other than action fixes the issue. Is action a bad choice for a method in general? I'd say so purely design/code smell view: 'action' doesn't communicate what the method will do (at least not unless it returns an action of some sort). That said, the crash your having is a bug in PyObjC as I expected. The bug has two levels: first of all PyObjC thinks there is an informal protocol that describes the interface of an action method because a class in AppKit defines its action method in a category. Secondly PyObjC shouldn't use its knowlegde about informal protocols to override the method signature of method that is defined in ObjC. This last bit causes the crash: your ObjC method is a method dat returns nothing ("-(void)action"), while the action method in the PyObjC metadata returns a selector ("-(SEL)action"). This causes PyObjC to treat some arbitrary value on the stack as a SEL, which is basicly a C string and that causes a EXC_BAD_ACCESS. Ronald > > -Scott > On May 15, 2010, at 11:24 AM, Ronald Oussoren wrote: > >> >> On 14 May, 2010, at 8:40, Scott Harris wrote: >> >>> I've got this obj-c object in a simple demo program: >>> >>> >>> @implementation junker >>> -(id) init >>> { >>> [super init]; >>> NSLog(@"initing"); >>> [self action]; >>> return self; >>> } >>> -(void) action >>> { >>> NSLog(@"junk"); >>> //NSBeep(); >>> } >>> @end >>> >>> I call it from Python in my App delegate like this: >>> >>> from Foundation import * >>> from AppKit import * >>> >>> class PyObjCTestAppDelegate(NSObject): >>> def applicationDidFinishLaunching_(self, sender): >>> NSLog("Application did finish launching.") >>> self.a=junker.alloc().init() >>> >>> def awakeFromNib(self): >>> NSLog("Awoke from NIB") >>> >>> @objc.IBAction >>> def buttonPress_(self, sender): >>> NSLog("Button pressed!") >>> self.a.action() >>> >>> The funny thing is that the program crashes when I press the button that calls buttonPress iff NSBeep is commented out, but runs fine if the NSBeep is uncommented. Strange. >>> >>> Here's the console output: >>> 2010-05-14 00:39:23.924 PyObjCTest[99096:a0f] Awoke from NIB >>> 2010-05-14 00:39:24.006 PyObjCTest[99096:a0f] Drawing >>> 2010-05-14 00:39:24.069 PyObjCTest[99096:a0f] Application did finish launching. >>> 2010-05-14 00:39:24.070 PyObjCTest[99096:a0f] initing >>> 2010-05-14 00:39:24.070 PyObjCTest[99096:a0f] junk >>> 2010-05-14 00:39:29.781 PyObjCTest[99096:a0f] Button Pressed >>> 2010-05-14 00:39:29.782 PyObjCTest[99096:a0f] junk >>> Program received signal: “EXC_BAD_ACCESS”. >>> sharedlibrary apply-load-rules all >>> >>> Any ideas? >> >> The code looks correct, but indeed crashes. I'm looking into this, at first glance it seems that PyObjC is confused about the return type for [junker -action], and that's probably caused by the metadata files. >> >> One quick way to work around this: rename 'action' to something else. >> >> Ronald >> > |