[pygobject] Replace statically bound GLib.Variant.new_tuple() with GI



commit 4d0ab13a8461f781986accc637fada3909cfb91a
Author: Simon Feltman <sfeltman src gnome org>
Date:   Thu Aug 21 15:11:39 2014 -0700

    Replace statically bound GLib.Variant.new_tuple() with GI
    
    Remove the static implementation of _wrap_pyg_variant_new_tuple with
    usage of the dynamic version coming from GI. Array marshalling has
    drastically improved in recent years making the dynamic version usable
    with a small compatibility shim for the arguments.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=735199

 gi/gimodule.c        |   39 ---------------------------------------
 gi/overrides/GLib.py |   12 +++++-------
 2 files changed, 5 insertions(+), 46 deletions(-)
---
diff --git a/gi/gimodule.c b/gi/gimodule.c
index a18c477..de9b787 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -470,44 +470,6 @@ _wrap_pyg_has_vfunc_implementation (PyObject *self, PyObject *args)
 #endif
 
 static PyObject *
-_wrap_pyg_variant_new_tuple (PyObject *self, PyObject *args)
-{
-    PyObject *py_values;
-    GVariant **values = NULL;
-    GVariant *variant = NULL;
-    PyObject *py_variant = NULL;
-    PyObject *py_type;
-    gssize i;
-
-    if (!PyArg_ParseTuple (args, "O!:variant_new_tuple",
-                           &PyTuple_Type, &py_values)) {
-        return NULL;
-    }
-
-    py_type = _pygi_type_import_by_name ("GLib", "Variant");
-
-    values = g_newa (GVariant*, PyTuple_Size (py_values));
-
-    for (i = 0; i < PyTuple_Size (py_values); i++) {
-        PyObject *value = PyTuple_GET_ITEM (py_values, i);
-
-        if (!PyObject_IsInstance (value, py_type)) {
-            PyErr_Format (PyExc_TypeError, "argument %" G_GSSIZE_FORMAT " is not a GLib.Variant", i);
-            return NULL;
-        }
-
-        values[i] = pyg_pointer_get (value, GVariant);
-    }
-
-    variant = g_variant_new_tuple (values, PyTuple_Size (py_values));
-    g_variant_ref_sink (variant);
-
-    py_variant = _pygi_struct_new ( (PyTypeObject *) py_type, variant, FALSE);
-
-    return py_variant;
-}
-
-static PyObject *
 _wrap_pyg_variant_type_from_string (PyObject *self, PyObject *args)
 {
     char *type_string;
@@ -617,7 +579,6 @@ static PyMethodDef _gi_functions[] = {
 
     { "register_interface_info", (PyCFunction) _wrap_pyg_register_interface_info, METH_VARARGS },
     { "hook_up_vfunc_implementation", (PyCFunction) _wrap_pyg_hook_up_vfunc_implementation, METH_VARARGS },
-    { "variant_new_tuple", (PyCFunction) _wrap_pyg_variant_new_tuple, METH_VARARGS },
     { "variant_type_from_string", (PyCFunction) _wrap_pyg_variant_type_from_string, METH_VARARGS },
     { "source_new", (PyCFunction) _wrap_pyg_source_new, METH_NOARGS },
     { "source_set_callback", (PyCFunction) pyg_source_set_callback, METH_VARARGS },
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py
index e72ed36..ce15da1 100644
--- a/gi/overrides/GLib.py
+++ b/gi/overrides/GLib.py
@@ -24,7 +24,7 @@ import warnings
 import sys
 
 from ..module import get_introspection_module
-from .._gi import (variant_new_tuple, variant_type_from_string, source_new,
+from .._gi import (variant_type_from_string, source_new,
                    source_set_callback, io_channel_read)
 from ..overrides import override, deprecated
 from gi import PyGIDeprecationWarning, version_info
@@ -243,6 +243,10 @@ class Variant(GLib.Variant):
         v.format_string = format_string
         return v
 
+    @staticmethod
+    def new_tuple(*elements):
+        return GLib.Variant.new_tuple(elements)
+
     def __del__(self):
         self.unref()
 
@@ -457,16 +461,10 @@ class Variant(GLib.Variant):
         return res
 
 
- classmethod
-def new_tuple(cls, *elements):
-    return variant_new_tuple(elements)
-
-
 def get_string(self):
     value, length = GLib.Variant.get_string(self)
     return value
 
-setattr(Variant, 'new_tuple', new_tuple)
 setattr(Variant, 'get_string', get_string)
 
 __all__.append('Variant')


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