Re: [Pyobjc-dev] "out" parameters and return values
Brought to you by:
ronaldoussoren
|
From: Mani G. <ma...@tu...> - 2009-02-19 15:29:11
|
Ok, I'll put together some simplified code and post my results as soon as I can (might be a couple days). In the meantime, here is the protocol in question: ISyncSessionDriverDataSource (http://developer.apple.com/documentation/Cocoa/Reference/ISyncSessionDriverDataSource_Protocol/Reference/Reference.html#//apple_ref/occ/intf/ISyncSessionDriverDataSource) Kind regards, Mani On Thu, Feb 19, 2009 at 2:11 AM, Ronald Oussoren <ron...@ma...> wrote: > > On 19 Feb, 2009, at 5:16, Mani Ghasemlou wrote: > >> Thanks so much. Then, there must be something wrong with my code, >> because I keep getting a crash when hitting this code. This however >> rules out that my overall approach is wrong. > > Can you reproduce your crash in a smaller program? That would allow us to > look at the code and could help pintpoint the issue (either something in > your code or a bug in PyObjC). > > Is the method your writing overriding an existing method, or implementing an > informal protocol? PyObjC cannot deduce the right signature for methods > with output arguments without that information. An easy way to check if > that's your problem is to add some decoration[1] to your code that > explicitly sets the signature: > > def returnIntWithError_(self, outError): > pass # body goes here > returnIntWithError_ = objc.selector(returnIntWithError_, > signature='@@:o^@') > > Ronald > > [1] the reason for this strange formulation is that I wanted to write "a > decorator", but noticed that the required decorator isn't actually part of > PyObjC yet. > >> >> >> Kind regards, >> Mani >> >> On Wed, Feb 18, 2009 at 4:17 PM, Ronald Oussoren <ron...@ma...> >> wrote: >>> >>> Hi, >>> >>> You're approach is correct. >>> >>>>> def returnIntWithError_(self, outError): >>>>> myError = NSError.errorWithDomain_code_userInfo_('myDomain', '1', >>>>> objc.nil) >>>>> myReturnVal = 1 >>>>> return myReturnVal, myError >>>> >>> >>> As an optimization you could check if "outError is objc.NULL", if it is >>> the >>> caller isn't interested in the error value and you could return >>> (myReturnVal, objc.NULL) instead of (myReturnVal, myError). That's not >>> really an issue here, but could help when it is hard to calculate the >>> value >>> of the output argument. >>> >>> BTW. Use "None" instead of "objc.nil", both have the same value and >>> "objc.nil" is basicly only present to make it easier to translate ObjC >>> code >>> into Python. The same is true for objc.YES and objc.NO, those are aliases >>> for True and False. >>> >>> Ronald >>> >>> >>> On 17 Feb, 2009, at 20:51, Mani Ghasemlou wrote: >>> >>>> Just wanted to raise this question again, as I still haven't found a >>>> solution. >>>> >>>> I've posted the same question on Cocoa-dev, also with no response: >>>> http://www.cocoabuilder.com/archive/message/cocoa/2009/2/2/229316 >>>> >>>> Would greatly appreciate any insights! >>>> >>>> Kind regards, >>>> Mani >>>> >>>> On Mon, Feb 2, 2009 at 9:34 AM, Mani Ghasemlou <ma...@tu...> wrote: >>>>> >>>>> Hi all, >>>>> >>>>> From what I understand of the PyObjc documentation, "out" pointer >>>>> variables (such as "NSError **outError") are actually appended to the >>>>> list of return values for a bridge function. >>>>> >>>>> For example: >>>>> >>>>> int returnIntWithError: NSError **outError >>>>> >>>>> from Python would be invoked as: >>>>> >>>>> returned_int, returned_error = returnIntWithError_(None) >>>>> >>>>> I hope that my understanding of the above is correct. >>>>> >>>>> Now, my real question is to extend the above concept to the Python >>>>> side, when we want to implement an informal protocol. Let's say the >>>>> protocol says that I have to implement the returnIntWithError: >>>>> function as described above. How do I implement this function? Is the >>>>> code below enough? >>>>> >>>>> def returnIntWithError_(self, outError): >>>>> myError = NSError.errorWithDomain_code_userInfo_('myDomain', '1', >>>>> objc.nil) >>>>> myReturnVal = 1 >>>>> return myReturnVal, myError >>>>> >>>>> Note that I am completely ignoring the "outError" parameter. Does this >>>>> look kosher? >>>>> >>>>> Thanks in advance for any help! >>>>> >>>>> Cheers, >>>>> Mani >>>>> >>>> >>>> >>>> >>>> ------------------------------------------------------------------------------ >>>> Open Source Business Conference (OSBC), March 24-25, 2009, San >>>> Francisco, >>>> CA >>>> -OSBC tackles the biggest issue in open source: Open Sourcing the >>>> Enterprise >>>> -Strategies to boost innovation and cut costs with open source >>>> participation >>>> -Receive a $600 discount off the registration fee with the source code: >>>> SFAD >>>> http://p.sf.net/sfu/XcvMzF8H >>>> _______________________________________________ >>>> Pyobjc-dev mailing list >>>> Pyo...@li... >>>> https://lists.sourceforge.net/lists/listinfo/pyobjc-dev >>> >>> > > |