diff options
author | Cédric Krier <cedric.krier@b2ck.com> | 2012-02-10 09:04:18 +0100 |
---|---|---|
committer | Martin Pitt <martin.pitt@ubuntu.com> | 2012-02-10 09:04:18 +0100 |
commit | 4aeb27efc43e131de5d0bc0f60dca7c1d34c3d45 (patch) | |
tree | 6fe99f4612a10b180b0617fad2ae4ceb0220c158 | |
parent | 5c0b20cc1a261cb7430a5251dffe60da698033b5 (diff) | |
download | pygobject-4aeb27efc43e131de5d0bc0f60dca7c1d34c3d45.tar.gz |
Provide access to gpointer struct values
https://bugzilla.gnome.org/show_bug.cgi?id=668356
Signed-off-by: Martin Pitt <martin.pitt@ubuntu.com>
-rw-r--r-- | gi/pygi-argument.c | 3 | ||||
-rw-r--r-- | gi/pygi-info.c | 13 | ||||
-rw-r--r-- | tests/test_everything.py | 21 |
3 files changed, 36 insertions, 1 deletions
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c index 9d99c352..fce91b4a 100644 --- a/gi/pygi-argument.c +++ b/gi/pygi-argument.c @@ -1330,7 +1330,8 @@ _pygi_argument_to_object (GIArgument *arg, type_tag = g_type_info_get_tag (type_info); switch (type_tag) { case GI_TYPE_TAG_VOID: - if (g_type_info_is_pointer (type_info)) { + if (g_type_info_is_pointer (type_info) && + (arg->v_pointer != NULL)) { /* Raw Python objects are passed to void* args */ g_warn_if_fail (transfer == GI_TRANSFER_NOTHING); object = arg->v_pointer; diff --git a/gi/pygi-info.c b/gi/pygi-info.c index bf3af589..d3adacc6 100644 --- a/gi/pygi-info.c +++ b/gi/pygi-info.c @@ -1371,6 +1371,19 @@ _wrap_g_field_info_set_value (PyGIBaseInfo *self, } g_base_info_unref (info); + } else if (g_type_info_is_pointer (field_type_info) + && g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_VOID) { + int offset; + + offset = g_field_info_get_offset ((GIFieldInfo *) self->info); + value = _pygi_argument_from_object (py_value, field_type_info, GI_TRANSFER_NOTHING); + + Py_XDECREF(G_STRUCT_MEMBER (gpointer, pointer, offset)); + G_STRUCT_MEMBER (gpointer, pointer, offset) = (gpointer)value.v_pointer; + Py_XINCREF(py_value); + + retval = Py_None; + goto out; } value = _pygi_argument_from_object (py_value, field_type_info, GI_TRANSFER_EVERYTHING); diff --git a/tests/test_everything.py b/tests/test_everything.py index 82edfcfa..f4f4bf98 100644 --- a/tests/test_everything.py +++ b/tests/test_everything.py @@ -8,6 +8,7 @@ import sys sys.path.insert(0, "../") from sys import getrefcount +import copy import cairo from gi.repository import GObject @@ -161,6 +162,26 @@ class TestEverything(unittest.TestCase): def test_ptrarray(self): self.assertEquals (Everything.test_garray_container_return(), ['regress']) + def test_struct_gpointer(self): + l1 = GLib.List() + self.assertEqual(l1.data, None) + init_refcount = getrefcount(l1) + + l1.data = 'foo' + self.assertEqual(l1.data, 'foo') + + l2 = l1 + self.assertEqual(l1.data, l2.data) + self.assertEquals(getrefcount(l1), init_refcount+1) + + l3 = copy.copy(l1) + l3.data = 'bar' + self.assertEqual(l1.data, 'foo') + self.assertEqual(l2.data, 'foo') + self.assertEqual(l3.data, 'bar') + self.assertEquals(getrefcount(l1), init_refcount+1) + self.assertEquals(getrefcount(l3), init_refcount) + class TestNullableArgs(unittest.TestCase): def test_in_nullable_hash(self): Everything.test_ghash_null_in(None) |