summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrederic Peters <fpeters@entrouvert.com>2008-04-29 12:05:28 +0000
committerFrederic Peters <fpeters@entrouvert.com>2008-04-29 12:05:28 +0000
commite532085587f82fca4d47bd63a8e9d1e4404f2379 (patch)
tree42c07dce7b3059306f370e8321ffee662dfc29a5
parent349d44ce6894bf0e979f12f5c62fe69bcceabc7d (diff)
downloadlasso-e532085587f82fca4d47bd63a8e9d1e4404f2379.tar.gz
lasso-e532085587f82fca4d47bd63a8e9d1e4404f2379.tar.xz
lasso-e532085587f82fca4d47bd63a8e9d1e4404f2379.zip
[project @ fpeters@0d.be-20071113172348-8i4mcve247l8ec0k]
fixed memory managements issues in Python binding Original author: Frederic Peters <fpeters@0d.be> Date: 2007-11-13 18:23:48.693000+01:00
-rw-r--r--bindings/lang_python.py17
-rw-r--r--bindings/lang_python_wrapper_top.c1
2 files changed, 12 insertions, 6 deletions
diff --git a/bindings/lang_python.py b/bindings/lang_python.py
index d7be04c4..8e8c8045 100644
--- a/bindings/lang_python.py
+++ b/bindings/lang_python.py
@@ -57,7 +57,9 @@ import _lasso
_lasso.init()
-def cptrToPy( cptr):
+def cptrToPy(cptr):
+ if cptr is None:
+ return None
klass = getattr(lasso, cptr.typename)
o = klass.__new__(klass)
o._cptr = cptr
@@ -515,7 +517,11 @@ register_constants(PyObject *d)
print >> fd, ' this = (%s*)cvt_this->obj;' % klassname
if self.is_pygobject(m[0]):
- print >> fd, ' return_value = g_object_ref(this->%s);' % m[1];
+ print >> fd, ' if (this->%s) {' % m[1]
+ print >> fd, ' return_value = g_object_ref(this->%s);' % m[1];
+ print >> fd, ' } else {'
+ print >> fd, ' return_value = NULL;'
+ print >> fd, ' }'
elif m[0] in ('char*', 'const char*', 'gchar*', 'const gchar*'):
print >> fd, ' return_value = g_strdup(this->%s);' % m[1]
else:
@@ -644,7 +650,7 @@ register_constants(PyObject *d)
print >> fd, ' if (return_value) {'
print >> fd, ' return_pyvalue = PyString_FromString(return_value);'
print >> fd, ' g_free(return_value);'
- #print >> fd, ' Py_INCREF(return_pyvalue);'
+ print >> fd, ' Py_INCREF(return_pyvalue);'
print >> fd, ' return return_pyvalue;'
print >> fd, ' } else {'
print >> fd, ' Py_INCREF(Py_None);'
@@ -653,7 +659,7 @@ register_constants(PyObject *d)
elif vtype in ('const char*', 'const gchar*'):
print >> fd, ' if (return_value) {'
print >> fd, ' return_pyvalue = PyString_FromString(return_value);'
- #print >> fd, ' Py_INCREF(return_pyvalue);'
+ print >> fd, ' Py_INCREF(return_pyvalue);'
print >> fd, ' return return_pyvalue;'
print >> fd, ' } else {'
print >> fd, ' Py_INCREF(Py_None);'
@@ -713,7 +719,7 @@ register_constants(PyObject *d)
# convert xmlNode* to strings
print >> fd, ' if (return_value) {'
print >> fd, ' return_pyvalue = get_pystring_from_xml_node(return_value);'
- #print >> fd, ' Py_INCREF(return_pyvalue);'
+ print >> fd, ' Py_INCREF(return_pyvalue);'
print >> fd, ' return return_pyvalue;'
print >> fd, ' } else {'
print >> fd, ' Py_INCREF(Py_None);'
@@ -727,7 +733,6 @@ register_constants(PyObject *d)
print >> fd, '''\
if (return_value) {
return_pyvalue = PyGObjectPtr_New(G_OBJECT(return_value));
- /*Py_INCREF(return_pyvalue);*/
return return_pyvalue;
} else {
Py_INCREF(Py_None);
diff --git a/bindings/lang_python_wrapper_top.c b/bindings/lang_python_wrapper_top.c
index 2ae93296..fc2769f9 100644
--- a/bindings/lang_python_wrapper_top.c
+++ b/bindings/lang_python_wrapper_top.c
@@ -173,6 +173,7 @@ PyGObjectPtr_dealloc(PyGObjectPtr *self)
G_OBJECT_TYPE_NAME(self->obj),
self->obj->ref_count);
#endif
+ g_object_set_qdata_full(self->obj, lasso_wrapper_key, NULL, NULL);
g_object_unref(self->obj);
Py_XDECREF(self->typename);
self->ob_type->tp_free((PyObject*)self);