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

Glynn Clements glynn at gclements.plus.com
Fri Apr 23 12:33:32 EDT 2010


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 at gclements.plus.com>


More information about the grass-user mailing list