Re: [Pyobjc-dev] Headache over hacking an XML editor
Brought to you by:
ronaldoussoren
From: Just v. R. <ju...@le...> - 2003-01-14 18:57:28
|
bb...@ma... wrote: > Thread starts here: > > http://sourceforge.net/mailarchive/message.php?msg_id=2347617 > > But this particular response [of mine] contains the most detailed > explanation on why I don't believe it is possible to eliminate > retain/release/autorelease entirely from the Python side of the > bridge: > > http://sourceforge.net/mailarchive/message.php?msg_id=2349810 > > And another thread that may also be illuminating: > > http://sourceforge.net/mailarchive/message.php?msg_id=2342178 > > And another thread: > > http://sourceforge.net/mailarchive/message.php?msg_id=2331515 Ugh, this is depressing :-(. (So you _can_ find out the return type of a method at runtime but not whether it returns a new or a borrowed reference. Great.) Here's a quick idea to work around the most common (I think) irritation: instead of raising an exception when calling a (subclass of) NSObject ("TypeError: Use class methods to instantiate new Objective-C objects") have objc-object.m::object_new() do this: self = cls.alloc() self.release() # ownership transferred to the Python wrapper return self This doesn't touch the alloc() semantics, yet provides a much more Pythonic way to create instances. Heck, this will even call __init__() for you! ;-) What I still don't understand is how pyobjc manages the refcount of Python objects passed to objc: the Python object can't have a reference to it, so when will the wrapper be released? Is it an autorelease object? Just |