diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2014-06-30 00:07:28 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2014-06-30 00:07:28 (GMT) |
commit | de68722ca06615692613148b7015b3c62cd043c3 (patch) | |
tree | 40ee136de88cdf028fcc75ca03422b77a6a2fc90 /Modules/_io/_iomodule.c | |
parent | d95224ceaf61b6c4cbc7fd8e851a1268f6eee914 (diff) | |
download | cpython-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.c | 28 |
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, |