[pypy-svn] pypy default: Implemented the st_blksize logic for _io.open.
alex_gaynor
commits-noreply at bitbucket.org
Mon Jan 31 01:26:37 CET 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r41479:c1c023c69720
Date: 2011-01-30 19:26 -0500
http://bitbucket.org/pypy/pypy/changeset/c1c023c69720/
Log: Implemented the st_blksize logic for _io.open.
diff --git a/pypy/module/_io/interp_io.py b/pypy/module/_io/interp_io.py
--- a/pypy/module/_io/interp_io.py
+++ b/pypy/module/_io/interp_io.py
@@ -1,3 +1,5 @@
+import os
+
from pypy.interpreter.baseobjspace import ObjSpace, W_Root
from pypy.interpreter.error import operationerrfmt, OperationError
from pypy.interpreter.gateway import interp2app, Arguments, unwrap_spec
@@ -7,6 +9,7 @@
from pypy.module._io.interp_fileio import W_FileIO
from pypy.module._io.interp_iobase import W_IOBase
from pypy.module._io.interp_textio import W_TextIOWrapper
+from pypy.rpython.module.ll_os_stat import STAT_FIELD_TYPES
class W_BlockingIOError(W_IOError):
@@ -114,26 +117,17 @@
if buffering < 0:
buffering = DEFAULT_BUFFER_SIZE
- """
- XXX: implement me!
- #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
- {
- struct stat st;
- long fileno;
- PyObject *res = PyObject_CallMethod(raw, "fileno", NULL);
- if (res == NULL)
- goto error;
- fileno = PyInt_AsLong(res);
- Py_DECREF(res);
- if (fileno == -1 && PyErr_Occurred())
- goto error;
+ if "st_blksize" in STAT_FIELD_TYPES:
+ fileno = space.int_w(space.call_method(w_raw, "fileno"))
+ try:
+ st = os.fstat(fileno)
+ except OSError:
+ # Errors should never pass silently, except this one time.
+ pass
+ else:
+ buffering = st.st_blksize
- if (fstat(fileno, &st) >= 0)
- buffering = st.st_blksize;
- }
- #endif
- """
if buffering < 0:
raise OperationError(space.w_ValueError,
space.wrap("invalid buffering size")
More information about the Pypy-commit
mailing list