From 761a71bb8692ba42c26ed5ef872c4209b20bc470 Mon Sep 17 00:00:00 2001 From: DongHun Kwak Date: Wed, 12 Jul 2017 08:37:54 +0900 Subject: [PATCH] Imported Upstream version 3.0.1 Change-Id: I26a0bcadb4a71ef2c031860ee9d617b250d3a6d7 Signed-off-by: DongHun Kwak --- ChangeLog | 54 +++++++++++++++++++++++++++++++++++++ NEWS | 5 ++++ PKG-INFO | 4 +-- configure | 26 +++++++++--------- configure.ac | 2 +- gi/_gobject/gobjectmodule.c | 37 ++++++++++++++----------- gi/_gobject/pygobject-private.h | 3 +++ gi/_gobject/pygobject.c | 27 ++++++++++++++++++- gi/_gobject/pygobject.h | 3 ++- gi/pygi-marshal-from-py.c | 60 ++++++++++++++++++++++++++++++++++++++--- 10 files changed, 184 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index d307ea4..9bd04d3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,57 @@ +commit 56ac9339eb1d6950623dc4d8c3b9972874e7fa86 +Author: John (J5) Palmieri +Date: Thu Sep 22 19:03:20 2011 -0400 + + when checking instances union members are same type as parent + + * this is so we can support sending Gdk.Event members in place of + the Event union into methods + * we only support this if the union member has a type of GI_INTERFACE + for now + + https://bugzilla.gnome.org/show_bug.cgi?id=659879 + + gi/pygi-marshal-from-py.c | 60 + ++++++++++++++++++++++++++++++++++++++++++--- + 1 files changed, 56 insertions(+), 4 deletions(-) + +commit 311a4f8035a95b41bc3c0a836c32b7a5bf2d9959 +Author: John (J5) Palmieri +Date: Wed Sep 21 21:50:48 2011 -0400 + + add a floating flag to pygobjects + + * this allows us to correctly refcount when custom gobjects are + instantiated + via g_object_new + + gi/_gobject/gobjectmodule.c | 5 +++++ + gi/_gobject/pygobject-private.h | 3 +++ + gi/_gobject/pygobject.c | 27 ++++++++++++++++++++++++++- + gi/_gobject/pygobject.h | 3 ++- + 4 files changed, 36 insertions(+), 2 deletions(-) + +commit d2d29ae5845217254b9336fd8629f369cb119b25 +Author: John (J5) Palmieri +Date: Wed Sep 21 21:13:22 2011 -0400 + + Revert "Fix refcount bug by not creating python wrapper during + gobject init stage" + + This reverts commit f6fa5dd8f39af1b8a52d7600d257400b0983e8c5. + + gi/_gobject/gobjectmodule.c | 32 +++++++++++++++++--------------- + 1 files changed, 17 insertions(+), 15 deletions(-) + +commit a24c10b779f2a1b0425d56d03d59c393389cad98 +Author: John (J5) Palmieri +Date: Wed Sep 21 21:10:00 2011 -0400 + + make sure to commit the NEWS file + + NEWS | 4 ++++ + 1 files changed, 4 insertions(+), 0 deletions(-) + commit 2eed2940c9be099fb6305288d895265e6b35d3d2 Author: John (J5) Palmieri Date: Mon Sep 19 13:19:57 2011 -0400 diff --git a/NEWS b/NEWS index 2a8cf08..d3792f1 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ +3.0.1 30-Sep-2011 + - when checking instances union members are same type as parent + - add a floating flag to pygobjects + - Revert "Fix refcount bug by not creating python wrapper during gobject init stage" + 3.0.0 19-Sep-2011 - up version required of gobject-introspection to 1.29.0 (John (J5) Palmieri) - fix most warnings (John (J5) Palmieri) diff --git a/PKG-INFO b/PKG-INFO index 4b92ae8..4c1a946 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: PyGObject -Version: 3.0.0 +Version: 3.0.1 Summary: Python bindings for GObject Home-page: http://www.pygtk.org/ Author: James Henstridge @@ -8,7 +8,7 @@ Author-email: james@daa.com.au Maintainer: Johan Dahlin Maintainer-email: johan@gnome.org License: GNU LGPL -Download-url: ftp://ftp.gnome.org/pub/GNOME/sources/pygobject/3.0/pygobject-3.0.0.tar.gz +Download-url: ftp://ftp.gnome.org/pub/GNOME/sources/pygobject/3.0/pygobject-3.0.1.tar.gz Description: Python bindings for GLib and GObject Platform: POSIX, Windows Classifier: Development Status :: 5 - Production/Stable diff --git a/configure b/configure index c09caab..57590f5 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.68 for pygobject 3.0.0. +# Generated by GNU Autoconf 2.68 for pygobject 3.0.1. # # Report bugs to . # @@ -571,8 +571,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='pygobject' PACKAGE_TARNAME='pygobject' -PACKAGE_VERSION='3.0.0' -PACKAGE_STRING='pygobject 3.0.0' +PACKAGE_VERSION='3.0.1' +PACKAGE_STRING='pygobject 3.0.1' PACKAGE_BUGREPORT='http://bugzilla.gnome.org/enter_bug.cgi?product=pygobject' PACKAGE_URL='' @@ -1358,7 +1358,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures pygobject 3.0.0 to adapt to many kinds of systems. +\`configure' configures pygobject 3.0.1 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1428,7 +1428,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of pygobject 3.0.0:";; + short | recursive ) echo "Configuration of pygobject 3.0.1:";; esac cat <<\_ACEOF @@ -1553,7 +1553,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -pygobject configure 3.0.0 +pygobject configure 3.0.1 generated by GNU Autoconf 2.68 Copyright (C) 2010 Free Software Foundation, Inc. @@ -1831,7 +1831,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by pygobject $as_me 3.0.0, which was +It was created by pygobject $as_me 3.0.1, which was generated by GNU Autoconf 2.68. Invocation command line was $ $0 $@ @@ -2195,9 +2195,9 @@ $as_echo "#define PYGOBJECT_MINOR_VERSION 0" >>confdefs.h PYGOBJECT_MINOR_VERSION=0 -$as_echo "#define PYGOBJECT_MICRO_VERSION 0" >>confdefs.h +$as_echo "#define PYGOBJECT_MICRO_VERSION 1" >>confdefs.h -PYGOBJECT_MICRO_VERSION=0 +PYGOBJECT_MICRO_VERSION=1 ac_config_headers="$ac_config_headers config.h" @@ -2681,7 +2681,7 @@ fi # Define the identity of the package. PACKAGE='pygobject' - VERSION='3.0.0' + VERSION='3.0.1' cat >>confdefs.h <<_ACEOF @@ -12017,7 +12017,7 @@ Usage: $0 [OPTIONS] Report bugs to ." lt_cl_version="\ -pygobject config.lt 3.0.0 +pygobject config.lt 3.0.1 configured by $0, generated by GNU Autoconf 2.68. Copyright (C) 2010 Free Software Foundation, Inc. @@ -16723,7 +16723,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by pygobject $as_me 3.0.0, which was +This file was extended by pygobject $as_me 3.0.1, which was generated by GNU Autoconf 2.68. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -16789,7 +16789,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -pygobject config.status 3.0.0 +pygobject config.status 3.0.1 configured by $0, generated by GNU Autoconf 2.68, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index 8946b85..937c13f 100644 --- a/configure.ac +++ b/configure.ac @@ -12,7 +12,7 @@ m4_define(python3_min_ver, 3.1) dnl the pygobject version number m4_define(pygobject_major_version, 3) m4_define(pygobject_minor_version, 0) -m4_define(pygobject_micro_version, 0) +m4_define(pygobject_micro_version, 1) m4_define(pygobject_version, pygobject_major_version.pygobject_minor_version.pygobject_micro_version) dnl versions of packages we require ... diff --git a/gi/_gobject/gobjectmodule.c b/gi/_gobject/gobjectmodule.c index ffa323b..ac065a5 100644 --- a/gi/_gobject/gobjectmodule.c +++ b/gi/_gobject/gobjectmodule.c @@ -1048,7 +1048,7 @@ pygobject__g_instance_init(GTypeInstance *instance, gpointer g_class) { GObject *object = (GObject *) instance; - PyObject *wrapper; + PyObject *wrapper, *args, *kwargs; wrapper = g_object_get_qdata(object, pygobject_wrapper_key); if (wrapper == NULL) { @@ -1059,6 +1059,27 @@ pygobject__g_instance_init(GTypeInstance *instance, } } pygobject_init_wrapper_set(NULL); + if (wrapper == NULL) { + /* this looks like a python object created through + * g_object_new -> we have no python wrapper, so create it + * now */ + PyGILState_STATE state; + state = pyglib_gil_state_ensure(); + wrapper = pygobject_new_full(object, FALSE, g_class); + + /* float the wrapper ref here because we are going to orphan it + * so we don't destroy the wrapper. The next call to pygobject_new_full + * will take the ref */ + pygobject_ref_float (wrapper); + args = PyTuple_New(0); + kwargs = PyDict_New(); + if (Py_TYPE(wrapper)->tp_init(wrapper, args, kwargs)) + PyErr_Print(); + + Py_DECREF(args); + Py_DECREF(kwargs); + pyglib_gil_state_release(state); + } } @@ -1730,22 +1751,8 @@ pyg_object_new (PyGObject *self, PyObject *args, PyObject *kwargs) g_type_class_unref(class); if (obj) { - PyObject *empty_args; - PyObject *empty_kwargs; - PyGILState_STATE state; - pygobject_sink (obj); self = (PyGObject *) pygobject_new_full((GObject *)obj, FALSE, NULL); - empty_args = PyTuple_New(0); - empty_kwargs = PyDict_New(); - - state = pyglib_gil_state_ensure(); - if (Py_TYPE(self)->tp_init((PyObject *)self, empty_args, empty_kwargs)) - PyErr_Print(); - pyglib_gil_state_release(state); - - Py_DECREF(empty_args); - Py_DECREF(empty_kwargs); g_object_unref(obj); } else self = NULL; diff --git a/gi/_gobject/pygobject-private.h b/gi/_gobject/pygobject-private.h index dabf0a4..1b1d6db 100644 --- a/gi/_gobject/pygobject-private.h +++ b/gi/_gobject/pygobject-private.h @@ -96,6 +96,9 @@ PyObject *pyg_integer_richcompare(PyObject *v, gboolean pyg_gerror_exception_check(GError **error); +void pygobject_ref_float(PyGObject *self); +void pygobject_ref_sink(PyGObject *self); + /* from pygtype.h */ extern PyTypeObject PyGTypeWrapper_Type; diff --git a/gi/_gobject/pygobject.c b/gi/_gobject/pygobject.c index 48a9f18..0f0e5e2 100644 --- a/gi/_gobject/pygobject.c +++ b/gi/_gobject/pygobject.c @@ -560,6 +560,31 @@ pygobject_switch_to_toggle_ref(PyGObject *self) g_object_unref(self->obj); } +/* Called when an custom gobject is initalized via g_object_new instead of + its constructor. The next time the wrapper is access via + pygobject_new_full it will sink the floating reference instead of + adding a new reference and causing a leak */ + +void +pygobject_ref_float(PyGObject *self) +{ + /* should only be floated once */ + g_assert(!(self->private_flags.flags & PYGOBJECT_IS_FLOATING_REF)); + + self->private_flags.flags |= PYGOBJECT_IS_FLOATING_REF; +} + +/* Called by gobject_new_full, if the floating flag is set remove it, otherwise + ref the pyobject */ +void +pygobject_ref_sink(PyGObject *self) +{ + if (self->private_flags.flags & PYGOBJECT_IS_FLOATING_REF) + self->private_flags.flags &= ~PYGOBJECT_IS_FLOATING_REF; + else + Py_INCREF ( (PyObject *) self); +} + /** * pygobject_register_wrapper: * @self: the wrapper instance @@ -888,7 +913,7 @@ pygobject_new_full(GObject *obj, gboolean sink, gpointer g_class) /* we already have a wrapper for this object -- return it. */ self = (PyGObject *)g_object_get_qdata(obj, pygobject_wrapper_key); if (self != NULL) { - Py_INCREF(self); + pygobject_ref_sink(self); } else { /* create wrapper */ PyGObjectData *inst_data = pyg_object_peek_inst_data(obj); diff --git a/gi/_gobject/pygobject.h b/gi/_gobject/pygobject.h index f728e15..8879fd0 100644 --- a/gi/_gobject/pygobject.h +++ b/gi/_gobject/pygobject.h @@ -23,7 +23,8 @@ struct _PyGClosure { }; typedef enum { - PYGOBJECT_USING_TOGGLE_REF = 1 << 0 + PYGOBJECT_USING_TOGGLE_REF = 1 << 0, + PYGOBJECT_IS_FLOATING_REF = 1 << 1 } PyGObjectFlags; /* closures is just an alias for what is found in the diff --git a/gi/pygi-marshal-from-py.c b/gi/pygi-marshal-from-py.c index fa74a22..b78cfe3 100644 --- a/gi/pygi-marshal-from-py.c +++ b/gi/pygi-marshal-from-py.c @@ -1416,10 +1416,62 @@ gboolean _pygi_marshal_from_py_interface_instance (PyGIInvokeState *state, GType type = iface_cache->g_type; if (!PyObject_IsInstance (py_arg, iface_cache->py_type)) { - PyErr_Format (PyExc_TypeError, "Expected a %s, but got %s", - iface_cache->type_name, - py_arg->ob_type->tp_name); - return FALSE; + /* wait, we might be a member of a union so manually check */ + if (info_type == GI_INFO_TYPE_UNION) { + gint i; + gint n_fields; + gboolean is_member = FALSE; + GIUnionInfo *union_info = (GIUnionInfo *) iface_cache->interface_info; + + n_fields = g_union_info_get_n_fields (union_info); + + for (i = 0; i < n_fields; i++) { + GIFieldInfo *field_info; + GITypeInfo *field_type_info; + + field_info = g_union_info_get_field (union_info, i); + field_type_info = g_field_info_get_type (field_info); + + /* we can only check if the members are interfaces */ + if (g_type_info_get_tag (field_type_info) == + GI_TYPE_TAG_INTERFACE) { + PyObject *py_type; + GIInterfaceInfo *field_iface_info = + g_type_info_get_interface(field_type_info); + + py_type = _pygi_type_import_by_gi_info ( + (GIBaseInfo *) field_iface_info); + + if (PyObject_IsInstance (py_arg, py_type)) { + is_member = TRUE; + break; + } + + Py_XDECREF (py_type); + g_base_info_unref ( ( GIBaseInfo *) field_iface_info); + + } + + g_base_info_unref ( ( GIBaseInfo *) field_type_info); + g_base_info_unref ( ( GIBaseInfo *) field_info); + + if (is_member) + break; + } + + if (!is_member) { + PyErr_Format (PyExc_TypeError, + "Expected a %s, but got %s", + iface_cache->type_name, + py_arg->ob_type->tp_name); + return FALSE; + } + } else { + PyErr_Format (PyExc_TypeError, "Expected a %s, but got %s", + iface_cache->type_name, + py_arg->ob_type->tp_name); + return FALSE; + } } if (g_type_is_a (type, G_TYPE_BOXED)) { -- 2.7.4