[pypy-commit] pypy py3k: avoid recursion issues at startup by pre-importing the utf-8/latin1 encodings
pjenvey
noreply at buildbot.pypy.org
Wed Feb 27 22:59:34 CET 2013
Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r61870:7939f83e15e5
Date: 2013-02-27 13:58 -0800
http://bitbucket.org/pypy/pypy/changeset/7939f83e15e5/
Log: avoid recursion issues at startup by pre-importing the utf-8/latin1
encodings (like cpython does)
diff --git a/pypy/interpreter/app_main.py b/pypy/interpreter/app_main.py
--- a/pypy/interpreter/app_main.py
+++ b/pypy/interpreter/app_main.py
@@ -233,20 +233,34 @@
def initstdio(encoding=None, unbuffered=False):
if hasattr(sys, 'stdin'):
return # already initialized
- if not encoding:
- encoding = sys.getfilesystemencoding()
- if ':' in encoding:
- encoding, errors = encoding.split(':', 1)
- else:
- errors = None
- sys.stdin = sys.__stdin__ = create_stdio(
- 0, False, "<stdin>", encoding, errors, unbuffered)
- sys.stdout = sys.__stdout__ = create_stdio(
- 1, True, "<stdout>", encoding, errors, unbuffered)
- sys.stderr = sys.__stderr__ = create_stdio(
- 2, True, "<stderr>", encoding, 'backslashreplace', unbuffered)
+ # Hack to avoid recursion issues during bootstrapping: pre-import
+ # the utf-8 and latin-1 codecs
+ encerr = None
+ try:
+ import encodings.utf_8
+ import encodings.latin_1
+ except ImportError as e:
+ encerr = e
+ try:
+ if not encoding:
+ encoding = sys.getfilesystemencoding()
+ if ':' in encoding:
+ encoding, errors = encoding.split(':', 1)
+ else:
+ errors = None
+
+ sys.stdin = sys.__stdin__ = create_stdio(
+ 0, False, "<stdin>", encoding, errors, unbuffered)
+ sys.stdout = sys.__stdout__ = create_stdio(
+ 1, True, "<stdout>", encoding, errors, unbuffered)
+ sys.stderr = sys.__stderr__ = create_stdio(
+ 2, True, "<stderr>", encoding, 'backslashreplace', unbuffered)
+ finally:
+ if encerr:
+ display_exception(encerr)
+ del encerr
def create_stdio(fd, writing, name, encoding, errors, unbuffered):
import io
More information about the pypy-commit
mailing list