[Qgis-developer] bug when calling QgsGeometry::setWkbAndOwnership
from python (with patch)
Stefanie Tellex
stefie10 at media.mit.edu
Tue Jun 3 08:54:22 EDT 2008
Hi,
The attached patch (against r8576) fixes a bug I ran into when trying to
call QgsGeometry::setWkbAndOnwership from python. When calling it
from python, the caller cannot release ownership of the input buffer,
and I would get a seg fault. I put a wrapper around the method that
makes a copy before passing it to the C code.
There's no memory leak (I don't think), because python retains ownership
of the input string, and the qgsgeometry object owns the copy.
Stefanie
-------------- next part --------------
Index: qgis/qgis_unstable/python/core/qgsgeometry.sip
===================================================================
--- qgis.orig/qgis_unstable/python/core/qgsgeometry.sip 2008-05-02 13:23:54.000000000 -0400
+++ qgis/qgis_unstable/python/core/qgsgeometry.sip 2008-05-26 21:08:55.000000000 -0400
@@ -61,7 +61,12 @@
*/
// SIP: buffer will be transferred from python to C++
// TODO: create pythonic interface that will receive wkb as a string
- void setWkbAndOwnership(unsigned char * wkb /Transfer, Array/, size_t length /ArraySize/);
+ void setWkbAndOwnership(unsigned char * wkb /Array/, size_t length /ArraySize/);
+%MethodCode
+unsigned char * copy = (unsigned char * ) malloc(a1);
+memcpy(copy, a0, a1);
+sipCpp->setWkbAndOwnership(copy, a1);
+%End
/**
Returns the buffer containing this geometry in WKB format.
More information about the Qgis-developer
mailing list