[pygobject] Fix raising an error in a constructor
- From: Garrett Regier <gregier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Fix raising an error in a constructor
- Date: Thu, 7 Aug 2014 19:56:26 +0000 (UTC)
commit 9d0c43b2b9f92fff4249e4eb296f00ea73b15af3
Author: Garrett Regier <Garrett Regier riftio com>
Date: Thu Aug 7 12:06:30 2014 -0400
Fix raising an error in a constructor
It should raise a Python exception instead of warnings about
a constructor returning NULL.
https://bugzilla.gnome.org/show_bug.cgi?id=727004
gi/pygi-cache.c | 6 +++---
tests/test_gi.py | 6 ++++++
2 files changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/gi/pygi-cache.c b/gi/pygi-cache.c
index 1682890..4727570 100644
--- a/gi/pygi-cache.c
+++ b/gi/pygi-cache.c
@@ -859,10 +859,10 @@ _constructor_cache_invoke_real (PyGIFunctionCache *function_cache,
py_args, py_kwargs);
Py_DECREF (py_args);
- if (cache->return_cache == NULL || cache->return_cache->is_skipped)
+ if (ret == NULL || cache->return_cache->is_skipped)
return ret;
- if (ret != NULL && ret != Py_None) {
+ if (ret != Py_None) {
if (!PyTuple_Check (ret))
return ret;
@@ -872,7 +872,7 @@ _constructor_cache_invoke_real (PyGIFunctionCache *function_cache,
PyErr_SetString (PyExc_TypeError, "constructor returned NULL");
- Py_XDECREF (ret);
+ Py_DECREF (ret);
return NULL;
}
diff --git a/tests/test_gi.py b/tests/test_gi.py
index edd8ca0..2c850a7 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -2111,6 +2111,12 @@ class TestPythonGObject(unittest.TestCase):
object_ = self.Object(int=42)
self.assertTrue(isinstance(object_, self.Object))
+ @unittest.skipUnless(hasattr(GIMarshallingTests.Object, 'new_fail'),
+ 'Requires newer version of GI')
+ def test_object_fail(self):
+ with self.assertRaises(GLib.Error):
+ GIMarshallingTests.Object.new_fail(int_=42)
+
def test_object_method(self):
self.Object(int=0).method()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]