Re: [Pyobjc-dev] Segmentation fault when patching a namespace
Brought to you by:
ronaldoussoren
From: Ronald O. <ron...@ma...> - 2009-05-26 11:50:26
|
On 26 May, 2009, at 11:17, Orestis Markou wrote: > Hi, > > as part of unit-testing our PyObjC app, I'm trying to use mocks for > some Obj-C classes, to make things easier. Unfortunately it leads to a > segmentation fault. Even more annoyingly I can't reproduce for a > simple case. I agree that this is annoying, PyObjC shouldn't cause crashes when you do this. I won't be able to debug this unless you have a self- contained example though. > > Here's what the pattern looks like: > > from package import module as aModule > original = aModule.CALayerSubclass > > milestoneModule.CALayerSubclass = Mock() > > in 'module', we have, among others, the following: > > ...more > from Foundation import * > from AppKit import * > from Quartz import * > > from other.another import CALayerSubclass > ...more > > and other.another has just these imports: > > import sys > > from math import ceil > > from AppKit import * > from Foundation import * > from Quartz import * > > > A similar situation, when extracted to three python modules and run > works fine, so it's probably an interaction somewhere else. > > Any pointers to what I should be looking at are welcome! I tried > fiddling with sys.modules, in the suspicion that something somewhere > is keeping a reference to the original class, but to no avail. Once you have defined an ObjC class the bridge will for ever keep a reference to that class in an internal cache. You cannot work around that, because it is important to do this to ensure the bridge can work at all. Do you know when the crash occurs, in your own code of somewhere in Apple code? Gdb should be able to tell you that, at least if you can get your code to run in gdb (see http://bugs.python.org/setuptools/issue70 for that). One thing that might cause problems is when you pass instances of the mock class to Apple code that expects a subclass of CAlayer. When your mock class is not such a subclass Apple's code could crash (and that's not a bug in Apple's code or PyObjC, just a reminder on how nice it is to develop in Python instead of a pretty low-level compiled language). Ronald |