Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2009-02-19 23:38:27 (GMT)
committer Colin Walters <walters@verbum.org>2009-02-19 23:38:27 (GMT)
commit48b8fe509e0aef8ce4db323053507ba1daeb2552 (patch)
tree22cecf3aa088516f4f87d9b048d331ab4b62b932
parentb02efbc94a1a6febddf62d1e742abd1f82e9ecf3 (diff)
giscanner: Set Python exceptions on type errors instead of g_assert
This gives us nice stack traces.
-rw-r--r--giscanner/giscannermodule.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/giscanner/giscannermodule.c b/giscanner/giscannermodule.c
index 3223508..b7ac316 100644
--- a/giscanner/giscannermodule.c
+++ b/giscanner/giscannermodule.c
@@ -547,8 +547,8 @@ pygi_collect_attributes (PyObject *self,
GString *attr_value;
int len;
- if (!PyArg_ParseTuple(args, "sOisi",
- &tag_name, &attributes,
+ if (!PyArg_ParseTuple(args, "sO!isi",
+ &tag_name, &PyList_Type, &attributes,
&self_indent, &indent_char,
&indent))
return NULL;
@@ -566,8 +566,6 @@ pygi_collect_attributes (PyObject *self,
first = TRUE;
attr_value = g_string_new ("");
-
- g_assert(PyList_Check(attributes));
for (i = 0; i < PyList_Size (attributes); ++i)
{
@@ -575,9 +573,21 @@ pygi_collect_attributes (PyObject *self,
char *attr, *value, *escaped;
tuple = PyList_GetItem (attributes, i);
- g_assert(tuple != NULL);
- g_assert(PyTuple_Check(tuple));
- g_assert(PyTuple_Size(tuple) == 2);
+
+ if (!PyTuple_Check (tuple))
+ {
+ PyErr_SetString(PyExc_TypeError,
+ "attribute item must be a tuple");
+ return NULL;
+ }
+
+ if (!PyTuple_Size (tuple) == 2)
+ {
+ PyErr_SetString(PyExc_IndexError,
+ "attribute item must be a tuple of length 2");
+ return NULL;
+ }
+
if (PyTuple_GetItem(tuple, 1) == Py_None)
continue;