[pypy-commit] pypy default: Push back all changes to RPython from the py3.5 branch
arigo
pypy.commits at gmail.com
Sun Oct 16 04:19:39 EDT 2016
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r87826:b607ae6d8133
Date: 2016-10-16 10:15 +0200
http://bitbucket.org/pypy/pypy/changeset/b607ae6d8133/
Log: Push back all changes to RPython from the py3.5 branch
diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py
--- a/rpython/rlib/objectmodel.py
+++ b/rpython/rlib/objectmodel.py
@@ -505,6 +505,8 @@
# ----------
+HASH_ALGORITHM = "rpython" # XXX Is there a better name?
+
def _hash_string(s):
"""The algorithm behind compute_hash() for a string or a unicode."""
from rpython.rlib.rarithmetic import intmask
diff --git a/rpython/tool/runsubprocess.py b/rpython/tool/runsubprocess.py
--- a/rpython/tool/runsubprocess.py
+++ b/rpython/tool/runsubprocess.py
@@ -8,9 +8,15 @@
import os
from subprocess import PIPE, Popen
+PY2 = (sys.version_info.major == 2)
+if PY2:
+ text = unicode
+else:
+ text = str
+
def run_subprocess(executable, args, env=None, cwd=None):
if isinstance(args, list):
- args = [a.encode('latin1') if isinstance(a, unicode) else a
+ args = [a.encode('latin1') if isinstance(a, text) else a
for a in args]
return _run(executable, args, env, cwd)
@@ -71,24 +77,38 @@
_source = os.path.join(_source, 'runsubprocess.py') # and not e.g. '.pyc'
def spawn_subprocess():
- global _child
+ global _child, child_stdin, child_stdout
_child = Popen([sys.executable, _source], bufsize=0,
stdin=PIPE, stdout=PIPE, close_fds=True)
+ if PY2:
+ child_stdin = _child.stdin
+ child_stdout = _child.stdout
+ else:
+ # create TextIOWrappers which (hopefully) have the same newline
+ # behavior as the child's stdin / stdout
+ from io import TextIOWrapper
+ child_stdin = TextIOWrapper(_child.stdin,
+ newline=sys.stdin.newlines,
+ write_through=True)
+ child_stdout = TextIOWrapper(_child.stdout,
+ newline=sys.stdout.newlines)
spawn_subprocess()
def cleanup_subprocess():
- global _child
+ global _child, child_stdin, child_stdout
_child = None
+ child_stdin = None
+ child_stdout = None
import atexit; atexit.register(cleanup_subprocess)
def _run(*args):
try:
- _child.stdin.write('%r\n' % (args,))
+ child_stdin.write('%r\n' % (args,))
except (OSError, IOError):
# lost the child. Try again...
spawn_subprocess()
- _child.stdin.write('%r\n' % (args,))
- results = _child.stdout.readline()
+ child_stdin.write('%r\n' % (args,))
+ results = child_stdout.readline()
assert results.startswith('(')
results = eval(results)
if results[0] is None:
More information about the pypy-commit
mailing list