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

Glynn Clements glynn at gclements.plus.com
Mon Apr 19 12:39:18 EDT 2010


Andrew MacIntyre wrote:

> > Glynn Clements wrote:
> 
> {...}
> 
> > Nor can I figure out how to make use of any pointers returned from
> > functions. Typemaps exist to allow strings, arrays, etc to be
> > converted to pointers when passing them into functions, but it isn't
> > possible to do the reverse (converting to a pointer discards the size
> > and type; converting from a pointer would require some way to obtain
> > this information). The functions generated by cpointer.i and carrays.i
> > don't seem to work as expected (I get a segfault).
> 
> Doesn't the ctypes cast() function work for you in making use of
> returned pointers?

In case it wasn't clear, I was talking about SWIG-wrapped pointers,
e.g.:

> import grass.lib.raster as rast
> import grass.lib.grass as gis
> import ctypes
> gis.G_gisinit("")
> p = rast.Rast_allocate_c_buf()
> p
<Swig Object of type 'int *' at 0x912e5b8>
> q = ctypes.cast(p, ctypes.c_void_p)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/ctypes/__init__.py", line 489, in cast
    return _cast(obj, obj, typ)
ctypes.ArgumentError: argument 1: <type 'exceptions.TypeError'>: wrong type

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


More information about the grass-user mailing list