[pygi] If None is passed to an interface which takes an object, convert it to NULL
- From: Tomeu Vizoso <tomeuv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygi] If None is passed to an interface which takes an object, convert it to NULL
- Date: Sun, 23 May 2010 09:00:31 +0000 (UTC)
commit 0df0c956bb2476392c9d81f0a243a7e84c067166
Author: Tomeu Vizoso <tomeu vizoso collabora co uk>
Date: Sun May 23 10:59:27 2010 +0200
If None is passed to an interface which takes an object, convert it to
NULL
* without this patch PyGI treats the None object as a PyGObject and ends up
extracting garbage data causing a crash
* None's equivalent in C is NULL so we must provide a special case where we
marshal the None as NULL
https://bugzilla.gnome.org/show_bug.cgi?id=617880
gi/pygi-argument.c | 5 +++++
tests/test_everything.py | 6 ++++++
2 files changed, 11 insertions(+), 0 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index 6461980..4f91fb9 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -997,6 +997,11 @@ array_item_error:
}
case GI_INFO_TYPE_INTERFACE:
case GI_INFO_TYPE_OBJECT:
+ if (object == Py_None) {
+ arg.v_pointer = NULL;
+ break;
+ }
+
arg.v_pointer = pygobject_get(object);
if (transfer == GI_TRANSFER_EVERYTHING) {
g_object_ref(arg.v_pointer);
diff --git a/tests/test_everything.py b/tests/test_everything.py
index 7ef7b8a..fb6bc25 100644
--- a/tests/test_everything.py
+++ b/tests/test_everything.py
@@ -64,6 +64,9 @@ class TestNullableArgs(unittest.TestCase):
def test_in_nullable_string(self):
Everything.test_utf8_null_in(None)
+ def test_in_nullable_object(self):
+ Everything.test_object_null_in(None)
+
def test_out_nullable_hash(self):
self.assertEqual(None, Everything.test_ghash_null_out())
@@ -77,6 +80,9 @@ class TestNullableArgs(unittest.TestCase):
def test_out_nullable_string(self):
self.assertEqual(None, Everything.test_utf8_null_out())
+ def test_out_nullable_object(self):
+ self.assertEqual(None, Everything.test_object_null_out())
+
class TestCallbacks(unittest.TestCase):
called = False
main_loop = GObject.MainLoop()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]