[Pyobjc-dev] Bridging NS and CF classes
Brought to you by:
ronaldoussoren
From: <bb...@ma...> - 2003-01-09 13:55:05
|
On Wednesday, Jan 8, 2003, at 18:03 US/Eastern, Jack Jansen wrote: > I think I would like the bridging to be done one-way, i.e. if > something wants an NSArray and the argument isn't an NSArray it should > try coercing the argument to an NSArray. One of the things that could > be coerced is CF.CFArray. > > I think that for going the other way (from NS to CF) manual conversion > is probably good enough initially. Won't work as there is no class identification on the arguments to methods. As such, there is no way to implement a system as you described -- no way to identify [short of parsing the headers-- but that won't be completely correct] that a particular argument should be an instance of NSArray vs. an NSDictionary vs. a DeveloperDefined. ObjC just doesn't care. Why can't we add enough stuff to both the CF* module(s) and the PyObjC bridge such that both can transparently consume objects from the other, where appropriate. This is basically what Apple did to ObjC and CF to create the no-cost bridge -- it would seem that we need a parallel mechanism within the "two" Python modules. That is, make the following work: >>> import _CF #this is framework build, why do I do this and not "CF"?? >>> x = _CF.CFArrayCreateMutable(10) >>> from Foundation import NSMutableArray >>> NSMutableArray.addObject_(x, 'y') Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: First argument must be an objective-C object, got <CFMutableArrayRef object at 0x0012c0e0 for 0x00160000> And so should this: >>> import _CF >>> from Foundation import NSMutableArray >>> x = NSMutableArray.array() >>> _CF.CFArrayAppendValue(x, 'y') Traceback (most recent call last): File "<stdin>", line 1, in ? AttributeError: 'module' object has no attribute 'CFArrayAppendValue' -- In the first case (CF type being messaged via PyObjC), a simple [I think] fix would be to add a method *on the C side* that can return a reference to the ObjC representation of the CF type. In the handler that produces the TypeError as shown above, the PyObjC bridge could check to see if the object has a method/attribute/function/identifier that can be used to retrieve/identify what part of the object could be used directly as the ObjC instance to be messaged. Something similar could be done for the second case, as well -- but I have *no* idea what the implementation issues would be in that context. (I couldn't actually figure out how to call CFArrayAppendValue() on CFMutableArrayRef.) b.bum |