Re: [Pyobjc-dev] "out" parameters and return values
Brought to you by:
ronaldoussoren
|
From: Mani G. <ma...@tu...> - 2009-02-19 04:16:44
|
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.
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
>
>
|