[pypy-commit] pypy win32-cleanup2: more cleanup of validate_fd (amaury_)
mattip
noreply at buildbot.pypy.org
Mon Apr 16 23:29:59 CEST 2012
Author: Matti Picus <matti.picus at gmail.com>
Branch: win32-cleanup2
Changeset: r54446:dba9f63cc754
Date: 2012-04-17 00:29 +0300
http://bitbucket.org/pypy/pypy/changeset/dba9f63cc754/
Log: more cleanup of validate_fd (amaury_)
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -26,7 +26,7 @@
from pypy.module.__builtin__.interp_classobj import W_ClassObject
from pypy.module.__builtin__.interp_memoryview import W_MemoryView
from pypy.rlib.entrypoint import entrypoint
-from pypy.rlib.rposix import validate_fd
+from pypy.rlib.rposix import _validate_fd
from pypy.rlib.unroll import unrolling_iterable
from pypy.rlib.objectmodel import specialize
from pypy.rlib.exports import export_struct
@@ -90,7 +90,7 @@
_fclose = rffi.llexternal('fclose', [FILEP], rffi.INT)
def fclose(fp):
- if not validate_fd(fileno(fp)):
+ if not _validate_fd(fileno(fp)):
return -1
return _fclose(fp)
diff --git a/pypy/rlib/rposix.py b/pypy/rlib/rposix.py
--- a/pypy/rlib/rposix.py
+++ b/pypy/rlib/rposix.py
@@ -5,6 +5,7 @@
from pypy.translator.tool.cbuild import ExternalCompilationInfo
from pypy.rlib.rarithmetic import intmask
from pypy.rlib.objectmodel import specialize
+from pypy.rlib import jit
class CConstantErrno(CConstant):
# these accessors are used when calling get_errno() or set_errno()
@@ -97,10 +98,14 @@
_set_errno(rffi.cast(INT, errno))
if os.name == 'nt':
- validate_fd = rffi.llexternal(
+ _validate_fd = rffi.llexternal(
"_PyVerify_fd", [rffi.INT], rffi.INT,
compilation_info=eci,
)
+ @jit.dont_look_inside
+ def validate_fd(fd):
+ if not _validate_fd(fd):
+ raise OSError(get_errno(), 'Bad file descriptor')
else:
def validate_fd(fd):
return 1
@@ -109,7 +114,7 @@
# this behaves like os.closerange() from Python 2.6.
for fd in xrange(fd_low, fd_high):
try:
- if validate_fd(fd):
+ if _validate_fd(fd):
os.close(fd)
except OSError:
pass
diff --git a/pypy/rlib/rwin32.py b/pypy/rlib/rwin32.py
--- a/pypy/rlib/rwin32.py
+++ b/pypy/rlib/rwin32.py
@@ -128,8 +128,7 @@
_get_osfhandle = rffi.llexternal('_get_osfhandle', [rffi.INT], HANDLE)
def get_osfhandle(fd):
- if not validate_fd(fd):
- raise WindowsError(errno.EBADF, 'Bad file descriptor')
+ validate_fd(fd)
handle = _get_osfhandle(fd)
if handle == INVALID_HANDLE_VALUE:
raise WindowsError(errno.EBADF, "Invalid file handle")
diff --git a/pypy/rlib/test/test_rposix.py b/pypy/rlib/test/test_rposix.py
--- a/pypy/rlib/test/test_rposix.py
+++ b/pypy/rlib/test/test_rposix.py
@@ -133,11 +133,11 @@
pass
def test_validate_fd(self):
- assert rposix.validate_fd(0) == 1
+ assert rposix._validate_fd(0) == 1
fid = open(str(udir.join('validate_test.txt')), 'w')
fd = fid.fileno()
- assert rposix.validate_fd(fd) == 1
+ assert rposix._validate_fd(fd) == 1
fid.close()
- assert rposix.validate_fd(fd) == 0
+ assert rposix._validate_fd(fd) == 0
diff --git a/pypy/rpython/module/ll_os.py b/pypy/rpython/module/ll_os.py
--- a/pypy/rpython/module/ll_os.py
+++ b/pypy/rpython/module/ll_os.py
@@ -916,8 +916,7 @@
def os_write_llimpl(fd, data):
count = len(data)
- if not rposix.validate_fd(fd):
- raise OSError(rposix.get_errno(), 'Bad file descriptor')
+ rposix.validate_fd(fd)
buf = rffi.get_nonmovingbuffer(data)
try:
written = rffi.cast(lltype.Signed, os_write(
@@ -942,8 +941,7 @@
rffi.INT, threadsafe=False)
def close_llimpl(fd):
- if not rposix.validate_fd(fd):
- raise OSError(rposix.get_errno(), 'Bad file descriptor')
+ rposix.validate_fd(fd)
error = rffi.cast(lltype.Signed, os_close(rffi.cast(rffi.INT, fd)))
if error == -1:
raise OSError(rposix.get_errno(), "close failed")
@@ -979,8 +977,7 @@
rffi.LONGLONG)
def lseek_llimpl(fd, pos, how):
- if not rposix.validate_fd(fd):
- raise OSError(rposix.get_errno(), 'Bad file descriptor')
+ rposix.validate_fd(fd)
how = fix_seek_arg(how)
res = os_lseek(rffi.cast(rffi.INT, fd),
rffi.cast(rffi.LONGLONG, pos),
@@ -1006,8 +1003,7 @@
[rffi.INT, rffi.LONGLONG], rffi.INT)
def ftruncate_llimpl(fd, length):
- if not rposix.validate_fd(fd):
- raise OSError(rposix.get_errno(), 'Bad file descriptor')
+ rposix.validate_fd(fd)
res = rffi.cast(rffi.LONG,
os_ftruncate(rffi.cast(rffi.INT, fd),
rffi.cast(rffi.LONGLONG, length)))
@@ -1026,8 +1022,7 @@
os_fsync = self.llexternal('_commit', [rffi.INT], rffi.INT)
def fsync_llimpl(fd):
- if not rposix.validate_fd(fd):
- raise OSError(rposix.get_errno(), 'Bad file descriptor')
+ rposix.validate_fd(fd)
res = rffi.cast(rffi.SIGNED, os_fsync(rffi.cast(rffi.INT, fd)))
if res < 0:
raise OSError(rposix.get_errno(), "fsync failed")
@@ -1040,8 +1035,7 @@
os_fdatasync = self.llexternal('fdatasync', [rffi.INT], rffi.INT)
def fdatasync_llimpl(fd):
- if not rposix.validate_fd(fd):
- raise OSError(rposix.get_errno(), 'Bad file descriptor')
+ rposix.validate_fd(fd)
res = rffi.cast(rffi.SIGNED, os_fdatasync(rffi.cast(rffi.INT, fd)))
if res < 0:
raise OSError(rposix.get_errno(), "fdatasync failed")
More information about the pypy-commit
mailing list