summaryrefslogtreecommitdiffstats
path: root/Modules/_io/textio.c
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2012-02-29 23:31:31 (GMT)
committerBrett Cannon <brett@python.org>2012-02-29 23:31:31 (GMT)
commitefb00c0cc189c1fdee329e8b7fdd07b3fd4a54cf (patch)
tree22dc683979e0dd42d049416797b756a5c6a053cd /Modules/_io/textio.c
parent54c32032aa28bdfead50714bf7861c98a9843597 (diff)
downloadcpython-efb00c0cc189c1fdee329e8b7fdd07b3fd4a54cf.zip
cpython-efb00c0cc189c1fdee329e8b7fdd07b3fd4a54cf.tar.gz
cpython-efb00c0cc189c1fdee329e8b7fdd07b3fd4a54cf.tar.bz2
Issue #14153 Create _Py_device_encoding() to prevent _io from having to import
the os module.
Diffstat (limited to 'Modules/_io/textio.c')
-rw-r--r--Modules/_io/textio.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index 79c64ba..833a527 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -14,7 +14,6 @@
_Py_IDENTIFIER(close);
_Py_IDENTIFIER(_dealloc_warn);
_Py_IDENTIFIER(decode);
-_Py_IDENTIFIER(device_encoding);
_Py_IDENTIFIER(fileno);
_Py_IDENTIFIER(flush);
_Py_IDENTIFIER(getpreferredencoding);
@@ -875,9 +874,13 @@ textiowrapper_init(textio *self, PyObject *args, PyObject *kwds)
}
}
else {
- self->encoding = _PyObject_CallMethodId(state->os_module,
- &PyId_device_encoding,
- "N", fileno);
+ int fd = (int) PyLong_AsLong(fileno);
+ Py_DECREF(fileno);
+ if (fd == -1 && PyErr_Occurred()) {
+ goto error;
+ }
+
+ self->encoding = _Py_device_encoding(fd);
if (self->encoding == NULL)
goto error;
else if (!PyUnicode_Check(self->encoding))