summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Reiter <creiter@src.gnome.org>2015-07-04 22:09:46 +0200
committerChristoph Reiter <creiter@src.gnome.org>2016-02-29 14:34:55 +0100
commit7e29227b6f58cfcc96118a4af83658ca1a6fa1f4 (patch)
treee0e0d9dbfa502e315f1cfe010fc0cc68d6d443fd
parent49880800b35029de3731523eede1b3174f10c1db (diff)
downloadpygobject-7e29227b6f58cfcc96118a4af83658ca1a6fa1f4.tar.gz
Some error handling/reporting fixes.
* Check in pyg_boxed_new() if the passed type is an actual subclass * Don't replace existing exceptions in pyg_value_as_pyobject() * Print an error in pyg_closure_marshal() in case marshalling an argument failed. https://bugzilla.gnome.org/show_bug.cgi?id=751956
-rw-r--r--gi/pygboxed.c8
-rw-r--r--gi/pygi-value.c15
-rw-r--r--gi/pygtype.c11
3 files changed, 27 insertions, 7 deletions
diff --git a/gi/pygboxed.c b/gi/pygboxed.c
index 30ab423a..cdb766c2 100644
--- a/gi/pygboxed.c
+++ b/gi/pygboxed.c
@@ -189,7 +189,7 @@ pyg_register_boxed(PyObject *dict, const gchar *class_name,
* wrapper will be freed when the wrapper is deallocated. If
* @copy_boxed is True, then @own_ref must also be True.
*
- * Returns: the boxed wrapper.
+ * Returns: the boxed wrapper or %NULL and sets an exception.
*/
PyObject *
pyg_boxed_new(GType boxed_type, gpointer boxed, gboolean copy_boxed,
@@ -218,6 +218,12 @@ pyg_boxed_new(GType boxed_type, gpointer boxed, gboolean copy_boxed,
if (!tp)
tp = (PyTypeObject *)&PyGBoxed_Type; /* fallback */
+ if (!PyType_IsSubtype (tp, &PyGBoxed_Type)) {
+ PyErr_Format (PyExc_RuntimeError, "%s isn't a GBoxed", tp->tp_name);
+ pyglib_gil_state_release (state);
+ return NULL;
+ }
+
self = (PyGBoxed *)tp->tp_alloc(tp, 0);
if (self == NULL) {
diff --git a/gi/pygi-value.c b/gi/pygi-value.c
index 413e14a9..b155a68e 100644
--- a/gi/pygi-value.c
+++ b/gi/pygi-value.c
@@ -834,13 +834,13 @@ pygi_value_to_py_structured_type (const GValue *value, GType fundamental, gboole
* This function creates/returns a Python wrapper object that
* represents the GValue passed as an argument.
*
- * Returns: a PyObject representing the value.
+ * Returns: a PyObject representing the value or %NULL and sets an exception.
*/
PyObject *
pyg_value_as_pyobject (const GValue *value, gboolean copy_boxed)
{
- gchar buf[128];
PyObject *pyobj;
+ const gchar *type_name;
GType fundamental = G_TYPE_FUNDAMENTAL (G_VALUE_TYPE (value));
/* HACK: special case char and uchar to return PyBytes intstead of integers
@@ -865,9 +865,14 @@ pyg_value_as_pyobject (const GValue *value, gboolean copy_boxed)
return pyobj;
}
- g_snprintf(buf, sizeof(buf), "unknown type %s",
- g_type_name(G_VALUE_TYPE(value)));
- PyErr_SetString(PyExc_TypeError, buf);
+ if (!PyErr_Occurred ()) {
+ type_name = g_type_name (G_VALUE_TYPE (value));
+ if (type_name == NULL) {
+ type_name = "(null)";
+ }
+ PyErr_Format (PyExc_TypeError, "unknown type %s", type_name);
+ }
+
return NULL;
}
diff --git a/gi/pygtype.c b/gi/pygtype.c
index 985e9696..a3784c86 100644
--- a/gi/pygtype.c
+++ b/gi/pygtype.c
@@ -704,7 +704,16 @@ pyg_closure_marshal(GClosure *closure,
/* error condition */
if (!item) {
- goto out;
+ if (!PyErr_Occurred ())
+ PyErr_SetString (PyExc_TypeError,
+ "can't convert parameter to desired type");
+
+ if (pc->exception_handler)
+ pc->exception_handler (return_value, n_param_values, param_values);
+ else
+ PyErr_Print();
+
+ goto out;
}
PyTuple_SetItem(params, i, item);
}