Commit df18f9cc authored by Simon Feltman's avatar Simon Feltman
Browse files

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
parent 571e0cb2
......@@ -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 }
};
......
......@@ -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;
}
......
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