[pygobject] Fix reference sharing of gi sub-modules in Python 2
- From: Simon Feltman <sfeltman src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Fix reference sharing of gi sub-modules in Python 2
- Date: Wed, 15 Jan 2014 20:55:05 +0000 (UTC)
commit 7222a37a4b4955fe6c1dcc86e0eb798d653711e8
Author: Simon Feltman <sfeltman src gnome org>
Date: Wed Jan 15 12:51:57 2014 -0800
Fix reference sharing of gi sub-modules in Python 2
Ensure we add a new reference to sub-modules added to gi._gi. This may
have caused GC errors upon exiting the Python process since a reference was
shared by sys.modules and gi._gi.
https://bugzilla.gnome.org/show_bug.cgi?id=722274
gi/gimodule.c | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
---
diff --git a/gi/gimodule.c b/gi/gimodule.c
index e0d9878..ef3e205 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -643,6 +643,14 @@ PYGLIB_MODULE_START(_gi, "_gi")
if (_glib_module == NULL) {
return PYGLIB_MODULE_ERROR_RETURN;
}
+ /* In Python 2.x, pyglib_..._module_create returns a borrowed reference and
+ * PyModule_AddObject steals a reference. Ensure we don't share a reference
+ * between sys.modules and gi._gi._glib by incrementing the ref count here.
+ * Note that we don't add this to the PYGLIB_MODULE_START macro because that
+ * would cause a leak for the main module gi._gi */
+ if (PY_MAJOR_VERSION < 3) {
+ Py_INCREF (_glib_module);
+ }
PyModule_AddObject (module, "_glib", _glib_module);
PyModule_AddStringConstant(module, "__package__", "gi._gi");
@@ -650,6 +658,9 @@ PYGLIB_MODULE_START(_gi, "_gi")
if (_gobject_module == NULL) {
return PYGLIB_MODULE_ERROR_RETURN;
}
+ if (PY_MAJOR_VERSION < 3) {
+ Py_INCREF (_gobject_module);
+ }
PyModule_AddObject (module, "_gobject", _gobject_module);
PyModule_AddStringConstant(module, "__package__", "gi._gi");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]