[pypy-commit] pypy win32-cleanup2: rework get_osfhandle, begin review (amaury_)
mattip
noreply at buildbot.pypy.org
Mon Apr 16 21:35:00 CEST 2012
Author: Matti Picus <matti.picus at gmail.com>
Branch: win32-cleanup2
Changeset: r54445:390a3cc7e556
Date: 2012-04-16 22:34 +0300
http://bitbucket.org/pypy/pypy/changeset/390a3cc7e556/
Log: rework get_osfhandle, begin review (amaury_)
diff --git a/pypy/rlib/rmmap.py b/pypy/rlib/rmmap.py
--- a/pypy/rlib/rmmap.py
+++ b/pypy/rlib/rmmap.py
@@ -740,9 +740,6 @@
# to 'anonymously' map memory.
if fileno != -1 and fileno != 0:
fh = rwin32.get_osfhandle(fileno)
- if fh == INVALID_HANDLE:
- errno = rposix.get_errno()
- raise OSError(errno, os.strerror(errno))
# Win9x appears to need us seeked to zero
# SEEK_SET = 0
# libc._lseek(fileno, 0, SEEK_SET)
diff --git a/pypy/rlib/rposix.py b/pypy/rlib/rposix.py
--- a/pypy/rlib/rposix.py
+++ b/pypy/rlib/rposix.py
@@ -97,17 +97,9 @@
_set_errno(rffi.cast(INT, errno))
if os.name == 'nt':
- def validate_fd_emulator(fd):
- try:
- os.fstat(fd)
- return 1
- except:
- return 0
-
validate_fd = rffi.llexternal(
"_PyVerify_fd", [rffi.INT], rffi.INT,
- _callable=validate_fd_emulator, compilation_info=eci,
- _nowrapper=True, elidable_function=False, sandboxsafe=False,
+ compilation_info=eci,
)
else:
def validate_fd(fd):
diff --git a/pypy/rlib/rwin32.py b/pypy/rlib/rwin32.py
--- a/pypy/rlib/rwin32.py
+++ b/pypy/rlib/rwin32.py
@@ -128,9 +128,12 @@
_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)
+ if not validate_fd(fd):
+ raise WindowsError(errno.EBADF, 'Bad file descriptor')
+ handle = _get_osfhandle(fd)
+ if handle == INVALID_HANDLE_VALUE:
+ raise WindowsError(errno.EBADF, "Invalid file handle")
+ return handle
def build_winerror_to_errno():
"""Build a dictionary mapping windows error numbers to POSIX errno.
diff --git a/pypy/rlib/streamio.py b/pypy/rlib/streamio.py
--- a/pypy/rlib/streamio.py
+++ b/pypy/rlib/streamio.py
@@ -175,15 +175,14 @@
if sys.platform == "win32":
- from pypy.rlib import rwin32
+ from pypy.rlib.rwin32 import BOOL, HANDLE, get_osfhandle, GetLastError
from pypy.translator.tool.cbuild import ExternalCompilationInfo
from pypy.rpython.lltypesystem import rffi
- import errno
_eci = ExternalCompilationInfo()
_setmode = rffi.llexternal('_setmode', [rffi.INT, rffi.INT], rffi.INT,
compilation_info=_eci)
- SetEndOfFile = rffi.llexternal('SetEndOfFile', [rffi.LONG], rwin32.BOOL,
+ SetEndOfFile = rffi.llexternal('SetEndOfFile', [HANDLE], BOOL,
compilation_info=_eci)
# HACK: These implementations are specific to MSVCRT and the C backend.
@@ -198,11 +197,9 @@
# move to the position to be truncated
os.lseek(fd, size, 0)
# Truncate. Note that this may grow the file!
- handle = rwin32.get_osfhandle(fd)
- if handle == -1:
- raise OSError(errno.EBADF, "Invalid file handle")
+ handle = get_osfhandle(fd)
if not SetEndOfFile(handle):
- raise WindowsError(rwin32.GetLastError(),
+ raise WindowsError(GetLastError(),
"Could not truncate file")
finally:
# we restore the file pointer position in any case
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
@@ -403,7 +403,6 @@
def win32_fstat_llimpl(fd):
handle = rwin32.get_osfhandle(fd)
-
filetype = win32traits.GetFileType(handle)
if filetype == win32traits.FILE_TYPE_CHAR:
# console or LPT device
More information about the pypy-commit
mailing list