diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-07-12 08:36:58 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-07-12 08:37:00 +0900 |
commit | 188514abf089f6c3bf73469e83525f3519f15ede (patch) | |
tree | aef6a890adbf5572bf779c92fe98cb69b2b34636 /gi | |
parent | dd20fe51cd566c8c20bcbb96901c766a385d0a11 (diff) | |
download | pygobject2-188514abf089f6c3bf73469e83525f3519f15ede.tar.gz pygobject2-188514abf089f6c3bf73469e83525f3519f15ede.tar.bz2 pygobject2-188514abf089f6c3bf73469e83525f3519f15ede.zip |
Imported Upstream version 2.28.6upstream/2.28.6
Change-Id: Ic975e9ed81a8d0c60fea3fadf17e4172a6c19009
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'gi')
-rw-r--r-- | gi/gimodule.c | 6 | ||||
-rw-r--r-- | gi/module.py | 13 | ||||
-rw-r--r-- | gi/overrides/GLib.py | 14 | ||||
-rw-r--r-- | gi/overrides/Gdk.py | 6 | ||||
-rw-r--r-- | gi/pygi-argument.c | 10 | ||||
-rw-r--r-- | gi/pygi-closure.c | 15 | ||||
-rw-r--r-- | gi/pygi-foreign-cairo.c | 18 | ||||
-rw-r--r-- | gi/pygi-foreign-gvariant.c | 15 | ||||
-rw-r--r-- | gi/pygi-foreign-gvariant.h | 14 | ||||
-rw-r--r-- | gi/pygi-foreign.c | 21 | ||||
-rw-r--r-- | gi/pygi-foreign.h | 16 | ||||
-rw-r--r-- | gi/pygi-invoke.c | 26 |
12 files changed, 102 insertions, 72 deletions
diff --git a/gi/gimodule.c b/gi/gimodule.c index 2c4c335..5ef166f 100644 --- a/gi/gimodule.c +++ b/gi/gimodule.c @@ -475,8 +475,10 @@ _wrap_pyg_variant_type_from_string (PyObject *self, PyObject *args) py_type = _pygi_type_import_by_name ("GLib", "VariantType"); - py_variant = _pygi_struct_new ( (PyTypeObject *) py_type, type_string, FALSE); - + if (PyType_IsSubtype (py_type, &PyGIBoxed_Type)) + py_variant = _pygi_boxed_new ( (PyTypeObject *) py_type, type_string, FALSE); + else + py_variant = _pygi_struct_new ( (PyTypeObject *) py_type, type_string, FALSE); return py_variant; } diff --git a/gi/module.py b/gi/module.py index 3e2b59e..70df76c 100644 --- a/gi/module.py +++ b/gi/module.py @@ -24,6 +24,7 @@ from __future__ import absolute_import import os import gobject +import string import gi from .overrides import registry @@ -120,8 +121,14 @@ class IntrospectionModule(object): wrapper.__info__ = info wrapper.__module__ = 'gi.repository.' + info.get_namespace() + # Don't use upper() here to avoid locale specific + # identifier conversion (e. g. in Turkish 'i'.upper() == 'i') + # see https://bugzilla.gnome.org/show_bug.cgi?id=649165 + ascii_upper_trans = string.maketrans( + 'abcdefgjhijklmnopqrstuvwxyz', + 'ABCDEFGJHIJKLMNOPQRSTUVWXYZ') for value_info in info.get_values(): - value_name = value_info.get_name().upper() + value_name = value_info.get_name().translate(ascii_upper_trans) setattr(wrapper, value_name, wrapper(value_info.get_value())) if g_type != gobject.TYPE_NONE: @@ -150,7 +157,9 @@ class IntrospectionModule(object): elif isinstance(info, (StructInfo, UnionInfo)): if g_type.is_a(gobject.TYPE_BOXED): bases = (Boxed,) - elif g_type.is_a(gobject.TYPE_POINTER) or g_type == gobject.TYPE_NONE: + elif g_type.is_a(gobject.TYPE_POINTER) or \ + g_type == gobject.TYPE_NONE or \ + g_type.fundamental == g_type: bases = (Struct,) else: raise TypeError("unable to create a wrapper for %s.%s" % (info.get_namespace(), info.get_name())) diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py index ad9f235..2caf205 100644 --- a/gi/overrides/GLib.py +++ b/gi/overrides/GLib.py @@ -25,6 +25,17 @@ GLib = modules['GLib']._introspection_module __all__ = [] +def _create_variant(value): + '''Create a variant containing the variant "value". + + This is usually done with the GLib.Variant.new_variant() leaf + constructor, but this is currently broken, see GNOME#639952. + ''' + builder = GLib.VariantBuilder() + builder.init(variant_type_from_string('v')) + builder.add_value(value) + return builder.end() + class _VariantCreator(object): _LEAF_CONSTRUCTORS = { @@ -41,7 +52,8 @@ class _VariantCreator(object): 's': GLib.Variant.new_string, 'o': GLib.Variant.new_object_path, 'g': GLib.Variant.new_signature, - 'v': GLib.Variant.new_variant, + #'v': GLib.Variant.new_variant, + 'v': _create_variant, } def _create(self, format, args): diff --git a/gi/overrides/Gdk.py b/gi/overrides/Gdk.py index e346f55..7b86e1f 100644 --- a/gi/overrides/Gdk.py +++ b/gi/overrides/Gdk.py @@ -39,6 +39,9 @@ class Color(Gdk.Color): def __new__(cls, *args, **kwargs): return Gdk.Color.__new__(cls) + def __eq__(self, other): + return self.equal(other) + def __repr__(self): return '<Gdk.Color(red=%d, green=%d, blue=%d)>' % (self.red, self.green, self.blue) @@ -57,6 +60,9 @@ if Gdk._version == '3.0': def __new__(cls, *args, **kwargs): return Gdk.RGBA.__new__(cls) + def __eq__(self, other): + return self.equal(other) + def __repr__(self): return '<Gdk.Color(red=%f, green=%f, blue=%f, alpha=%f)>' % (self.red, self.green, self.blue, self.alpha) diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c index ad02ff7..a9b5b60 100644 --- a/gi/pygi-argument.c +++ b/gi/pygi-argument.c @@ -1084,15 +1084,15 @@ array_success: } arg.v_pointer = closure; + } else if (g_struct_info_is_foreign (info)) { + PyObject *result; + result = pygi_struct_foreign_convert_to_g_argument ( + object, info, transfer, &arg); } else if (g_type_is_a (type, G_TYPE_BOXED)) { arg.v_pointer = pyg_boxed_get (object, void); if (transfer == GI_TRANSFER_EVERYTHING) { arg.v_pointer = g_boxed_copy (type, arg.v_pointer); } - } else if ( (type == G_TYPE_NONE) && (g_struct_info_is_foreign (info))) { - PyObject *result; - result = pygi_struct_foreign_convert_to_g_argument ( - object, type_info, transfer, &arg); } else if (g_type_is_a (type, G_TYPE_POINTER) || type == G_TYPE_NONE) { g_warn_if_fail (!g_type_info_is_pointer (type_info) || transfer == GI_TRANSFER_NOTHING); arg.v_pointer = pyg_pointer_get (object, void); @@ -1581,7 +1581,7 @@ _pygi_argument_to_object (GIArgument *arg, if (g_type_is_a (type, G_TYPE_VALUE)) { object = pyg_value_as_pyobject (arg->v_pointer, FALSE); } else if (g_struct_info_is_foreign (info)) { - object = pygi_struct_foreign_convert_from_g_argument (type_info, arg->v_pointer); + object = pygi_struct_foreign_convert_from_g_argument (info, arg->v_pointer); } else if (g_type_is_a (type, G_TYPE_BOXED)) { PyObject *py_type; diff --git a/gi/pygi-closure.c b/gi/pygi-closure.c index 56ddc8b..35281a2 100644 --- a/gi/pygi-closure.c +++ b/gi/pygi-closure.c @@ -35,6 +35,9 @@ _pygi_closure_assign_pyobj_to_out_argument (gpointer out_arg, PyObject *object, GIArgument arg = _pygi_argument_from_object (object, type_info, transfer); GITypeTag type_tag = g_type_info_get_tag (type_info); + if (out_arg == NULL) + return; + switch (type_tag) { case GI_TYPE_TAG_BOOLEAN: *((gboolean *) out_arg) = arg.v_boolean; @@ -250,12 +253,9 @@ _pygi_closure_convert_arguments (GICallableInfo *callable_info, void **args, error: Py_CLEAR (*py_args); - - if (*out_args != NULL) - g_free (*out_args); - - if (g_args != NULL) - g_free (g_args); + g_free (*out_args); + *out_args = NULL; + g_free (g_args); return FALSE; } @@ -364,8 +364,7 @@ _pygi_closure_handle (ffi_cif *cif, _pygi_closure_set_out_arguments (closure->info, retval, out_args, result); end: - if (out_args != NULL) - g_free (out_args); + g_free (out_args); g_base_info_unref ( (GIBaseInfo*) return_type); PyGILState_Release (state); diff --git a/gi/pygi-foreign-cairo.c b/gi/pygi-foreign-cairo.c index 0264b71..e332a22 100644 --- a/gi/pygi-foreign-cairo.c +++ b/gi/pygi-foreign-cairo.c @@ -37,9 +37,9 @@ Pycairo_CAPI_t *Pycairo_CAPI; #include <pyglib-python-compat.h> PyObject * -cairo_context_to_arg (PyObject *value, - GITypeInfo *type_info, - GITransfer transfer, +cairo_context_to_arg (PyObject *value, + GIInterfaceInfo *iface_info, + GITransfer transfer, GIArgument *arg) { cairo_t *cr; @@ -56,7 +56,8 @@ cairo_context_to_arg (PyObject *value, } PyObject * -cairo_context_from_arg (GITypeInfo *type_info, gpointer data) +cairo_context_from_arg (GIInterfaceInfo *iface_info, + gpointer data) { cairo_t *context = (cairo_t*) data; @@ -75,9 +76,9 @@ cairo_context_release (GIBaseInfo *base_info, PyObject * -cairo_surface_to_arg (PyObject *value, - GITypeInfo *type_info, - GITransfer transfer, +cairo_surface_to_arg (PyObject *value, + GIInterfaceInfo *iface_info, + GITransfer transfer, GIArgument *arg) { cairo_surface_t *surface; @@ -95,7 +96,8 @@ cairo_surface_to_arg (PyObject *value, } PyObject * -cairo_surface_from_arg (GITypeInfo *type_info, gpointer data) +cairo_surface_from_arg (GIInterfaceInfo *iface_info, + gpointer data) { cairo_surface_t *surface = (cairo_surface_t*) data; diff --git a/gi/pygi-foreign-gvariant.c b/gi/pygi-foreign-gvariant.c index 3c8ae8d..9249d44 100644 --- a/gi/pygi-foreign-gvariant.c +++ b/gi/pygi-foreign-gvariant.c @@ -27,9 +27,9 @@ #include "pygi-foreign-gvariant.h" PyObject * -g_variant_to_arg (PyObject *value, - GITypeInfo *type_info, - GITransfer transfer, +g_variant_to_arg (PyObject *value, + GIInterfaceInfo *type_info, + GITransfer transfer, GIArgument *arg) { g_assert (transfer == GI_TRANSFER_NOTHING); @@ -41,12 +41,11 @@ g_variant_to_arg (PyObject *value, } PyObject * -g_variant_from_arg (GITypeInfo *type_info, - gpointer data) +g_variant_from_arg (GIInterfaceInfo *iface_info, + gpointer data) { GVariant *variant = (GVariant *) data; - GITypeInfo *interface_info = g_type_info_get_interface (type_info); - PyObject *type = _pygi_type_import_by_gi_info (interface_info); + PyObject *type = _pygi_type_import_by_gi_info (iface_info); g_variant_ref_sink (variant); @@ -55,7 +54,7 @@ g_variant_from_arg (GITypeInfo *type_info, PyObject * g_variant_release_foreign (GIBaseInfo *base_info, - gpointer struct_) + gpointer struct_) { g_variant_unref ( (GVariant *) struct_); Py_RETURN_NONE; diff --git a/gi/pygi-foreign-gvariant.h b/gi/pygi-foreign-gvariant.h index b0c9781..8ebc4cd 100644 --- a/gi/pygi-foreign-gvariant.h +++ b/gi/pygi-foreign-gvariant.h @@ -26,14 +26,12 @@ #include "pygi-foreign.h" -PyObject *g_variant_to_arg(PyObject *value, - GITypeInfo *type_info, - GITransfer transfer, - GIArgument *arg); - -PyObject *g_variant_from_arg(GITypeInfo *type_info, - gpointer data); - +PyObject *g_variant_to_arg (PyObject *value, + GIInterfaceInfo *iface_info, + GITransfer transfer, + GIArgument *arg); +PyObject *g_variant_from_arg (GIInterfaceInfo *iface_info, + gpointer data); PyObject *g_variant_release_foreign (GIBaseInfo *base_info, gpointer struct_); diff --git a/gi/pygi-foreign.c b/gi/pygi-foreign.c index 5c9a88a..eafaca3 100644 --- a/gi/pygi-foreign.c +++ b/gi/pygi-foreign.c @@ -107,37 +107,34 @@ pygi_struct_foreign_lookup (GIBaseInfo *base_info) } PyObject * -pygi_struct_foreign_convert_to_g_argument (PyObject *value, - GITypeInfo *type_info, - GITransfer transfer, +pygi_struct_foreign_convert_to_g_argument (PyObject *value, + GIInterfaceInfo *iface_info, + GITransfer transfer, GIArgument *arg) { - GIBaseInfo *base_info = g_type_info_get_interface (type_info); + GIBaseInfo *base_info = (GIBaseInfo *) iface_info; PyGIForeignStruct *foreign_struct = pygi_struct_foreign_lookup (base_info); - g_base_info_unref (base_info); if (foreign_struct == NULL) return NULL; - if (!foreign_struct->to_func (value, type_info, transfer, arg)) + if (!foreign_struct->to_func (value, iface_info, transfer, arg)) return NULL; Py_RETURN_NONE; } PyObject * -pygi_struct_foreign_convert_from_g_argument (GITypeInfo *type_info, - GIArgument *arg) +pygi_struct_foreign_convert_from_g_argument (GIInterfaceInfo *iface_info, + GIArgument *arg) { - GIBaseInfo *base_info = g_type_info_get_interface (type_info); + GIBaseInfo *base_info = (GIBaseInfo *) iface_info; PyGIForeignStruct *foreign_struct = pygi_struct_foreign_lookup (base_info); - g_base_info_unref (base_info); - if (foreign_struct == NULL) return NULL; - return foreign_struct->from_func (type_info, arg); + return foreign_struct->from_func (iface_info, arg); } PyObject * diff --git a/gi/pygi-foreign.h b/gi/pygi-foreign.h index b57f892..b07f682 100644 --- a/gi/pygi-foreign.h +++ b/gi/pygi-foreign.h @@ -30,14 +30,14 @@ #include "pygi.h" -PyObject *pygi_struct_foreign_convert_to_g_argument (PyObject *value, - GITypeInfo *type_info, - GITransfer transfer, - GIArgument *arg); -PyObject *pygi_struct_foreign_convert_from_g_argument (GITypeInfo *type_info, - GIArgument *arg); -PyObject *pygi_struct_foreign_release (GITypeInfo *type_info, - gpointer struct_); +PyObject *pygi_struct_foreign_convert_to_g_argument (PyObject *value, + GIInterfaceInfo *iface_info, + GITransfer transfer, + GIArgument *arg); +PyObject *pygi_struct_foreign_convert_from_g_argument (GIInterfaceInfo *iface_info, + GIArgument *arg); +PyObject *pygi_struct_foreign_release (GIBaseInfo *base_info, + gpointer struct_); void pygi_register_foreign_struct_real (const char* namespace_, const char* name, diff --git a/gi/pygi-invoke.c b/gi/pygi-invoke.c index 78984e5..f9e09bb 100644 --- a/gi/pygi-invoke.c +++ b/gi/pygi-invoke.c @@ -378,19 +378,19 @@ _prepare_invocation_state (struct invocation_state *state, /* if caller allocates only use one level of indirection */ state->out_args[out_args_pos].v_pointer = NULL; state->args[i] = &state->out_args[out_args_pos]; - if (g_type_is_a (g_registered_type_info_get_g_type (info), G_TYPE_BOXED)) { - state->args[i]->v_pointer = _pygi_boxed_alloc (info, NULL); - } else if (g_struct_info_is_foreign((GIStructInfo *) info) ) { + if (g_struct_info_is_foreign((GIStructInfo *) info) ) { PyObject *foreign_struct = - pygi_struct_foreign_convert_from_g_argument(state->arg_type_infos[i], NULL); + pygi_struct_foreign_convert_from_g_argument(info, NULL); pygi_struct_foreign_convert_to_g_argument( foreign_struct, - state->arg_type_infos[i], + info, GI_TRANSFER_EVERYTHING, state->args[i]); Py_DECREF(foreign_struct); + } else if (g_type_is_a (g_registered_type_info_get_g_type (info), G_TYPE_BOXED)) { + state->args[i]->v_pointer = _pygi_boxed_alloc (info, NULL); } else { gssize size = g_struct_info_get_size ( (GIStructInfo *) info); state->args[i]->v_pointer = g_malloc0 (size); @@ -457,6 +457,12 @@ _prepare_invocation_state (struct invocation_state *state, if (g_type_is_a (type, G_TYPE_BOXED)) { g_assert (state->n_in_args > 0); state->in_args[0].v_pointer = pyg_boxed_get (py_arg, void); + } else if (g_struct_info_is_foreign (container_info)) { + PyObject *result; + result = pygi_struct_foreign_convert_to_g_argument ( + py_arg, container_info, + GI_TRANSFER_NOTHING, + &state->in_args[0]); } else if (g_type_is_a (type, G_TYPE_POINTER) || type == G_TYPE_NONE) { g_assert (state->n_in_args > 0); state->in_args[0].v_pointer = pyg_pointer_get (py_arg, void); @@ -688,13 +694,13 @@ _process_invocation_state (struct invocation_state *state, type = g_registered_type_info_get_g_type ( (GIRegisteredTypeInfo *) info); - if (g_type_is_a (type, G_TYPE_BOXED)) { - g_warn_if_fail (transfer == GI_TRANSFER_EVERYTHING); - state->return_value = _pygi_boxed_new (py_type, state->return_arg.v_pointer, transfer == GI_TRANSFER_EVERYTHING); - } else if (type == G_TYPE_NONE && g_struct_info_is_foreign (info)) { + if (g_struct_info_is_foreign (info)) { state->return_value = pygi_struct_foreign_convert_from_g_argument ( - state->return_type_info, state->return_arg.v_pointer); + info, state->return_arg.v_pointer); + } else if (g_type_is_a (type, G_TYPE_BOXED)) { + g_warn_if_fail (transfer == GI_TRANSFER_EVERYTHING); + state->return_value = _pygi_boxed_new (py_type, state->return_arg.v_pointer, transfer == GI_TRANSFER_EVERYTHING); } else if (g_type_is_a (type, G_TYPE_POINTER) || type == G_TYPE_NONE) { if (transfer != GI_TRANSFER_NOTHING) g_warning ("Return argument in %s returns a struct " |