RE: FW: [GRASS-user] Question with Python-SWIG example [SEC=UNCLASSIFIED]

Sorry for this incomplete message - it was intended as a note to self (at another email address) about a more complete response and I didn't catch that it would be sent to the list.

Andrew.

-------------------------> "These thoughts are mine alone!" <---------
Andrew MacIntyre Operations Branch
tel: +61 2 6219 5356 Communications Infrastructure Division
fax: +61 2 6253 3277 Australian Communications & Media Authority
email: andrew.macintyre@acma.gov.au http://www.acma.gov.au/

-----Original Message-----
From: Andrew MacIntyre [mailto:andymac@bullseye.apana.org.au]
Sent: Monday, 3 May 2010 11:05 PM
To: Andrew MacIntyre
Subject: Re: FW: [GRASS-user] Question with Python-SWIG example
[SEC=UNCLASSIFIED]

Andrew MacIntyre wrote:
>
> -------------------------> "These thoughts are mine alone!" <---------
> Andrew MacIntyre Operations Branch
> tel: +61 2 6219 5356 Communications Infrastructure Division
> fax: +61 2 6253 3277 Australian Communications & Media Authority
> email: andrew.macintyre@acma.gov.au http://www.acma.gov.au/
>
>
>> -----Original Message-----
>> From: Glynn Clements [mailto:glynn@gclements.plus.com]
>> Sent: Saturday, 24 April 2010 2:34 AM
>> To: Andrew MacIntyre
>> Cc: GRASS user list
>> Subject: RE: [GRASS-user] Question with Python-SWIG example
>> [SEC=UNCLASSIFIED]
>>
>>
>> Andrew MacIntyre wrote:
>>
>>>> That's what I suspect, namely that the typemap for pointers is getting
>>>> in the way.
>>>>
>>>> Removing the typemap would mean that you couldn't pass a Python
>>>> string, array, buffer, sequence, etc directly to a GRASS function, but
>>>> would have to explicitly allocate and populate a block of memory.
>>> I don't think you need to get rid of the typemap - I suspect you might
>>> have to expand it to distinguish between the different types of pointers
>>> though (see below)...
>> Yes, but I know how to get rid of it; I don't know how to expand it.
>>
>>>>> In the SWIG wrapper? I see a note about SWIG_ConvertPtr() in
>>>>> http://www.swig.org/Doc1.3/Python.html#Python_nn64 ?
>>>> That might help, although I still don't know how to test whether a
>>>> given "PyObject *" is a SWIG-wrapped pointer.
>>> I get the impression from the above linked documentation that, for
>>> example, there should be an explicit typemap reference for CELL
pointers
>>> (as returned by Rast_allocate_c_buf()) and that the typemap for CELL
>>> pointers as an input argument should use SWIG_ConvertPtr(), which will
>>> set an exception if the inbound object is not a suitable input (if the
>>> exception flag is used; returning NULL will then propagate the
>>> exception). As far as SWIGged pointers go, this seems to be the closest
>>> you can get to Python's *Check* APIs.
>> But does that convert arrays, buffers, etc?
>>
>> FWIW, the typemaps are in swig/include/python/my_typemaps.i.
>>
>> --
>> Glynn Clements <glynn@gclements.plus.com>
>
> If you have received this email in error, please notify the sender
immediately and erase all copies of the email and any attachments to it. The
information contained in this email and any attachments may be private,
confidential and legally privileged or the subject of copyright. If you are not
the addressee it may be illegal to review, disclose, use, forward, or distribute
this email and/or its contents.
>
> Unless otherwise specified, the information in the email and any
attachments is intended as a guide only and should not be relied upon as
legal or technical advice or regarded as a substitute for legal or technical
advice in individual cases. Opinions contained in this email or any of its
attachments do not necessarily reflect the opinions of ACMA.

see pyobj_to_ptr() in typemap

- what is being expected in the CObject case?

- should this be changed to use above linked APIs to extract pointers
from SWIGged pointer objects? (can't see a typemap that converts a
returned pointer to a CObject).

--
-------------------------------------------------------------------------
Andrew I MacIntyre "These thoughts are mine alone..."
E-mail: andymac@bullseye.apana.org.au (pref) | Snail: PO Box 370
        andymac@pcug.org.au (alt) | Belconnen ACT 2616
Web: http://www.andymac.org/ | Australia

If you have received this email in error, please notify the sender immediately and erase all copies of the email and any attachments to it. The information contained in this email and any attachments may be private, confidential and legally privileged or the subject of copyright. If you are not the addressee it may be illegal to review, disclose, use, forward, or distribute this email and/or its contents.

Unless otherwise specified, the information in the email and any attachments is intended as a guide only and should not be relied upon as legal or technical advice or regarded as a substitute for legal or technical advice in individual cases. Opinions contained in this email or any of its attachments do not necessarily reflect the opinions of ACMA.