[pypy-commit] pypy use-file-star-for-file: use getc_unlocked when possible
bdkearns
noreply at buildbot.pypy.org
Fri Sep 12 01:11:19 CEST 2014
Author: Brian Kearns <bdkearns at gmail.com>
Branch: use-file-star-for-file
Changeset: r73494:06cf208f624d
Date: 2014-09-11 16:10 -0700
http://bitbucket.org/pypy/pypy/changeset/06cf208f624d/
Log: use getc_unlocked when possible
diff --git a/rpython/rlib/rfile.py b/rpython/rlib/rfile.py
--- a/rpython/rlib/rfile.py
+++ b/rpython/rlib/rfile.py
@@ -89,9 +89,18 @@
_fclose2 = (c_fclose, c_fclose_nogil)
_pclose2 = (c_pclose, c_pclose_nogil)
-c_getc = llexternal('getc', [FILEP], rffi.INT, macro=True, releasegil=False)
+c_flockfile = llexternal('flockfile', [FILEP], lltype.Void, releasegil=False)
+c_funlockfile = llexternal('funlockfile', [FILEP], lltype.Void, releasegil=False)
+
+c_getc = llexternal('getc', [FILEP], rffi.INT, releasegil=False)
+c_getc_unlocked = llexternal('getc_unlocked', [FILEP], rffi.INT, releasegil=False)
c_ungetc = llexternal('ungetc', [rffi.INT, FILEP], rffi.INT, releasegil=False)
+if os.name == 'nt':
+ c_flockfile = lambda ll_file: None
+ c_funlockfile = lambda ll_file: None
+ c_getc_unlocked = c_getc
+
c_fgets = llexternal('fgets', [rffi.CCHARP, rffi.INT, FILEP], rffi.CCHARP)
c_fread = llexternal('fread', [rffi.CCHARP, rffi.SIZE_T, rffi.SIZE_T, FILEP],
rffi.SIZE_T)
@@ -488,16 +497,17 @@
c = 0
s = StringBuilder()
while True:
+ c_flockfile(ll_file)
if self._univ_newline:
while size < 0 or s.getlength() < size:
- c = c_getc(ll_file)
+ c = c_getc_unlocked(ll_file)
if c == EOF:
break
if skipnextlf:
skipnextlf = False
if c == ord('\n'):
newlinetypes |= NEWLINE_CRLF
- c = c_getc(ll_file)
+ c = c_getc_unlocked(ll_file)
if c == EOF:
break
else:
@@ -512,6 +522,7 @@
break
if c == EOF:
if c_ferror(ll_file) and rposix.get_errno() == errno.EINTR:
+ c_funlockfile(ll_file)
self._newlinetypes = newlinetypes
self._skipnextlf = skipnextlf
if self._signal_checker is not None:
@@ -522,12 +533,13 @@
newlinetypes |= NEWLINE_CR
else:
while s.getlength() < size:
- c = c_getc(ll_file)
+ c = c_getc_unlocked(ll_file)
if c == EOF:
break
s.append(chr(c))
if c == ord('\n'):
break
+ c_funlockfile(ll_file)
self._newlinetypes = newlinetypes
self._skipnextlf = skipnextlf
if c == ord('\n'):
More information about the pypy-commit
mailing list