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

Glynn Clements glynn at gclements.plus.com
Tue Apr 20 09:59:38 EDT 2010


Andrew MacIntyre wrote:

> After some googling, it seems that the pointer address should be
> obtainable by using int() on the pointer object returned by the SWIG
> wrapper (i.e. int(p) in the above example), with the resulting value
> usable in ctypes' from_address() method.  I might be wrong, but I think
> that e.g. ctypes.c_void_p(int(p)) might also work to create a ctypes
> void pointer instance.

That doesn't seem to work either:

	> import grass.lib.grass as gis
	> import grass.lib.raster as rast
	> import ctypes
	> gis.G_gisinit("")
	> p = rast.Rast_allocate_c_buf()
	> a = ctypes.cast(int(p), ctypes.POINTER(ctypes.c_int))
	> infd = rast.Rast_open_old("elevation.dem", "")
	> rast.Rast_get_c_row(infd, a, 10)
	> a[0]
	
	Segmentation fault (core dumped) 14:52:56

It's possible that the typemap is getting in the way here, but I have
no idea what should be done instead.

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


More information about the grass-user mailing list