Author: Matti Picus <matti.pi...@gmail.com> Branch: win32-cleanup2 Changeset: r54424:95133865222a Date: 2012-04-16 17:43 +0300 http://bitbucket.org/pypy/pypy/changeset/95133865222a/
Log: rework get_osfhandle to call validate_fd first diff --git a/pypy/rlib/rmmap.py b/pypy/rlib/rmmap.py --- a/pypy/rlib/rmmap.py +++ b/pypy/rlib/rmmap.py @@ -739,9 +739,7 @@ # assume -1 and 0 both mean invalid file descriptor # to 'anonymously' map memory. if fileno != -1 and fileno != 0: - if not rposix.validate_fd(fileno): - raise OSError(rposix.get_errno(), 'Bad file descriptor') - fh = rwin32._get_osfhandle(fileno) + fh = rwin32.get_osfhandle(fileno) if fh == INVALID_HANDLE: errno = rposix.get_errno() raise OSError(errno, os.strerror(errno)) diff --git a/pypy/rlib/rwin32.py b/pypy/rlib/rwin32.py --- a/pypy/rlib/rwin32.py +++ b/pypy/rlib/rwin32.py @@ -8,6 +8,7 @@ from pypy.translator.platform import CompilationError from pypy.rpython.lltypesystem import lltype, rffi from pypy.rlib.rarithmetic import intmask +from pypy.rlib.rposix import validate_fd from pypy.rlib import jit import os, sys, errno @@ -126,6 +127,11 @@ _get_osfhandle = rffi.llexternal('_get_osfhandle', [rffi.INT], HANDLE) + def get_osfhandle(fd): + if not validate_fd(fileno): + raise OSError(GetLastError(), 'Bad file descriptor') + return _get_osfhandle(fd) + def build_winerror_to_errno(): """Build a dictionary mapping windows error numbers to POSIX errno. The function returns the dict, and the default value for codes not diff --git a/pypy/rlib/streamio.py b/pypy/rlib/streamio.py --- a/pypy/rlib/streamio.py +++ b/pypy/rlib/streamio.py @@ -181,8 +181,6 @@ import errno _eci = ExternalCompilationInfo() - _get_osfhandle = rffi.llexternal('_get_osfhandle', [rffi.INT], rffi.LONG, - compilation_info=_eci) _setmode = rffi.llexternal('_setmode', [rffi.INT, rffi.INT], rffi.INT, compilation_info=_eci) SetEndOfFile = rffi.llexternal('SetEndOfFile', [rffi.LONG], rwin32.BOOL, @@ -200,7 +198,7 @@ # move to the position to be truncated os.lseek(fd, size, 0) # Truncate. Note that this may grow the file! - handle = _get_osfhandle(fd) + handle = rwin32.get_osfhandle(fd) if handle == -1: raise OSError(errno.EBADF, "Invalid file handle") if not SetEndOfFile(handle): diff --git a/pypy/rpython/module/ll_os_stat.py b/pypy/rpython/module/ll_os_stat.py --- a/pypy/rpython/module/ll_os_stat.py +++ b/pypy/rpython/module/ll_os_stat.py @@ -402,7 +402,7 @@ lltype.free(data, flavor='raw') def win32_fstat_llimpl(fd): - handle = rwin32._get_osfhandle(fd) + handle = rwin32.get_osfhandle(fd) filetype = win32traits.GetFileType(handle) if filetype == win32traits.FILE_TYPE_CHAR: _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit