Author: Carl Friedrich Bolz <cfb...@gmx.de> Branch: space-newtext Changeset: r88066:9cd4b09a39f8 Date: 2016-11-02 10:38 +0100 http://bitbucket.org/pypy/pypy/changeset/9cd4b09a39f8/
Log: sys module diff --git a/pypy/module/parser/__init__.py b/pypy/module/parser/__init__.py --- a/pypy/module/parser/__init__.py +++ b/pypy/module/parser/__init__.py @@ -10,8 +10,8 @@ } interpleveldefs = { - '__name__' : '(space.wrap("parser"))', - '__doc__' : '(space.wrap("parser module"))', + '__name__' : '(space.newtext("parser"))', + '__doc__' : '(space.newtext("parser module"))', 'suite' : 'pyparser.suite', 'expr' : 'pyparser.expr', 'issuite' : 'pyparser.issuite', diff --git a/pypy/module/sys/__init__.py b/pypy/module/sys/__init__.py --- a/pypy/module/sys/__init__.py +++ b/pypy/module/sys/__init__.py @@ -24,21 +24,21 @@ self.dlopenflags = rdynload._dlopen_default_mode() interpleveldefs = { - '__name__' : '(space.wrap("sys"))', - '__doc__' : '(space.wrap("PyPy sys module"))', + '__name__' : '(space.newtext("sys"))', + '__doc__' : '(space.newtext("PyPy sys module"))', - 'platform' : 'space.wrap(sys.platform)', - 'maxint' : 'space.wrap(sys.maxint)', - 'maxsize' : 'space.wrap(sys.maxint)', - 'byteorder' : 'space.wrap(sys.byteorder)', - 'maxunicode' : 'space.wrap(vm.MAXUNICODE)', + 'platform' : 'space.newtext(sys.platform)', + 'maxint' : 'space.newint(sys.maxint)', + 'maxsize' : 'space.newint(sys.maxint)', + 'byteorder' : 'space.newtext(sys.byteorder)', + 'maxunicode' : 'space.newint(vm.MAXUNICODE)', 'stdin' : 'state.getio(space).w_stdin', '__stdin__' : 'state.getio(space).w_stdin', 'stdout' : 'state.getio(space).w_stdout', '__stdout__' : 'state.getio(space).w_stdout', 'stderr' : 'state.getio(space).w_stderr', '__stderr__' : 'state.getio(space).w_stderr', - 'pypy_objspaceclass' : 'space.wrap(repr(space))', + 'pypy_objspaceclass' : 'space.newtext(repr(space))', #'prefix' : # added by pypy_initial_path() when it #'exec_prefix' : # succeeds, pointing to trunk or /usr 'path' : 'state.get(space).w_path', @@ -79,10 +79,10 @@ 'displayhook' : 'hook.displayhook', '__displayhook__' : 'hook.__displayhook__', - 'meta_path' : 'space.wrap([])', - 'path_hooks' : 'space.wrap([])', - 'path_importer_cache' : 'space.wrap({})', - 'dont_write_bytecode' : 'space.wrap(space.config.translation.sandbox)', + 'meta_path' : 'space.newlist([])', + 'path_hooks' : 'space.newlist([])', + 'path_importer_cache' : 'space.newdict()', + 'dont_write_bytecode' : 'space.newbool(space.config.translation.sandbox)', 'getdefaultencoding' : 'interp_encoding.getdefaultencoding', 'setdefaultencoding' : 'interp_encoding.setdefaultencoding', @@ -116,18 +116,18 @@ else: from pypy.module.sys import version - space.setitem(self.w_dict, space.wrap("version"), - space.wrap(version.get_version(space))) + space.setitem(self.w_dict, space.newtext("version"), + version.get_version(space)) if _WIN: from pypy.module.sys import vm w_handle = vm.get_dllhandle(space) - space.setitem(self.w_dict, space.wrap("dllhandle"), w_handle) + space.setitem(self.w_dict, space.newtext("dllhandle"), w_handle) def getmodule(self, name): space = self.space w_modules = self.get('modules') try: - return space.getitem(w_modules, space.wrap(name)) + return space.getitem(w_modules, space.newtext(name)) except OperationError as e: if not e.match(space, space.w_KeyError): raise @@ -135,7 +135,7 @@ def setmodule(self, w_module): space = self.space - w_name = self.space.getattr(w_module, space.wrap('__name__')) + w_name = self.space.getattr(w_module, space.newtext('__name__')) w_modules = self.get('modules') self.space.setitem(w_modules, w_name, w_module) @@ -161,7 +161,7 @@ if operror is None: return space.w_None else: - return space.wrap(operror.get_traceback()) + return operror.get_traceback() return None def get_w_default_encoder(self): @@ -176,7 +176,7 @@ def get_flag(self, name): space = self.space - return space.int_w(space.getattr(self.get('flags'), space.wrap(name))) + return space.int_w(space.getattr(self.get('flags'), space.newtext(name))) def get_state(self, space): from pypy.module.sys import state diff --git a/pypy/module/sys/currentframes.py b/pypy/module/sys/currentframes.py --- a/pypy/module/sys/currentframes.py +++ b/pypy/module/sys/currentframes.py @@ -61,17 +61,17 @@ else: frames.append(None) - w_topframe = space.wrap(None) + w_topframe = space.w_None w_prevframe = None for f in frames: w_nextframe = space.call_function(w_fake_frame, space.wrap(f)) if w_prevframe is None: w_topframe = w_nextframe else: - space.setattr(w_prevframe, space.wrap('f_back'), w_nextframe) + space.setattr(w_prevframe, space.newtext('f_back'), w_nextframe) w_prevframe = w_nextframe space.setitem(w_result, - space.wrap(thread_ident), + space.newint(thread_ident), w_topframe) return w_result diff --git a/pypy/module/sys/hook.py b/pypy/module/sys/hook.py --- a/pypy/module/sys/hook.py +++ b/pypy/module/sys/hook.py @@ -3,7 +3,7 @@ def displayhook(space, w_obj): """Print an object to sys.stdout and also save it in __builtin__._""" if not space.is_w(w_obj, space.w_None): - space.setitem(space.builtin.w_dict, space.wrap('_'), w_obj) + space.setitem(space.builtin.w_dict, space.newtext('_'), w_obj) # NB. this is slightly more complicated in CPython, # see e.g. the difference with >>> print 5,; 8 print_item_to(space, space.repr(w_obj), sys_stdout(space)) diff --git a/pypy/module/sys/initpath.py b/pypy/module/sys/initpath.py --- a/pypy/module/sys/initpath.py +++ b/pypy/module/sys/initpath.py @@ -117,7 +117,7 @@ if state is not None: # 'None' for testing only lib_extensions = os.path.join(lib_pypy, '__extensions__') - state.w_lib_extensions = state.space.wrap(lib_extensions) + state.w_lib_extensions = state.space.newtext(lib_extensions) importlist.append(lib_extensions) importlist.append(lib_pypy) @@ -149,12 +149,12 @@ @unwrap_spec(executable='str0') def pypy_find_executable(space, executable): - return space.wrap(find_executable(executable)) + return space.newtext(find_executable(executable)) @unwrap_spec(filename='str0') def pypy_resolvedirof(space, filename): - return space.wrap(resolvedirof(filename)) + return space.newtext(resolvedirof(filename)) @unwrap_spec(executable='str0') @@ -171,10 +171,10 @@ path, prefix = find_stdlib(get_state(space), dyn_path) if path is None: return space.w_None - w_prefix = space.wrap(prefix) - space.setitem(space.sys.w_dict, space.wrap('prefix'), w_prefix) - space.setitem(space.sys.w_dict, space.wrap('exec_prefix'), w_prefix) - return space.newlist([space.wrap(p) for p in path]) + w_prefix = space.newtext(prefix) + space.setitem(space.sys.w_dict, space.newtext('prefix'), w_prefix) + space.setitem(space.sys.w_dict, space.newtext('exec_prefix'), w_prefix) + return space.newlist([space.newtext(p) for p in path]) # ____________________________________________________________ diff --git a/pypy/module/sys/interp_encoding.py b/pypy/module/sys/interp_encoding.py --- a/pypy/module/sys/interp_encoding.py +++ b/pypy/module/sys/interp_encoding.py @@ -5,14 +5,14 @@ def getdefaultencoding(space): """Return the current default string encoding used by the Unicode implementation.""" - return space.wrap(space.sys.defaultencoding) + return space.newtext(space.sys.defaultencoding) def setdefaultencoding(space, w_encoding): """Set the current default string encoding used by the Unicode implementation.""" encoding = space.str_w(w_encoding) mod = space.getbuiltinmodule("_codecs") - w_lookup = space.getattr(mod, space.wrap("lookup")) + w_lookup = space.getattr(mod, space.newtext("lookup")) # check whether the encoding is there space.call_function(w_lookup, w_encoding) space.sys.w_default_encoder = None @@ -21,11 +21,11 @@ def get_w_default_encoder(space): assert not (space.config.translating and not we_are_translated()), \ "get_w_default_encoder() should not be called during translation" - w_encoding = space.wrap(space.sys.defaultencoding) + w_encoding = space.newtext(space.sys.defaultencoding) mod = space.getbuiltinmodule("_codecs") - w_lookup = space.getattr(mod, space.wrap("lookup")) + w_lookup = space.getattr(mod, space.newtext("lookup")) w_functuple = space.call_function(w_lookup, w_encoding) - w_encoder = space.getitem(w_functuple, space.wrap(0)) + w_encoder = space.getitem(w_functuple, space.newint(0)) space.sys.w_default_encoder = w_encoder # cache it return w_encoder @@ -51,7 +51,7 @@ if loc_codeset: codecmod = space.getbuiltinmodule('_codecs') w_res = space.call_method(codecmod, 'lookup', - space.wrap(loc_codeset)) + space.newtext(loc_codeset)) if space.is_true(w_res): encoding = loc_codeset finally: @@ -66,4 +66,4 @@ """ if space.sys.filesystemencoding is None: space.sys.filesystemencoding = _getfilesystemencoding(space) - return space.wrap(space.sys.filesystemencoding) + return space.newtext(space.sys.filesystemencoding) diff --git a/pypy/module/sys/state.py b/pypy/module/sys/state.py --- a/pypy/module/sys/state.py +++ b/pypy/module/sys/state.py @@ -22,7 +22,7 @@ # Initialize the default path srcdir = os.path.dirname(pypydir) path = compute_stdlib_path(self, srcdir) - self.w_path = space.newlist([space.wrap(p) for p in path]) + self.w_path = space.newlist([space.newtext(p) for p in path]) def get(space): return space.fromcache(State) @@ -33,22 +33,22 @@ from pypy.module._file.interp_file import W_File self.space = space - stdin = W_File(space) - stdin.file_fdopen(0, "r", 1) - stdin.w_name = space.wrap('<stdin>') - self.w_stdin = space.wrap(stdin) + w_stdin = W_File(space) + w_stdin.file_fdopen(0, "r", 1) + w_stdin.w_name = space.newtext('<stdin>') + self.w_stdin = w_stdin - stdout = W_File(space) - stdout.file_fdopen(1, "w", 1) - stdout.w_name = space.wrap('<stdout>') - self.w_stdout = space.wrap(stdout) + w_stdout = W_File(space) + w_stdout.file_fdopen(1, "w", 1) + w_stdout.w_name = space.newtext('<stdout>') + self.w_stdout = w_stdout - stderr = W_File(space) - stderr.file_fdopen(2, "w", 0) - stderr.w_name = space.wrap('<stderr>') - self.w_stderr = space.wrap(stderr) + w_stderr = W_File(space) + w_stderr.file_fdopen(2, "w", 0) + w_stderr.w_name = space.newtext('<stderr>') + self.w_stderr = w_stderr - stdin._when_reading_first_flush(stdout) + w_stdin._when_reading_first_flush(w_stdout) def getio(space): return space.fromcache(IOState) @@ -58,4 +58,4 @@ """NOT_RPYTHON (should be removed from interpleveldefs before translation)""" from rpython.tool.udir import udir - return space.wrap(str(udir)) + return space.newtext(str(udir)) diff --git a/pypy/module/sys/system.py b/pypy/module/sys/system.py --- a/pypy/module/sys/system.py +++ b/pypy/module/sys/system.py @@ -31,17 +31,17 @@ def get_float_info(space): info_w = [ - space.wrap(rfloat.DBL_MAX), - space.wrap(rfloat.DBL_MAX_EXP), - space.wrap(rfloat.DBL_MAX_10_EXP), - space.wrap(rfloat.DBL_MIN), - space.wrap(rfloat.DBL_MIN_EXP), - space.wrap(rfloat.DBL_MIN_10_EXP), - space.wrap(rfloat.DBL_DIG), - space.wrap(rfloat.DBL_MANT_DIG), - space.wrap(rfloat.DBL_EPSILON), - space.wrap(rfloat.FLT_RADIX), - space.wrap(rfloat.FLT_ROUNDS), + space.newfloat(rfloat.DBL_MAX), + space.newint(rfloat.DBL_MAX_EXP), + space.newint(rfloat.DBL_MAX_10_EXP), + space.newfloat(rfloat.DBL_MIN), + space.newint(rfloat.DBL_MIN_EXP), + space.newint(rfloat.DBL_MIN_10_EXP), + space.newint(rfloat.DBL_DIG), + space.newint(rfloat.DBL_MANT_DIG), + space.newfloat(rfloat.DBL_EPSILON), + space.newint(rfloat.FLT_RADIX), + space.newint(rfloat.FLT_ROUNDS), ] w_float_info = app.wget(space, "float_info") return space.call_function(w_float_info, space.newtuple(info_w)) @@ -50,17 +50,17 @@ bits_per_digit = rbigint.SHIFT sizeof_digit = rffi.sizeof(rbigint.STORE_TYPE) info_w = [ - space.wrap(bits_per_digit), - space.wrap(sizeof_digit), + space.newint(bits_per_digit), + space.newint(sizeof_digit), ] w_long_info = app.wget(space, "long_info") return space.call_function(w_long_info, space.newtuple(info_w)) def get_float_repr_style(space): - return space.wrap("short") + return space.newtext("short") def getdlopenflags(space): - return space.wrap(space.sys.dlopenflags) + return space.newint(space.sys.dlopenflags) def setdlopenflags(space, w_flags): space.sys.dlopenflags = space.int_w(w_flags) diff --git a/pypy/module/sys/version.py b/pypy/module/sys/version.py --- a/pypy/module/sys/version.py +++ b/pypy/module/sys/version.py @@ -42,10 +42,11 @@ ''') def get_api_version(space): - return space.wrap(CPYTHON_API_VERSION) + return space.newint(CPYTHON_API_VERSION) def get_version_info(space): w_version_info = app.wget(space, "version_info") + # run at translation time return space.call_function(w_version_info, space.wrap(CPYTHON_VERSION)) def _make_version_template(PYPY_VERSION=PYPY_VERSION): @@ -65,31 +66,33 @@ _VERSION_TEMPLATE = _make_version_template() def get_version(space): - return space.wrap(_VERSION_TEMPLATE % compilerinfo.get_compiler_info()) + return space.newtext(_VERSION_TEMPLATE % compilerinfo.get_compiler_info()) def get_winver(space): - return space.wrap("%d.%d" % ( + return space.newtext("%d.%d" % ( CPYTHON_VERSION[0], CPYTHON_VERSION[1])) def get_hexversion(space): - return space.wrap(tuple2hex(CPYTHON_VERSION)) + return space.newint(tuple2hex(CPYTHON_VERSION)) def get_pypy_version_info(space): ver = PYPY_VERSION w_version_info = app.wget(space, "version_info") + # run at translation time return space.call_function(w_version_info, space.wrap(ver)) def get_subversion_info(space): + # run at translation time return space.wrap(('PyPy', '', '')) def get_repo_info(space): info = get_repo_version_info(root=pypyroot) if info: repo_tag, repo_version = info - return space.newtuple([space.wrap('PyPy'), - space.wrap(repo_tag), - space.wrap(repo_version)]) + return space.newtuple([space.newtext('PyPy'), + space.newtext(repo_tag), + space.newtext(repo_version)]) else: return space.w_None diff --git a/pypy/module/sys/vm.py b/pypy/module/sys/vm.py --- a/pypy/module/sys/vm.py +++ b/pypy/module/sys/vm.py @@ -36,7 +36,7 @@ raise oefmt(space.w_ValueError, "call stack is not deep enough") if depth == 0: f.mark_as_escaped() - return space.wrap(f) + return f depth -= 1 f = ec.getnextframe_nohidden(f) @@ -59,14 +59,14 @@ def getrecursionlimit(space): """Return the last value set by setrecursionlimit(). """ - return space.wrap(space.sys.recursionlimit) + return space.newint(space.sys.recursionlimit) @unwrap_spec(flag=bool) def set_track_resources(space, flag): space.sys.track_resources = flag def get_track_resources(space): - return space.wrap(space.sys.track_resources) + return space.newbool(space.sys.track_resources) @unwrap_spec(interval=int) def setcheckinterval(space, interval): @@ -84,7 +84,7 @@ result = space.actionflag.getcheckinterval() if result <= 1: result = 0 - return space.wrap(result) + return space.newint(result) def exc_info(space): """Return the (type, value, traceback) of the most recent exception @@ -98,7 +98,7 @@ return space.newtuple([space.w_None, space.w_None, space.w_None]) else: return space.newtuple([operror.w_type, operror.get_w_value(space), - space.wrap(operror.get_traceback())]) + operror.get_traceback()]) def exc_info_without_tb(space, frame): operror = frame.last_exception @@ -235,7 +235,7 @@ @jit.dont_look_inside def get_dllhandle(space): if not space.config.objspace.usemodules.cpyext: - return space.wrap(0) + return space.newint(0) return _get_dllhandle(space) @@ -248,10 +248,10 @@ # from pypy.module._rawffi.interp_rawffi import W_CDLL # from rpython.rlib.clibffi import RawCDLL # cdll = RawCDLL(handle) - # return space.wrap(W_CDLL(space, "python api", cdll)) + # return W_CDLL(space, "python api", cdll) # Provide a cpython-compatible int from rpython.rtyper.lltypesystem import lltype, rffi - return space.wrap(rffi.cast(lltype.Signed, handle)) + return space.newint(rffi.cast(lltype.Signed, handle)) getsizeof_missing = """sys.getsizeof() is not implemented on PyPy. _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit