Commit 4aeb27ef authored by Cédric Krier's avatar Cédric Krier Committed by Martin Pitt
Browse files

Provide access to gpointer struct values

https://bugzilla.gnome.org/show_bug.cgi?id=668356

Signed-off-by: Martin Pitt's avatarMartin Pitt <martin.pitt@ubuntu.com>
parent 5c0b20cc
......@@ -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;
......
......@@ -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);
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment