[pypy-svn] pypy default: More tweaks to try to make the translated pypy-c more happy.
arigo
commits-noreply at bitbucket.org
Sat Feb 5 19:50:27 CET 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r41634:98c9d9cfcfbe
Date: 2011-02-05 19:28 +0100
http://bitbucket.org/pypy/pypy/changeset/98c9d9cfcfbe/
Log: More tweaks to try to make the translated pypy-c more happy.
diff --git a/pypy/translator/goal/test2/test_nanos.py b/pypy/translator/goal/test2/test_nanos.py
--- a/pypy/translator/goal/test2/test_nanos.py
+++ b/pypy/translator/goal/test2/test_nanos.py
@@ -22,9 +22,6 @@
assert os1.name == os.name
assert os1.sep == os.sep
assert os1.pathsep == os.pathsep
- # check that the following attrs exist
- os1.fdopen
- os1.path.dirname
def test_dirname(self):
p1 = os.path
@@ -33,6 +30,7 @@
assert p1.dirname(path) == p2.dirname(path)
assert p1.dirname(path + os.sep) == p2.dirname(path + os.sep)
assert p1.dirname(path + 2*os.sep) == p2.dirname(path + 2*os.sep)
+ assert p1.dirname(p1.dirname(path)) == p2.dirname(p2.dirname(path))
def test_join(self):
p1 = os.path
@@ -50,6 +48,14 @@
assert p2.abspath(base) == base
assert p2.abspath('x') == os.path.join(os.getcwd(), 'x')
+ def test_isfile(self):
+ p2 = self.getnanos().path
+ udir.join('test_isfile').write('\n')
+ base = str(udir)
+ assert p2.isfile(p2.join(base, 'test_isfile'))
+ assert not p2.isfile(p2.join(base, 'test_isfile.DOES.NOT.EXIST'))
+ assert not p2.isfile(base)
+
def test_nanos():
space = Space()
diff --git a/pypy/translator/goal/nanos.py b/pypy/translator/goal/nanos.py
--- a/pypy/translator/goal/nanos.py
+++ b/pypy/translator/goal/nanos.py
@@ -31,8 +31,6 @@
if os.name == 'posix':
# code copied from posixpath.py
app_os_path = applevel("""
- from posix import getcwd, stat, lstat, error
-
def dirname(p):
i = p.rfind('/') + 1
head = p[:i]
@@ -51,21 +49,24 @@
def abspath(path):
if not path.startswith('/'):
- cwd = getcwd()
+ import posix
+ cwd = posix.getcwd()
path = join(cwd, path)
return path # this version does not call normpath()!
def isfile(path):
+ import posix
try:
- st = stat(path)
- except error:
+ st = posix.stat(path)
+ except posix.error:
return False
return (st.st_mode & 0170000) == 0100000 # S_ISREG
def islink(path):
+ import posix
try:
- st = lstat(path)
- except error:
+ st = posix.lstat(path)
+ except posix.error:
return False
return (st.st_mode & 0170000) == 0120000 # S_ISLNK
@@ -75,14 +76,15 @@
sep = '/'
pathsep = ':'
name = 'posix'
- from posix import fdopen, readlink
+
+ def readlink(fn):
+ import posix
+ return posix.readlink(fn)
""", filename=__file__)
elif os.name == 'nt':
# code copied from ntpath.py
app_os_path = applevel("""
- from nt import _getfullpathname, getcwd, stat, lstat, error
-
def splitdrive(p):
if p[1:2] == ':':
return p[0:2], p[2:]
@@ -157,19 +159,21 @@
return path
def abspath(path):
+ import nt
if path: # Empty path must return current working directory.
try:
- path = _getfullpathname(path)
+ path = nt._getfullpathname(path)
except WindowsError:
pass # Bad path - return unchanged.
else:
- path = getcwd()
+ path = nt.getcwd()
return path # this version does not call normpath()!
def isfile(path):
+ import nt
try:
- st = stat(path)
- except error:
+ st = nt.stat(path)
+ except nt.error:
return False
return (st.st_mode & 0170000) == 0100000 # S_ISREG
@@ -182,7 +186,6 @@
sep = '\\'
pathsep = ';'
name = 'nt'
- from posix import fdopen
""", filename=__file__)
else:
diff --git a/pypy/translator/goal/app_main.py b/pypy/translator/goal/app_main.py
--- a/pypy/translator/goal/app_main.py
+++ b/pypy/translator/goal/app_main.py
@@ -164,13 +164,20 @@
print >> sys.stderr, 'usage: %s [options]' % (sys.executable,)
print >> sys.stderr, 'Try `%s -h` for more information.' % (sys.executable,)
+def fdopen(fd, mode, bufsize=-1):
+ try:
+ fdopen = file.fdopen
+ except AttributeError: # only on top of CPython, running tests
+ from os import fdopen
+ return fdopen(fd, mode, bufsize)
+
def set_unbuffered_io():
- sys.stdin = sys.__stdin__ = os.fdopen(0, 'rb', 0)
- sys.stdout = sys.__stdout__ = os.fdopen(1, 'wb', 0)
- sys.stderr = sys.__stderr__ = os.fdopen(2, 'wb', 0)
+ sys.stdin = sys.__stdin__ = fdopen(0, 'rb', 0)
+ sys.stdout = sys.__stdout__ = fdopen(1, 'wb', 0)
+ sys.stderr = sys.__stderr__ = fdopen(2, 'wb', 0)
def set_fully_buffered_io():
- sys.stdout = sys.__stdout__ = os.fdopen(1, 'w')
+ sys.stdout = sys.__stdout__ = fdopen(1, 'w')
# ____________________________________________________________
# Main entry point
More information about the Pypy-commit
mailing list