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

Andrew MacIntyre Andrew.MacIntyre at acma.gov.au
Thu Apr 22 20:52:08 EDT 2010


> From: Glynn Clements
> Andrew MacIntyre wrote:
> 
> > > That was what I tried first, but it results in Rast_get_c_row()
> > > segfaulting.
> >
> > Then it seems to me that there's some problem with the SWIG wrapper
for
> > Rast_get_c_row(), if it won't accept a valid SWIG pointer object
> > returned from another wrapped function.
> 
> 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)...

> > > There is a typemap for pointers, which converts a CObject, string,
> > > buffer or sequence. I have no idea how to test for or convert a
> > > SWIG-wrapped pointer.
> >
> > 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.

Cheers,
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 at acma.gov.au            http://www.acma.gov.au/


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.


More information about the grass-user mailing list