diff options
author | Colin Walters <walters@verbum.org> | 2010-12-03 10:41:50 -0500 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2010-12-03 10:41:50 -0500 |
commit | 1c9ea4beb60488a7a356db5a8e2d21f6afb42092 (patch) | |
tree | 95ca8c3b2fe36e058337ec53e254092135fdc82e | |
parent | 805ed9f5150d8d202700d4be67af9d7068d8db5b (diff) | |
download | gobject-introspection-1c9ea4beb60488a7a356db5a8e2d21f6afb42092.tar.gz |
scanner: Switch to only Python 2.5 C API usage
PyUnicode_FromString is 2.6 only, we can use PyUnicode_DecodeUTF8
easily enough though.
Also, fix memory leaks in this function; we leaked the buffer
on success, and also in most failure paths.
-rw-r--r-- | giscanner/giscannermodule.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/giscanner/giscannermodule.c b/giscanner/giscannermodule.c index 0f94240f..b7cfd6ec 100644 --- a/giscanner/giscannermodule.c +++ b/giscanner/giscannermodule.c @@ -610,8 +610,9 @@ pygi_collect_attributes (PyObject *self, int indent, indent_len, i, j, self_indent; char *indent_char; gboolean first; - GString *attr_value; + GString *attr_value = NULL; int len; + PyObject *result = NULL; if (!PyArg_ParseTuple(args, "sO!isi", &tag_name, &PyList_Type, &attributes, @@ -620,7 +621,7 @@ pygi_collect_attributes (PyObject *self, return NULL; if (attributes == Py_None || !PyList_Size(attributes)) - return PyUnicode_FromString(""); + return PyUnicode_DecodeUTF8("", 0, "strict"); len = calc_attrs_length(attributes, indent, self_indent); if (len < 0) @@ -644,14 +645,14 @@ pygi_collect_attributes (PyObject *self, { PyErr_SetString(PyExc_TypeError, "attribute item must be a tuple"); - return NULL; + goto out; } if (!PyTuple_Size (tuple) == 2) { PyErr_SetString(PyExc_IndexError, "attribute item must be a tuple of length 2"); - return NULL; + goto out; } if (PyTuple_GetItem(tuple, 1) == Py_None) @@ -659,13 +660,12 @@ pygi_collect_attributes (PyObject *self, /* this leaks, but we exit after, so */ if (!PyArg_ParseTuple(tuple, "sO", &attr, &pyvalue)) - return NULL; + goto out; if (PyUnicode_Check(pyvalue)) { PyObject *s = PyUnicode_AsUTF8String(pyvalue); - if (!s) { - return NULL; - } + if (!s) + goto out; value = PyString_AsString(s); Py_DECREF(s); } else if (PyString_Check(pyvalue)) { @@ -673,7 +673,7 @@ pygi_collect_attributes (PyObject *self, } else { PyErr_SetString(PyExc_TypeError, "value must be string or unicode"); - return NULL; + goto out; } if (indent_len && !first) @@ -693,7 +693,11 @@ pygi_collect_attributes (PyObject *self, first = FALSE; } - return PyUnicode_FromString (g_string_free (attr_value, FALSE)); + result = PyUnicode_DecodeUTF8 (attr_value->str, attr_value->len, "strict"); + out: + if (attr_value != NULL) + g_string_free (attr_value, TRUE); + return result; } /* Module */ |