[Pyobjc-dev] Some PyObC tweaks for using EOF and custom frameworks
Brought to you by:
ronaldoussoren
From: Pierce T. W. I. <pi...@ma...> - 2003-08-09 05:56:42
|
Background: I'm using EOF 4.5, and I wanted to be able to use python to write test scripts, mini programs, and scripts that interacted with both our object model, and shell tools. Every thing works ok, except I had to make some tweaks. 1. I have to touch NSCalendarDate after loading Foundation and before loading any other frameworks via loadBundle. I think this causes +initialize for the various Foundation classes early on, which probably should have been done by the "import Foundation" step originally, but that might be tough. I'm using NSCalendarDate because NSCalendarDate had a +initialize method that was deadlocking, but using it seemed to fix everything. Doing this after the loadBundle call caused problems with both Foundation and the loaded frameworks. i.e I have to do some VOODOO: import objc import Foundation #VOODOO from Foundation import NSCalendarDate NSCalendarDate.date().description() objc.loadBundle("EOAccess",globals(),bundle_path="/System/Library/ Frameworks/EOAccess.framework") 2. EOF does some hackery on the ObjC where objects that haven't yet been fetched from the database have a fake "isa" pointer. When the object gets fetched, the isa pointer get reset to that of the real class. This crashes on the Python side, but it works if you pre resolve the fault on the ObjC side. That is in Python: mystock= trade.stock() bus errors, but mystock= trade.valueForKeyPath_("stock.self") works. Given this, the fix is easy. In objc_support.m:pythonify_c_value we have: case _C_ID: { id obj = *(id *) datum; if (obj == nil) { Which becomes: case _C_ID: { id obj = *(id *) datum; obj=[obj self]; if (obj == nil) { This forces the fault to resolve on the Objective-C side before python creates the python object. Then: mystock= trade.stock() Will work. I'm not sure what would happen if an object got invalidated. It seems in that case, you'd want to call [obj self] before doing any method calls on it, but I wasn't sure where to put that. Pierce |