Author: Armin Rigo <ar...@tunes.org> Branch: py3.5 Changeset: r90268:6cb34cc6c598 Date: 2017-02-21 15:20 +0100 http://bitbucket.org/pypy/pypy/changeset/6cb34cc6c598/
Log: hg merge default diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -1602,6 +1602,7 @@ def bytes_w(self, w_obj): return w_obj.bytes_w(self) + #@not_rpython BACKCOMPAT def str0_w(self, w_obj): "Like str_w, but rejects strings with NUL bytes." from rpython.rlib import rstring @@ -1620,6 +1621,15 @@ "argument must be a string without NUL characters") return rstring.assert_str0(result) + def text0_w(self, w_obj): + "Like text_w, but rejects strings with NUL bytes." + from rpython.rlib import rstring + result = self.text_w(w_obj) + if '\x00' in result: + raise oefmt(self.w_ValueError, + "argument must be a string without NUL characters") + return rstring.assert_str0(result) + def int_w(self, w_obj, allow_conversion=True): """ Unwrap an app-level int object into an interpret-level int. @@ -1717,8 +1727,9 @@ w_obj = self.fsdecode(w_obj) return self.unicode0_w(w_obj) + # BACKCOMPAT -- replace me with newfilename() def wrap_fsdecoded(self, x): - return self.fsdecode(self.newbytes(x)) + return self.newfilename(x) def bool_w(self, w_obj): # Unwraps a bool, also accepting an int for compatibility. diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py --- a/pypy/interpreter/gateway.py +++ b/pypy/interpreter/gateway.py @@ -168,9 +168,15 @@ def visit_bytes(self, el, app_sig): self.checked_space_method(el, app_sig) + def visit_bytes0(self, el, app_sig): + self.checked_space_method(el, app_sig) + def visit_text(self, el, app_sig): self.checked_space_method(el, app_sig) + def visit_text0(self, el, app_sig): + self.checked_space_method(el, app_sig) + def visit_fsencode(self, el, app_sig): self.checked_space_method(el, app_sig) @@ -314,9 +320,15 @@ def visit_bytes(self, typ): self.run_args.append("space.bytes_w(%s)" % (self.scopenext(),)) + def visit_bytes0(self, typ): + self.run_args.append("space.bytes0_w(%s)" % (self.scopenext(),)) + def visit_text(self, typ): self.run_args.append("space.text_w(%s)" % (self.scopenext(),)) + def visit_text0(self, typ): + self.run_args.append("space.text0_w(%s)" % (self.scopenext(),)) + def visit_fsencode(self, typ): self.run_args.append("space.fsencode_w(%s)" % (self.scopenext(),)) @@ -479,9 +491,15 @@ def visit_bytes(self, typ): self.unwrap.append("space.bytes_w(%s)" % (self.nextarg(),)) + def visit_bytes0(self, typ): + self.unwrap.append("space.bytes0_w(%s)" % (self.nextarg(),)) + def visit_text(self, typ): self.unwrap.append("space.text_w(%s)" % (self.nextarg(),)) + def visit_text0(self, typ): + self.unwrap.append("space.text0_w(%s)" % (self.nextarg(),)) + def visit_fsencode(self, typ): self.unwrap.append("space.fsencode_w(%s)" % (self.nextarg(),)) diff --git a/pypy/interpreter/miscutils.py b/pypy/interpreter/miscutils.py --- a/pypy/interpreter/miscutils.py +++ b/pypy/interpreter/miscutils.py @@ -33,6 +33,11 @@ def getallvalues(self): return {0: self._value} + def _cleanup_(self): + # should still be unfilled at this point during translation. + # but in some corner cases it is not... unsure why + self._value = None + def make_weak_value_dictionary(space, keytype, valuetype): "NOT_RPYTHON" diff --git a/pypy/module/cpyext/pystate.py b/pypy/module/cpyext/pystate.py --- a/pypy/module/cpyext/pystate.py +++ b/pypy/module/cpyext/pystate.py @@ -286,6 +286,8 @@ else: assert ec.cpyext_gilstate_counter_noleave == 0 assert oldstate == PyGILState_UNLOCKED + assert space.config.translation.thread + # ^^^ otherwise, we should not reach this case ec.cpyext_threadstate_is_current = False space.threadlocals.leave_thread(space) diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py --- a/pypy/module/imp/importing.py +++ b/pypy/module/imp/importing.py @@ -67,7 +67,7 @@ lib_pypy = os.path.join(os.path.dirname(__file__), '..', '..', '..', 'lib_pypy') -@unwrap_spec(modulename='str0', level=int) +@unwrap_spec(modulename='text0', level=int) def importhook(space, modulename, w_globals=None, w_locals=None, w_fromlist=None, level=0): # A minimal version, that can only import builtin and lib_pypy modules! assert w_locals is w_globals diff --git a/pypy/module/imp/interp_imp.py b/pypy/module/imp/interp_imp.py --- a/pypy/module/imp/interp_imp.py +++ b/pypy/module/imp/interp_imp.py @@ -72,7 +72,7 @@ return None def is_builtin(space, w_name): - name = space.str0_w(w_name) + name = space.text0_w(w_name) if name not in space.builtin_modules: return space.newint(0) if space.finditem(space.sys.get('modules'), w_name) is not None: diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py --- a/pypy/module/posix/interp_posix.py +++ b/pypy/module/posix/interp_posix.py @@ -66,7 +66,7 @@ self.w_obj = w_obj def as_bytes(self): - return self.space.fsencode_w(self.w_obj) + return self.space.bytes0_w(self.w_obj) def as_unicode(self): return self.space.fsdecode_w(self.w_obj) @@ -85,7 +85,7 @@ fname = FileEncoder(space, w_fname) return func(fname, *args) else: - fname = space.fsencode_w(w_fname) + fname = space.bytes0_w(w_fname) return func(fname, *args) return dispatch @@ -697,7 +697,7 @@ fullpath = rposix.getfullpathname(path) w_fullpath = space.newunicode(fullpath) else: - path = space.str0_w(w_path) + path = space.bytes0_w(w_path) fullpath = rposix.getfullpathname(path) w_fullpath = space.newbytes(fullpath) except OSError as e: @@ -793,7 +793,7 @@ cur = os.getlogin() except OSError as e: raise wrap_oserror(space, e, eintr_retry=False) - return space.wrap_fsdecoded(cur) + return space.newfilename(cur) # ____________________________________________________________ @@ -884,7 +884,7 @@ if space.is_none(w_path): w_path = space.newunicode(u".") if space.isinstance_w(w_path, space.w_bytes): - dirname = space.str0_w(w_path) + dirname = space.bytes0_w(w_path) try: result = rposix.listdir(dirname) except OSError as e: @@ -915,7 +915,7 @@ if _WIN32: result_w[i] = space.newunicode(result[i]) else: - result_w[i] = space.wrap_fsdecoded(result[i]) + result_w[i] = space.newfilename(result[i]) return space.newlist(result_w) @unwrap_spec(fd=c_int) @@ -1607,7 +1607,7 @@ r = os.uname() except OSError as e: raise wrap_oserror(space, e, eintr_retry=False) - l_w = [space.wrap_fsdecoded(i) + l_w = [space.newfilename(i) for i in [r[0], r[1], r[2], r[3], r[4]]] w_tuple = space.newtuple(l_w) w_uname_result = space.getattr(space.getbuiltinmodule(os.name), @@ -1945,7 +1945,7 @@ @unwrap_spec(fd=c_int) def ttyname(space, fd): try: - return space.wrap_fsdecoded(os.ttyname(fd)) + return space.newfilename(os.ttyname(fd)) except OSError as e: raise wrap_oserror(space, e, eintr_retry=False) @@ -2156,7 +2156,7 @@ Return the name of the controlling terminal for this process. """ - return space.wrap_fsdecoded(os.ctermid()) + return space.newfilename(os.ctermid()) @unwrap_spec(fd=c_int) def device_encoding(space, fd): diff --git a/pypy/objspace/fake/objspace.py b/pypy/objspace/fake/objspace.py --- a/pypy/objspace/fake/objspace.py +++ b/pypy/objspace/fake/objspace.py @@ -217,11 +217,10 @@ def newunicode(self, x): return w_some_obj() - def newutf8(self, x): + def newtext(self, x): return w_some_obj() - - newtext = newutf8 - newtext_or_none = newutf8 + newtext_or_none = newtext + newfilename = newtext @not_rpython def wrap(self, x): diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py --- a/pypy/objspace/std/objspace.py +++ b/pypy/objspace/std/objspace.py @@ -378,6 +378,9 @@ return self.w_None return self.newtext(s) + def newfilename(self, s): + return self.fsdecode(self.newbytes(s)) + def newunicode(self, uni): assert uni is not None assert isinstance(uni, unicode) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit