[pygobject] Replace GObject.signal_query with introspected version
- From: Simon Feltman <sfeltman src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Replace GObject.signal_query with introspected version
- Date: Mon, 18 Aug 2014 05:23:48 +0000 (UTC)
commit 62aed0977090f7099a5e538209f7c680ea22fe12
Author: Simon Feltman <sfeltman src gnome org>
Date: Sun Aug 17 19:04:51 2014 -0700
Replace GObject.signal_query with introspected version
Remove the static bindings for GObject.signal_query and replace with a
Python compatibility shim which utilizes the introspection exposed version
of the function.
https://bugzilla.gnome.org/show_bug.cgi?id=688792
gi/gobjectmodule.c | 89 -----------------------------------------------
gi/overrides/GObject.py | 39 +++++++++++---------
2 files changed, 21 insertions(+), 107 deletions(-)
---
diff --git a/gi/gobjectmodule.c b/gi/gobjectmodule.c
index 458884b..3248804 100644
--- a/gi/gobjectmodule.c
+++ b/gi/gobjectmodule.c
@@ -1282,93 +1282,6 @@ pyg_signal_new(PyObject *self, PyObject *args)
}
static PyObject *
-pyg_signal_query (PyObject *self, PyObject *args, PyObject *kwargs)
-{
- static char *kwlist1[] = { "name", "type", NULL };
- static char *kwlist2[] = { "signal_id", NULL };
- PyObject *py_query, *params_list, *py_itype;
- GObjectClass *class = NULL;
- GType itype;
- gchar *signal_name;
- guint i;
- GSignalQuery query;
- guint id;
- gpointer iface = NULL;
-
- if (PyArg_ParseTupleAndKeywords(args, kwargs, "sO:gobject.signal_query",
- kwlist1, &signal_name, &py_itype)) {
- if ((itype = pyg_type_from_object(py_itype)) == 0)
- return NULL;
-
- if (G_TYPE_IS_INSTANTIATABLE(itype)) {
- class = g_type_class_ref(itype);
- if (!class) {
- PyErr_SetString(PyExc_RuntimeError,
- "could not get a reference to type class");
- return NULL;
- }
- } else if (!G_TYPE_IS_INTERFACE(itype)) {
- PyErr_SetString(PyExc_TypeError,
- "type must be instantiable or an interface");
- return NULL;
- } else {
- iface = g_type_default_interface_ref(itype);
- }
- id = g_signal_lookup(signal_name, itype);
- } else {
- PyErr_Clear();
- if (!PyArg_ParseTupleAndKeywords(args, kwargs,
- "i:gobject.signal_query",
- kwlist2, &id)) {
- PyErr_Clear();
- PyErr_SetString(PyExc_TypeError,
- "Usage: one of:\n"
- " gobject.signal_query(name, type)\n"
- " gobject.signal_query(signal_id)");
-
- return NULL;
- }
- }
-
- g_signal_query(id, &query);
-
- if (query.signal_id == 0) {
- Py_INCREF(Py_None);
- py_query = Py_None;
- goto done;
- }
- py_query = PyTuple_New(6);
- if (py_query == NULL) {
- goto done;
- }
- params_list = PyTuple_New(query.n_params);
- if (params_list == NULL) {
- Py_DECREF(py_query);
- py_query = NULL;
- goto done;
- }
-
- PyTuple_SET_ITEM(py_query, 0, PYGLIB_PyLong_FromLong(query.signal_id));
- PyTuple_SET_ITEM(py_query, 1, PYGLIB_PyUnicode_FromString(query.signal_name));
- PyTuple_SET_ITEM(py_query, 2, pyg_type_wrapper_new(query.itype));
- PyTuple_SET_ITEM(py_query, 3, PYGLIB_PyLong_FromLong(query.signal_flags));
- PyTuple_SET_ITEM(py_query, 4, pyg_type_wrapper_new(query.return_type));
- for (i = 0; i < query.n_params; i++) {
- PyTuple_SET_ITEM(params_list, i,
- pyg_type_wrapper_new(query.param_types[i]));
- }
- PyTuple_SET_ITEM(py_query, 5, params_list);
-
- done:
- if (class)
- g_type_class_unref(class);
- if (iface)
- g_type_default_interface_unref(iface);
-
- return py_query;
-}
-
-static PyObject *
pyg_object_class_list_properties (PyObject *self, PyObject *args)
{
GParamSpec **specs;
@@ -1693,8 +1606,6 @@ static PyMethodDef _gobject_functions[] = {
{ "type_is_a", pyg_type_is_a, METH_VARARGS },
{ "type_register", _wrap_pyg_type_register, METH_VARARGS },
{ "signal_new", pyg_signal_new, METH_VARARGS },
- { "signal_query",
- (PyCFunction)pyg_signal_query, METH_VARARGS|METH_KEYWORDS },
{ "list_properties",
pyg_object_class_list_properties, METH_VARARGS },
{ "new",
diff --git a/gi/overrides/GObject.py b/gi/overrides/GObject.py
index f884af5..30ac542 100644
--- a/gi/overrides/GObject.py
+++ b/gi/overrides/GObject.py
@@ -393,31 +393,34 @@ def signal_lookup(name, type_):
__all__.append('signal_lookup')
+SignalQuery = namedtuple('SignalQuery',
+ ['signal_id',
+ 'signal_name',
+ 'itype',
+ 'signal_flags',
+ 'return_type',
+ # n_params',
+ 'param_types'])
+
+
def signal_query(id_or_name, type_=None):
- SignalQuery = namedtuple('SignalQuery',
- ['signal_id',
- 'signal_name',
- 'itype',
- 'signal_flags',
- 'return_type',
- # n_params',
- 'param_types'])
-
- # signal_query needs to use a static method until the following bugs are fixed:
- # https://bugzilla.gnome.org/show_bug.cgi?id=687550
- # https://bugzilla.gnome.org/show_bug.cgi?id=687545
- # https://bugzilla.gnome.org/show_bug.cgi?id=687541
if type_ is not None:
id_or_name = signal_lookup(id_or_name, type_)
- res = _gobject.signal_query(id_or_name)
+ res = GObjectModule.signal_query(id_or_name)
if res is None:
return None
- # Return a named tuple which allows indexing like the static bindings
- # along with field like access of the gi struct.
- # Note however that the n_params was not returned from the static bindings.
- return SignalQuery(*res)
+ if res.signal_id == 0:
+ return None
+
+ # Return a named tuple to allows indexing which is compatible with the
+ # static bindings along with field like access of the gi struct.
+ # Note however that the n_params was not returned from the static bindings
+ # so we must skip over it.
+ return SignalQuery(res.signal_id, res.signal_name, res.itype,
+ res.signal_flags, res.return_type,
+ tuple(res.param_types))
__all__.append('signal_query')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]