summaryrefslogtreecommitdiffstats
path: root/Modules/_io/_iomodule.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-08-01 19:04:50 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2013-08-01 19:04:50 (GMT)
commit932ff8368289b53c4ca37167747bb71d146fc6ea (patch)
tree31f508a77d07676df88535e20bfe555eb662f0a2 /Modules/_io/_iomodule.c
parent2d350fd8af29eada0c3f264a91df6ab4af4a05fd (diff)
downloadcpython-932ff8368289b53c4ca37167747bb71d146fc6ea.zip
cpython-932ff8368289b53c4ca37167747bb71d146fc6ea.tar.gz
cpython-932ff8368289b53c4ca37167747bb71d146fc6ea.tar.bz2
Issue #18608: Avoid keeping a strong reference to the locale module inside the _io module.
Diffstat (limited to 'Modules/_io/_iomodule.c')
-rw-r--r--Modules/_io/_iomodule.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c
index 4a7e758..14457e8 100644
--- a/Modules/_io/_iomodule.c
+++ b/Modules/_io/_iomodule.c
@@ -533,6 +533,31 @@ _PyIO_ConvertSsize_t(PyObject *obj, void *result) {
}
+PyObject *
+_PyIO_get_locale_module(_PyIO_State *state)
+{
+ PyObject *mod;
+ if (state->locale_module != NULL) {
+ assert(PyWeakref_CheckRef(state->locale_module));
+ mod = PyWeakref_GET_OBJECT(state->locale_module);
+ if (mod != Py_None) {
+ Py_INCREF(mod);
+ return mod;
+ }
+ Py_CLEAR(state->locale_module);
+ }
+ mod = PyImport_ImportModule("locale");
+ if (mod == NULL)
+ return NULL;
+ state->locale_module = PyWeakref_NewRef(mod, NULL);
+ if (state->locale_module == NULL) {
+ Py_DECREF(mod);
+ return NULL;
+ }
+ return mod;
+}
+
+
static int
iomodule_traverse(PyObject *mod, visitproc visit, void *arg) {
_PyIO_State *state = IO_MOD_STATE(mod);