[pygobject] Add __gpointer__ property to GObject static binding



commit df18f9cc3828d1bcf6b6cdf26af786fd9f36d77e
Author: Simon Feltman <sfeltman src gnome org>
Date:   Wed Jan 30 21:37:07 2013 -0800

    Add __gpointer__ property to GObject static binding
    
    Add access to the underlying C GObject pointer by wrapping it in a
    PyCapsule/PyCPointer and exposing it as __gpointer__.
    Add special case marshaling for gi parameters annotated as gpointer
    to accept a PyCapsule and extract the underlying pointer as the arg.
    This allows usage of methods like GObject.signal_handler_disconnect
    which we can start replacing the static bindings with.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=692918

 gi/_gobject/pygobject.c   |   11 +++++++++--
 gi/pygi-marshal-from-py.c |    6 +++++-
 2 files changed, 14 insertions(+), 3 deletions(-)
---
diff --git a/gi/_gobject/pygobject.c b/gi/_gobject/pygobject.c
index 811a20c..add71e2 100644
--- a/gi/_gobject/pygobject.c
+++ b/gi/_gobject/pygobject.c
@@ -2272,12 +2272,18 @@ static PyObject *
 pygobject_get_refcount(PyGObject *self, void *closure)
 {
     if (self->obj == NULL) {
-	PyErr_Format(PyExc_TypeError, "GObject instance is not yet created");
-	return NULL;
+        PyErr_Format(PyExc_TypeError, "GObject instance is not yet created");
+        return NULL;
     }
     return PYGLIB_PyLong_FromLong(self->obj->ref_count);
 }
 
+static PyObject *
+pygobject_get_pointer(PyGObject *self, void *closure)
+{
+    return PYGLIB_CPointer_WrapPointer (self->obj, NULL);
+}
+
 static int
 pygobject_setattro(PyObject *self, PyObject *name, PyObject *value)
 {
@@ -2296,6 +2302,7 @@ pygobject_setattro(PyObject *self, PyObject *name, PyObject *value)
 static PyGetSetDef pygobject_getsets[] = {
     { "__dict__", (getter)pygobject_get_dict, (setter)0 },
     { "__grefcount__", (getter)pygobject_get_refcount, (setter)0, },
+    { "__gpointer__", (getter)pygobject_get_pointer, (setter)0, },
     { NULL, 0, 0 }
 };
 
diff --git a/gi/pygi-marshal-from-py.c b/gi/pygi-marshal-from-py.c
index c14455c..9f7d874 100644
--- a/gi/pygi-marshal-from-py.c
+++ b/gi/pygi-marshal-from-py.c
@@ -235,7 +235,11 @@ _pygi_marshal_from_py_void (PyGIInvokeState   *state,
 {
     g_warn_if_fail (arg_cache->transfer == GI_TRANSFER_NOTHING);
 
-    arg->v_pointer = py_arg;
+    if (PYGLIB_CPointer_Check(py_arg)) {
+        arg->v_pointer = PYGLIB_CPointer_GetPointer (py_arg, NULL);
+    } else {
+        arg->v_pointer = py_arg;
+    }
 
     return TRUE;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]