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

Andrew MacIntyre Andrew.MacIntyre at acma.gov.au
Sun May 16 21:00:52 EDT 2010


> From: Glynn Clements

> > I also found ctypesgen:
> >
> > 	http://code.google.com/p/ctypesgen/
> 
> I finally got around to looking at this, and it took less than half an
hour to
> generate working bindings. Obviously, it will need more testing, but
unless
> any insurmountable problems show up, I intend to using this in place
of
> SWIG.

Glad you found something that you're comfortable with, and that the
effort required appears to be so modest.

> Also, I've discovered that NumPy arrays have conversion methods, e.g.
> 
>     p = buf.ctypes.data_as(POINTER(raster.CELL))
> 
> One caveat: this *doesn't* appear to increment the reference count, so
if
> you do e.g.:
> 
>     buf = buf.ctypes.data_as(POINTER(raster.CELL))
> 
> the array will be gc'd resulting in buf pointing at garbage.

This sort of issue is something that catches people in Python
(especially when using ctypes) until they learn what needs to be
preserved - its sometimes easy to lose sight of whether you've got deep
copies or shallow copies of the original.

> I haven't tried using ctypesgen for C++, though.

The material on the above website makes no mention of C++...

Regards,
Andrew.

-------------------------> "These thoughts are mine alone!" <---------
Andrew MacIntyre           Operations Branch
tel:   +61 2 6219 5356     Communications Infrastructure Division
fax:   +61 2 6253 3277     Australian Communications & Media Authority
email: andrew.macintyre at acma.gov.au            http://www.acma.gov.au/


If you have received this email in error, please notify the sender immediately and erase all copies of the email and any attachments to it. The information contained in this email and any attachments may be private, confidential and legally privileged or the subject of copyright. If you are not the addressee it may be illegal to review, disclose, use, forward, or distribute this email and/or its contents.
 
Unless otherwise specified, the information in the email and any attachments is intended as a guide only and should not be relied upon as legal or technical advice or regarded as a substitute for legal or technical advice in individual cases. Opinions contained in this email or any of its attachments do not necessarily reflect the opinions of ACMA.


More information about the grass-user mailing list