diff options
author | Simon Feltman <sfeltman@src.gnome.org> | 2014-01-15 12:51:57 -0800 |
---|---|---|
committer | Simon Feltman <sfeltman@src.gnome.org> | 2014-01-15 12:51:57 -0800 |
commit | 7222a37a4b4955fe6c1dcc86e0eb798d653711e8 (patch) | |
tree | d6adefedafab5093c6bfee53056e68c5985035af | |
parent | 8c838b683220bcbf2091bba97b91ddb56b275aed (diff) | |
download | pygobject-7222a37a4b4955fe6c1dcc86e0eb798d653711e8.tar.gz |
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
-rw-r--r-- | gi/gimodule.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/gi/gimodule.c b/gi/gimodule.c index e0d9878b..ef3e2050 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"); |