[pypy-commit] pypy py3k: Fix three cases where space.wrap() was called with a potentially non-ASCII string.

mjacob noreply at buildbot.pypy.org
Tue Aug 25 23:41:51 CEST 2015


Author: Manuel Jacob <me at manueljacob.de>
Branch: py3k
Changeset: r79228:aeafe30eac60
Date: 2015-08-25 12:35 +0200
http://bitbucket.org/pypy/pypy/changeset/aeafe30eac60/

Log:	Fix three cases where space.wrap() was called with a potentially
	non-ASCII string.

diff --git a/pypy/bin/pyinteractive.py b/pypy/bin/pyinteractive.py
--- a/pypy/bin/pyinteractive.py
+++ b/pypy/bin/pyinteractive.py
@@ -143,7 +143,8 @@
     if interactiveconfig.runmodule:
         command = args.pop(0)
     for arg in args:
-        space.call_method(space.sys.get('argv'), 'append', space.wrap(arg))
+        space.call_method(space.sys.get('argv'), 'append',
+                          space.wrap_fsdecoded(arg))
 
     # load the source of the program given as command-line argument
     if interactiveconfig.runcommand:
diff --git a/pypy/goal/targetpypystandalone.py b/pypy/goal/targetpypystandalone.py
--- a/pypy/goal/targetpypystandalone.py
+++ b/pypy/goal/targetpypystandalone.py
@@ -61,8 +61,8 @@
                         rlocale.setlocale(rlocale.LC_CTYPE, '')
                     except rlocale.LocaleError:
                         pass
-                w_executable = space.fsdecode(space.wrapbytes(argv[0]))
-                w_argv = space.newlist([space.fsdecode(space.wrapbytes(s))
+                w_executable = space.wrap_fsdecoded(argv[0])
+                w_argv = space.newlist([space.wrap_fsdecoded(s)
                                         for s in argv[1:]])
                 w_exitcode = space.call_function(w_entry_point, w_executable, w_argv)
                 exitcode = space.int_w(w_exitcode)
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1050,6 +1050,9 @@
         from pypy.objspace.std.listobject import make_empty_list_with_size
         return make_empty_list_with_size(self, sizehint)
 
+    def wrap_fsdecoded(self, x):
+        return self.fsdecode(self.wrapbytes(x))
+
     @jit.unroll_safe
     def exception_match(self, w_exc_type, w_check_class):
         """Checks if the given exception type matches 'w_check_class'."""
diff --git a/pypy/interpreter/main.py b/pypy/interpreter/main.py
--- a/pypy/interpreter/main.py
+++ b/pypy/interpreter/main.py
@@ -19,7 +19,8 @@
 def compilecode(space, source, filename, cmd='exec'):
     w = space.wrap
     w_code = space.builtin.call(
-        'compile', space.wrapbytes(source), w(filename), w(cmd), w(0), w(0))
+        'compile', space.wrapbytes(source), space.wrap_fsdecoded(filename),
+        w(cmd), w(0), w(0))
     pycode = space.interp_w(eval.Code, w_code)
     return pycode
 
@@ -44,7 +45,8 @@
 
         space.setitem(w_globals, w('__builtins__'), space.builtin)
         if filename is not None:
-            space.setitem(w_globals, w('__file__'), w(filename))
+            space.setitem(w_globals, w('__file__'),
+                          space.wrap_fsdecoded(filename))
 
         retval = pycode.exec_code(space, w_globals, w_globals)
         if eval:


More information about the pypy-commit mailing list