[pypy-commit] pypy win32-cleanup2: finish cleanup of fclose
mattip
noreply at buildbot.pypy.org
Tue Apr 3 21:43:32 CEST 2012
Author: Matti Picus <matti.picus at gmail.com>
Branch: win32-cleanup2
Changeset: r54171:21b9e0657e6f
Date: 2012-04-03 22:42 +0300
http://bitbucket.org/pypy/pypy/changeset/21b9e0657e6f/
Log: finish cleanup of fclose
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,6 +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.unroll import unrolling_iterable
from pypy.rlib.objectmodel import specialize
from pypy.rlib.exports import export_struct
@@ -80,14 +81,18 @@
# FILE* interface
FILEP = rffi.COpaquePtr('FILE')
+if sys.platform == 'win32':
+ fileno = rffi.llexternal('_fileno', [FILEP], rffi.INT)
+else:
+ fileno = rffi.llexternal('fileno', [FILEP], rffi.INT)
+
fopen = rffi.llexternal('fopen', [CONST_STRING, CONST_STRING], FILEP)
+
_fclose = rffi.llexternal('fclose', [FILEP], rffi.INT)
def fclose(fp):
- try:
- fd = fileno(fp)
- return os.close(fd)
- except:
+ if not validate_fd(fileno(fp)):
return -1
+ return _fclose(fp)
fwrite = rffi.llexternal('fwrite',
[rffi.VOIDP, rffi.SIZE_T, rffi.SIZE_T, FILEP],
@@ -96,10 +101,6 @@
[rffi.VOIDP, rffi.SIZE_T, rffi.SIZE_T, FILEP],
rffi.SIZE_T)
feof = rffi.llexternal('feof', [FILEP], rffi.INT)
-if sys.platform == 'win32':
- fileno = rffi.llexternal('_fileno', [FILEP], rffi.INT)
-else:
- fileno = rffi.llexternal('fileno', [FILEP], rffi.INT)
constant_names = """
More information about the pypy-commit
mailing list