summaryrefslogtreecommitdiffstats
path: root/Modules/_io/_iomodule.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-06-30 00:07:28 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2014-06-30 00:07:28 (GMT)
commitde68722ca06615692613148b7015b3c62cd043c3 (patch)
tree40ee136de88cdf028fcc75ca03422b77a6a2fc90 /Modules/_io/_iomodule.c
parentd95224ceaf61b6c4cbc7fd8e851a1268f6eee914 (diff)
downloadcpython-de68722ca06615692613148b7015b3c62cd043c3.zip
cpython-de68722ca06615692613148b7015b3c62cd043c3.tar.gz
cpython-de68722ca06615692613148b7015b3c62cd043c3.tar.bz2
Issue #21679: Prevent extraneous fstat() calls during open(). Patch by Bohuslav Kabrda.
Diffstat (limited to 'Modules/_io/_iomodule.c')
-rw-r--r--Modules/_io/_iomodule.c28
1 files changed, 9 insertions, 19 deletions
diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c
index 660ff1f..9e14b4f 100644
--- a/Modules/_io/_iomodule.c
+++ b/Modules/_io/_iomodule.c
@@ -237,8 +237,8 @@ io_open(PyObject *self, PyObject *args, PyObject *kwds)
PyObject *raw, *modeobj = NULL, *buffer, *wrapper, *result = NULL;
+ _Py_IDENTIFIER(_blksize);
_Py_IDENTIFIER(isatty);
- _Py_IDENTIFIER(fileno);
_Py_IDENTIFIER(mode);
_Py_IDENTIFIER(close);
@@ -380,24 +380,14 @@ io_open(PyObject *self, PyObject *args, PyObject *kwds)
line_buffering = 0;
if (buffering < 0) {
- buffering = DEFAULT_BUFFER_SIZE;
-#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
- {
- struct stat st;
- long fileno;
- PyObject *res = _PyObject_CallMethodId(raw, &PyId_fileno, NULL);
- if (res == NULL)
- goto error;
-
- fileno = PyLong_AsLong(res);
- Py_DECREF(res);
- if (fileno == -1 && PyErr_Occurred())
- goto error;
-
- if (fstat(fileno, &st) >= 0 && st.st_blksize > 1)
- buffering = st.st_blksize;
- }
-#endif
+ PyObject *blksize_obj;
+ blksize_obj = _PyObject_GetAttrId(raw, &PyId__blksize);
+ if (blksize_obj == NULL)
+ goto error;
+ buffering = PyLong_AsLong(blksize_obj);
+ Py_DECREF(blksize_obj);
+ if (buffering == -1 && PyErr_Occurred())
+ goto error;
}
if (buffering < 0) {
PyErr_SetString(PyExc_ValueError,