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

Martin Landa landa.martin at gmail.com
Fri May 21 03:37:31 EDT 2010


Hi,

2010/5/20 Glynn Clements <glynn at gclements.plus.com>:

[...]

> Does this work:
>        ...
>        c_input = c_char_p(input)
>        c_mapset = c_char_p("")
>        mapset = grass.G_find_raster2(c_input, c_mapset)
>        ...

No,

String.from_param(): $Revision: 41297 $
String.__init__(): $Revision: 41297 $
String.from_param(): $Revision: 41297 $
String.__init__(): $Revision: 41297 $
String.from_param(): /home/martin/smetiste/example7.py
String.__init__(): /home/martin/smetiste/example7.py
Traceback (most recent call last):
  File "/home/martin/smetiste/example7.py", line 10, in <module>
    mapset = grass.G_find_raster2(c_input, c_mapset)
ctypes.ArgumentError: argument 1: <type 'exceptions.TypeError'>:
cannot concatenate 'str' and 'c_char_p' objects

> Or this:
>        ...
>        grass.G_find_raster2.argtypes = [c_char_p, c_char_p]
>        grass.G_find_raster2.restype = c_char_p
>        mapset = grass.G_find_raster2(c_input, c_mapset)

Yes, it's working.

> The most common issue with ctypes, and the most likely reason why the
> underlying function would end up getting garbage data, is that the
> ctypes pointer types don't hold a reference to the underlying object,
> which can result in it being garbage collected while it is still being
> used.

Yes, it's seems to be a ctypes issue.

Thanks, Martin

-- 
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa


More information about the grass-dev mailing list