Thread: [Pyobjc-dev] "out" parameters and return values
Brought to you by:
ronaldoussoren
|
From: Mani G. <ma...@tu...> - 2009-02-02 14:59:16
|
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
|
|
From: Ian B. <ia...@on...> - 2009-02-02 16:07:06
|
I've been having this exact problem, as I detailed on this list a month or so ago: http://tinyurl.com/admeub I found plenty of resources on calling an Objective-C function from Python that asks for an **NSError parameter, but no information about how to implement an Objective-C protocol in Python that handles an **NSError correctly. I persistently got "Uncaught system extension" errors, and have yet to find a solution. I sincerely hope you have more luck than I, and if you do find a solution, please share! Ian On Feb 2, 2009, at 6:34 AM, Mani Ghasemlou 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 > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by: > SourcForge Community > SourceForge wants to tell your story. > http://p.sf.net/sfu/sf-spreadtheword > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev —————————————————— Ian Beck ia...@on... Tagamac: simple mac tagging http://tagamac.com |
|
From: Mani G. <ma...@tu...> - 2009-02-17 19:51:31
|
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 > |
|
From: Orestis M. <or...@or...> - 2009-02-17 20:37:00
|
Hello, I'm afraid that I don't know the answer, but it seems to me that what you describe should be a valid approach - I mean that it seems like the most reasonable syntax for this job. I assume that you've tried it and it doesn't work. Could you share what the output is? Orestis -- or...@or... http://orestis.gr/ On 17 Feb 2009, at 19: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 |
|
From: Ronald O. <ron...@ma...> - 2009-02-18 21:18:05
Attachments:
smime.p7s
|
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
|
|
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
>
>
|
|
From: Ronald O. <ron...@ma...> - 2009-02-19 07:12:13
Attachments:
smime.p7s
|
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
>>
>>
|
|
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 >>> >>> > > |
|
From: Mani G. <ma...@tu...> - 2009-02-20 18:07:03
Attachments:
SyncDriverTest.zip
|
Interestingly, while developing my simplified implementation, I hit a snag. There's one protocol function to be implemented, a very simple one: 'preferredSyncModeForEntityName:' (http://developer.apple.com/documentation/Cocoa/Reference/ISyncSessionDriverDataSource_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/ISyncSessionDriverDataSource/preferredSyncModeForEntityName: ). It returns an ISyncSessionDriverMode ( http://developer.apple.com/documentation/Cocoa/Reference/SyncServicesFramework/Miscellaneous/SyncServices_Constants/Reference/reference.html#//apple_ref/doc/c_ref/ISyncSessionDriverMode ) which is just an enum value (int). For some reason, it doesn't like my return value, even though I'm simply returning one of the enum values (ISyncSessionDriverModeRefresh). Here is the error: (ValueError: NSInvalidArgumentException - ISyncSessionDriverDataSource <MySyncSource: 0x1f803a0> responded poorly to preferredSyncModeForEntityName: with entity com.apple.contacts.Contact) Any ideas? It's all very straightforward, yet it fails. Source code is attached. Note: this test app syncs with your Address Book data (only first names/last names) and displays the raw data in the window. I've configured the sync settings (see SyncDriverTest.plist) so that it can only pull data. You can change SyncDriverTest.plist so that it retrieves any other data type recognized by sync services, but if you do make sure the entity is listed under "PullOnlyEntities" to protect your data. Cheers, Mani On Thu, Feb 19, 2009 at 10:28 AM, Mani Ghasemlou <ma...@tu...> wrote: > 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 >>>> >>>> >> >> > |