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

Glynn Clements glynn at gclements.plus.com
Mon May 10 13:55:29 EDT 2010


Andrew MacIntyre wrote:

> > > In the case where SWIG is using its own objects to contain returned
> > > pointers, then I expect pyobj_to_ptr() needs to be changed to use
> > > SWIG_ConvertPtr() rather than PyCObject_AsVoidPtr() to retrieve the
> > > actual pointer, or the output typemaps for returned pointers need to be
> > > changed to use Python's CObjects rather than native SWIG wrapper
> > > objects.
> > 
> > So, what do you suggest? Remove the PyCObject_Check() call, explicitly
> > check for string, read buffer, write buffer, and sequence, then call
> > SWIG_ConvertPtr() on anything which is left over?
> 
> That's what I would try.

Except ... SWIG_ConvertPtr() seems to require that you have access to
the type descriptor. The documentation seems to suggest (although, as
usual, it's unclear) that you need to know the actual type.

> 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)...

> 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

GRASS uses "void *" to refer to any of CELL*/FCELL*/DCELL* quite
extensively.

I think that I'm not going to put any more effort into the SWIG
wrapper unless usable documentation materialises. In the meantime, I'm
going to look for alternatives.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-user mailing list