[pygobject] Fix crash when returning (False, None) from Gtk.TreeModel.do_get_iter()
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Fix crash when returning (False, None) from Gtk.TreeModel.do_get_iter()
- Date: Mon, 30 Jul 2012 10:54:19 +0000 (UTC)
commit 8f31e85db1392eb7222593fc0d05144c2bca06a3
Author: Simon Feltman <s feltman gmail com>
Date: Sun Jul 29 23:36:25 2012 -0700
Fix crash when returning (False, None) from Gtk.TreeModel.do_get_iter()
Add a Py_None check before attempting memcpy().
https://bugzilla.gnome.org/show_bug.cgi?id=680812
Signed-off-by: Martin Pitt <martinpitt gnome org>
gi/pygi-closure.c | 10 +++++++---
tests/test_overrides.py | 9 +++++++++
2 files changed, 16 insertions(+), 3 deletions(-)
---
diff --git a/gi/pygi-closure.c b/gi/pygi-closure.c
index 8c8e13d..b05f2d1 100644
--- a/gi/pygi-closure.c
+++ b/gi/pygi-closure.c
@@ -81,9 +81,13 @@ _pygi_closure_assign_pyobj_to_out_argument (gpointer out_arg, PyObject *object,
interface_type = g_base_info_get_type (interface);
if (!g_type_info_is_pointer (type_info) &&
- interface_type == GI_INFO_TYPE_STRUCT) {
- gsize item_size = _pygi_g_type_info_size (type_info);
- memcpy (out_arg, arg.v_pointer, item_size);
+ interface_type == GI_INFO_TYPE_STRUCT) {
+ if (object == Py_None) {
+ arg.v_pointer = NULL;
+ } else {
+ gsize item_size = _pygi_g_type_info_size (type_info);
+ memcpy (out_arg, arg.v_pointer, item_size);
+ }
break;
}
}
diff --git a/tests/test_overrides.py b/tests/test_overrides.py
index 3d25d52..2aa803a 100644
--- a/tests/test_overrides.py
+++ b/tests/test_overrides.py
@@ -1570,6 +1570,15 @@ class TestGtk(unittest.TestCase):
self.assertRaises(IndexError, tree_store.__delitem__, -101)
self.assertRaises(IndexError, tree_store.__delitem__, 101)
+ def test_tree_model_get_iter_fail(self):
+ # TreeModel class with a failing get_iter()
+ class MyTreeModel(GObject.GObject, Gtk.TreeModel):
+ def do_get_iter(self, iter):
+ return (False, None)
+
+ tm = MyTreeModel()
+ self.assertEqual(tm.get_iter_first(), None)
+
def test_tree_model_edit(self):
model = Gtk.ListStore(int, str, float)
model.append([1, "one", -0.1])
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]