Author: Mark Young <marky1...@gmail.com> Branch: py3k-clock_get_info Changeset: r84764:e7720cf7a556 Date: 2016-05-24 21:16 -0400 http://bitbucket.org/pypy/pypy/changeset/e7720cf7a556/
Log: Let's try this. diff --git a/lib-python/3/sysconfig.py b/lib-python/3/sysconfig.py --- a/lib-python/3/sysconfig.py +++ b/lib-python/3/sysconfig.py @@ -42,6 +42,16 @@ 'scripts': '{base}/bin', 'data': '{base}', }, + 'pypy': { + 'stdlib': '{installed_base}/lib-python', + 'platstdlib': '{base}/lib-python', + 'purelib': '{base}/lib-python', + 'platlib': '{base}/lib-python', + 'include': '{installed_base}/include', + 'platinclude': '{installed_base}/include', + 'scripts': '{base}/bin', + 'data' : '{base}', + }, 'nt': { 'stdlib': '{installed_base}/Lib', 'platstdlib': '{base}/Lib', @@ -198,7 +208,9 @@ def _get_default_scheme(): - if os.name == 'posix': + if '__pypy__' in sys.builtin_module_names: + return 'pypy' + elif os.name == 'posix': # the default scheme for posix is posix_prefix return 'posix_prefix' return os.name diff --git a/lib-python/3/tempfile.py b/lib-python/3/tempfile.py --- a/lib-python/3/tempfile.py +++ b/lib-python/3/tempfile.py @@ -34,6 +34,7 @@ import os as _os import shutil as _shutil import errno as _errno +import weakref as _weakref from random import Random as _Random try: @@ -686,6 +687,7 @@ def __init__(self, suffix="", prefix=template, dir=None): self.name = mkdtemp(suffix, prefix, dir) + _tmpdirs.add(self) def __repr__(self): return "<{} {!r}>".format(self.__class__.__name__, self.name) @@ -714,6 +716,7 @@ def __exit__(self, exc, value, tb): self.cleanup() + _tmpdirs.discard(self) def __del__(self): # Issue a ResourceWarning if implicit cleanup needed @@ -736,10 +739,23 @@ except _OSError: pass +_tmpdirs = _weakref.WeakSet() _is_running = True +def _tmpdir_cleanup(): + while _tmpdirs: + try: + tmpdir = _tmpdirs.pop() + except KeyError: + break + try: + tmpdir.cleanup(_warn=True) + except: + pass + def _on_shutdown(): global _is_running + _tmpdir_cleanup() _is_running = False _atexit.register(_on_shutdown) diff --git a/lib-python/3/test/test_descr.py b/lib-python/3/test/test_descr.py --- a/lib-python/3/test/test_descr.py +++ b/lib-python/3/test/test_descr.py @@ -4533,6 +4533,9 @@ self.assertEqual(type(d).__name__, n + '_descriptor') for d in descriptors: + if (support.check_impl_detail(pypy=True) and + not hasattr(d, '__objclass__')): + continue qualname = d.__objclass__.__qualname__ + '.' + d.__name__ self.assertEqual(d.__qualname__, qualname) @@ -4574,6 +4577,8 @@ for o in gc.get_objects(): self.assertIsNot(type(o), X) + @unittest.skipIf(support.check_impl_detail(pypy=True), + "https://bitbucket.org/pypy/pypy/issues/2306") def test_object_new_and_init_with_parameters(self): # See issue #1683368 class OverrideNeither: diff --git a/lib-python/3/test/test_sysconfig.py b/lib-python/3/test/test_sysconfig.py --- a/lib-python/3/test/test_sysconfig.py +++ b/lib-python/3/test/test_sysconfig.py @@ -239,7 +239,7 @@ def test_get_scheme_names(self): wanted = ('nt', 'nt_user', 'os2', 'os2_home', 'osx_framework_user', - 'posix_home', 'posix_prefix', 'posix_user') + 'posix_home', 'posix_prefix', 'posix_user', 'pypy') self.assertEqual(get_scheme_names(), wanted) @skip_unless_symlink @@ -345,6 +345,7 @@ self.assertEqual(status, 0) self.assertEqual(my_platform, test_platform) + @impl_detail("Test is not PyPy compatible", pypy=False) def test_srcdir(self): # See Issues #15322, #15364. srcdir = sysconfig.get_config_var('srcdir') @@ -379,7 +380,7 @@ class MakefileTests(unittest.TestCase): - @impl_detail("PyPy lacks sysconfig.get_makefile_filename", pypy=False) + @impl_detail("Test is not PyPy compatible", pypy=False) @unittest.skipIf(sys.platform.startswith('win'), 'Test is not Windows compatible') def test_get_makefile_filename(self): diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py --- a/pypy/config/pypyoption.py +++ b/pypy/config/pypyoption.py @@ -18,6 +18,8 @@ "exceptions", "_io", "sys", "builtins", "posix", "_warnings", "itertools", "_frozen_importlib", ]) +if sys.platform == "win32": + essential_modules.add("_winreg") default_modules = essential_modules.copy() default_modules.update([ @@ -60,7 +62,6 @@ # XXX this should move somewhere else, maybe to platform ("is this posixish" # check or something) if sys.platform == "win32": - working_modules.add("_winreg") # unix only modules for name in ["crypt", "fcntl", "pwd", "termios", "_minimal_curses", "_posixsubprocess"]: diff --git a/pypy/conftest.py b/pypy/conftest.py --- a/pypy/conftest.py +++ b/pypy/conftest.py @@ -185,29 +185,7 @@ __multicall__.execute() def pytest_runtest_teardown(__multicall__, item): - user_del_action = None - if isinstance(item, py.test.collect.Function): - appclass = item.getparent(PyPyClassCollector) - if (appclass is not None and - not getattr(appclass.obj, 'runappdirect', False) and - hasattr(appclass.obj, 'space')): - user_del_action = appclass.obj.space.user_del_action - - if user_del_action: - # if leakfinder triggers leftover __del__s, ensure their - # enqueue_for_destruction callbacks are invoked immediately - # instead of scheduled for later (potentially never) - user_del_action._invoke_immediately = True - try: - # leakfinder - __multicall__.execute() - finally: - if user_del_action: - user_del_action._invoke_immediately = False - - if 'pygame' in sys.modules: - assert option.view, ("should not invoke Pygame " - "if conftest.option.view is False") + __multicall__.execute() class PyPyClassCollector(py.test.collect.Class): 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 @@ -2,7 +2,7 @@ # This is pure Python code that handles the main entry point into "pypy". # See test/test_app_main. -# Missing vs CPython: -b, -d, -x, -3 +# Missing vs CPython: -b, -d, -x from __future__ import print_function, unicode_literals USAGE1 = __doc__ = """\ Options and arguments (and corresponding environment variables): @@ -16,10 +16,10 @@ -O : skip assert statements; also PYTHONOPTIMIZE=x -OO : remove docstrings when importing modules in addition to -O -q : don't print version and copyright messages on interactive startup --R : ignored (see http://bugs.python.org/issue14621) -s : don't add user site directory to sys.path; also PYTHONNOUSERSITE -S : don't imply 'import site' on initialization --u : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x +-u : unbuffered binary stdout and stderr, stdin always buffered; + also PYTHONUNBUFFERED=x -v : verbose (trace import statements); also PYTHONVERBOSE=x can be supplied multiple times to increase verbosity -V : print the Python version number and exit (also --version) @@ -379,6 +379,9 @@ def end_options(options, _, iterargv): return list(iterargv) +def ignore_option(*args): + pass + cmdline_options = { # simple options just increment the counter of the options listed above 'b': (simple_option, 'bytes_warning'), @@ -387,7 +390,6 @@ 'E': (simple_option, 'ignore_environment'), 'i': (simple_option, 'interactive'), 'O': (simple_option, 'optimize'), - 'R': (simple_option, 'hash_randomization'), 's': (simple_option, 'no_user_site'), 'S': (simple_option, 'no_site'), 'u': (simple_option, 'unbuffered'), @@ -407,6 +409,7 @@ '--jit': (set_jit_option, Ellipsis), '-funroll-loops': (funroll_loops, None), '--': (end_options, None), + 'R': (ignore_option, None), # previously hash_randomization } def handle_argument(c, options, iterargv, iterarg=iter(())): diff --git a/pypy/interpreter/astcompiler/test/test_ast.py b/pypy/interpreter/astcompiler/test/test_ast.py --- a/pypy/interpreter/astcompiler/test/test_ast.py +++ b/pypy/interpreter/astcompiler/test/test_ast.py @@ -1,8 +1,8 @@ from pypy.interpreter.astcompiler import ast class TestAstToObject: def test_types(self, space): - assert space.is_true(space.issubtype( - ast.get(space).w_Module, ast.get(space).w_mod)) + assert space.issubtype_w( + ast.get(space).w_Module, ast.get(space).w_mod) def test_num(self, space): value = space.wrap(42) diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -593,9 +593,6 @@ # lives in pypy/module/exceptions, we rename it below for # sys.builtin_module_names bootstrap_modules = set(('sys', 'imp', 'builtins', 'exceptions')) - if sys.platform.startswith("win"): - self.setbuiltinmodule('_winreg') - bootstrap_modules.add('winreg') installed_builtin_modules = list(bootstrap_modules) exception_types_w = self.export_builtin_exceptions() @@ -1206,7 +1203,7 @@ def abstract_issubclass_w(self, w_cls1, w_cls2): # Equivalent to 'issubclass(cls1, cls2)'. - return self.is_true(self.issubtype(w_cls1, w_cls2)) + return self.issubtype_w(w_cls1, w_cls2) def abstract_isinstance_w(self, w_obj, w_cls): # Equivalent to 'isinstance(obj, cls)'. @@ -1236,16 +1233,16 @@ def exception_is_valid_obj_as_class_w(self, w_obj): if not self.isinstance_w(w_obj, self.w_type): return False - return self.is_true(self.issubtype(w_obj, self.w_BaseException)) + return self.issubtype_w(w_obj, self.w_BaseException) def exception_is_valid_class_w(self, w_cls): - return self.is_true(self.issubtype(w_cls, self.w_BaseException)) + return self.issubtype_w(w_cls, self.w_BaseException) def exception_getclass(self, w_obj): return self.type(w_obj) def exception_issubclass_w(self, w_cls1, w_cls2): - return self.is_true(self.issubtype(w_cls1, w_cls2)) + return self.issubtype_w(w_cls1, w_cls2) def new_exception_class(self, *args, **kwargs): "NOT_RPYTHON; convenience method to create excceptions in modules" diff --git a/pypy/interpreter/executioncontext.py b/pypy/interpreter/executioncontext.py --- a/pypy/interpreter/executioncontext.py +++ b/pypy/interpreter/executioncontext.py @@ -539,8 +539,6 @@ self.pending_with_disabled_del = None def perform(self, executioncontext, frame): - if self.finalizers_lock_count > 0: - return self._run_finalizers() @jit.dont_look_inside diff --git a/pypy/interpreter/pyparser/gendfa.py b/pypy/interpreter/pyparser/gendfa.py --- a/pypy/interpreter/pyparser/gendfa.py +++ b/pypy/interpreter/pyparser/gendfa.py @@ -202,7 +202,7 @@ newArcPair(states, EMPTY), pseudoExtras, number, funny, contStr, name)) dfaStates, dfaAccepts = nfaToDfa(states, *pseudoToken) - return DFA(dfaStates, dfaAccepts) + return DFA(dfaStates, dfaAccepts), dfaStates # ______________________________________________________________________ @@ -216,7 +216,9 @@ newArcPair(states, DEFAULT), any(states, notGroupStr(states, "'\\")))), newArcPair(states, "'")) - singleDFA = DFA(*nfaToDfa(states, *single)) + states, accepts = nfaToDfa(states, *single) + singleDFA = DFA(states, accepts) + states_singleDFA = states states = [] double = chain(states, any(states, notGroupStr(states, '"\\')), @@ -226,7 +228,9 @@ newArcPair(states, DEFAULT), any(states, notGroupStr(states, '"\\')))), newArcPair(states, '"')) - doubleDFA = DFA(*nfaToDfa(states, *double)) + states, accepts = nfaToDfa(states, *double) + doubleDFA = DFA(states, accepts) + states_doubleDFA = states states = [] single3 = chain(states, any(states, notGroupStr(states, "'\\")), @@ -241,7 +245,9 @@ notChainStr(states, "''"))), any(states, notGroupStr(states, "'\\")))), chainStr(states, "'''")) - single3DFA = NonGreedyDFA(*nfaToDfa(states, *single3)) + states, accepts = nfaToDfa(states, *single3) + single3DFA = NonGreedyDFA(states, accepts) + states_single3DFA = states states = [] double3 = chain(states, any(states, notGroupStr(states, '"\\')), @@ -256,27 +262,34 @@ notChainStr(states, '""'))), any(states, notGroupStr(states, '"\\')))), chainStr(states, '"""')) - double3DFA = NonGreedyDFA(*nfaToDfa(states, *double3)) - return {"'" : singleDFA, - '"' : doubleDFA, - "'''": single3DFA, - '"""': double3DFA} + states, accepts = nfaToDfa(states, *double3) + double3DFA = NonGreedyDFA(states, accepts) + states_double3DFA = states + return {"'" : (singleDFA, states_singleDFA), + '"' : (doubleDFA, states_doubleDFA), + "'''": (single3DFA, states_single3DFA), + '"""': (double3DFA, states_double3DFA)} # ______________________________________________________________________ -def output(name, dfa_class, dfa): +def output(name, dfa_class, dfa, states): import textwrap + lines = [] i = 0 for line in textwrap.wrap(repr(dfa.accepts), width = 50): if i == 0: - print "accepts =", line + lines.append("accepts = ") else: - print " ", line + lines.append(" ") + lines.append(line) + lines.append("\n") i += 1 import StringIO - print "states = [" - for numstate, state in enumerate(dfa.states): - print " #", numstate + lines.append("states = [\n") + for numstate, state in enumerate(states): + lines.append(" # ") + lines.append(str(numstate)) + lines.append("\n") s = StringIO.StringIO() i = 0 for k, v in sorted(state.items()): @@ -299,13 +312,15 @@ for line in text: line = line.replace('::', ': ') if i == 0: - print ' {' + line + lines.append(' {') else: - print ' ' + line + lines.append(' ') + lines.append(line) + lines.append('\n') i += 1 - print " ]" - print "%s = automata.%s(states, accepts)" % (name, dfa_class) - print + lines.append(" ]\n") + lines.append("%s = automata.%s(states, accepts)\n" % (name, dfa_class)) + return ''.join(lines) def main (): print "# THIS FILE IS AUTOMATICALLY GENERATED BY gendfa.py" @@ -314,13 +329,17 @@ print "# python gendfa.py > dfa_generated.py" print print "from pypy.interpreter.pyparser import automata" - pseudoDFA = makePyPseudoDFA() - output("pseudoDFA", "DFA", pseudoDFA) + pseudoDFA, states_pseudoDFA = makePyPseudoDFA() + print output("pseudoDFA", "DFA", pseudoDFA, states_pseudoDFA) endDFAMap = makePyEndDFAMap() - output("double3DFA", "NonGreedyDFA", endDFAMap['"""']) - output("single3DFA", "NonGreedyDFA", endDFAMap["'''"]) - output("singleDFA", "DFA", endDFAMap["'"]) - output("doubleDFA", "DFA", endDFAMap['"']) + dfa, states = endDFAMap['"""'] + print output("double3DFA", "NonGreedyDFA", dfa, states) + dfa, states = endDFAMap["'''"] + print output("single3DFA", "NonGreedyDFA", dfa, states) + dfa, states = endDFAMap["'"] + print output("singleDFA", "DFA", dfa, states) + dfa, states = endDFAMap['"'] + print output("doubleDFA", "DFA", dfa, states) # ______________________________________________________________________ diff --git a/pypy/interpreter/pyparser/test/test_gendfa.py b/pypy/interpreter/pyparser/test/test_gendfa.py new file mode 100644 --- /dev/null +++ b/pypy/interpreter/pyparser/test/test_gendfa.py @@ -0,0 +1,16 @@ +from pypy.interpreter.pyparser.automata import DFA, DEFAULT +from pypy.interpreter.pyparser.gendfa import output + +def test_states(): + states = [{"\x00": 1}, {"\x01": 0}] + d = DFA(states[:], [False, True]) + assert output('test', DFA, d, states) == """\ +accepts = [False, True] +states = [ + # 0 + {'\\x00': 1}, + # 1 + {'\\x01': 0}, + ] +test = automata.pypy.interpreter.pyparser.automata.DFA(states, accepts) +""" diff --git a/pypy/interpreter/test/conftest.py b/pypy/interpreter/test/conftest.py new file mode 100644 --- /dev/null +++ b/pypy/interpreter/test/conftest.py @@ -0,0 +1,13 @@ +from pypy.conftest import PYTHON3 + +def get_banner(): + import subprocess + p = subprocess.Popen([PYTHON3, "-c", + "import sys; print(sys.version.splitlines()[0])"], + stdout=subprocess.PIPE) + return p.stdout.read().rstrip() +banner = get_banner() if PYTHON3 else "PYTHON3 not found" + +def pytest_report_header(config): + if PYTHON3: + return "PYTHON3: %s\n(Version %s)" % (PYTHON3, banner) diff --git a/pypy/interpreter/test/test_app_main.py b/pypy/interpreter/test/test_app_main.py --- a/pypy/interpreter/test/test_app_main.py +++ b/pypy/interpreter/test/test_app_main.py @@ -6,22 +6,20 @@ import sys, os, re, runpy, subprocess from rpython.tool.udir import udir from contextlib import contextmanager -from pypy.conftest import pypydir +from pypy.conftest import PYTHON3, pypydir +from pypy.interpreter.test.conftest import banner from lib_pypy._pypy_interact import irc_header - -python3 = os.environ.get("PYTHON3", "python3") - -def get_banner(): - p = subprocess.Popen([python3, "-c", - "import sys; print(sys.version.splitlines()[0])"], - stdout=subprocess.PIPE) - return p.stdout.read().rstrip() -banner = get_banner() - app_main = os.path.join(os.path.realpath(os.path.dirname(__file__)), os.pardir, 'app_main.py') app_main = os.path.abspath(app_main) +def get_python3(): + if PYTHON3: + return PYTHON3 + import py.test + py.test.fail("Test requires 'python3' (not found in PATH) or a PYTHON3 " + "environment variable set") + _counter = 0 def _get_next_path(ext='.py'): global _counter @@ -37,7 +35,7 @@ def getscript_pyc(space, source): p = _get_next_path() p.write(str(py.code.Source(source))) - subprocess.check_call([python3, "-c", "import " + p.purebasename], + subprocess.check_call([get_python3(), "-c", "import " + p.purebasename], env={'PYTHONPATH': str(p.dirpath())}) # the .pyc file should have been created above pycache = p.dirpath('__pycache__') @@ -99,7 +97,7 @@ "option %r has unexpectedly the value %r" % (key, value)) def check(self, argv, env, **expected): - p = subprocess.Popen([python3, app_main, + p = subprocess.Popen([get_python3(), app_main, '--argparse-only'] + list(argv), stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) @@ -240,7 +238,7 @@ def spawn(self, argv, env=None): # make sure that when we do 'import pypy' we get the correct package with setpythonpath(): - return self._spawn(python3, [app_main] + argv, env=env) + return self._spawn(get_python3(), [app_main] + argv, env=env) def test_interactive(self): child = self.spawn([]) @@ -529,7 +527,7 @@ if sys.platform == "win32": skip("close_fds is not supported on Windows platforms") import subprocess, select, os - pipe = subprocess.Popen([python3, app_main, "-u", "-i"], + pipe = subprocess.Popen([get_python3(), app_main, "-u", "-i"], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT, @@ -624,7 +622,7 @@ import __pypy__ except: py.test.skip('app_main cannot run on non-pypy for windows') - cmdline = '%s %s "%s" %s' % (python3, python_flags, + cmdline = '%s %s "%s" %s' % (get_python3(), python_flags, app_main, cmdline) print 'POPEN:', cmdline process = subprocess.Popen( @@ -813,7 +811,7 @@ time.sleep(1) # stdout flushed automatically here """) - cmdline = '%s -E "%s" %s' % (python3, app_main, path) + cmdline = '%s -E "%s" %s' % (get_python3(), app_main, path) print 'POPEN:', cmdline child_in, child_out_err = os.popen4(cmdline) data = child_out_err.read(11) @@ -840,7 +838,7 @@ if 'stderr' in streams: os.close(2) p = subprocess.Popen( - [python3, app_main, "-E", "-c", code], + [get_python3(), app_main, "-E", "-c", code], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, diff --git a/pypy/module/__builtin__/abstractinst.py b/pypy/module/__builtin__/abstractinst.py --- a/pypy/module/__builtin__/abstractinst.py +++ b/pypy/module/__builtin__/abstractinst.py @@ -73,11 +73,10 @@ try: if space.is_w(w_pretendtype, space.type(w_obj)): return False # common case: obj.__class__ is type(obj) - if allow_override: - w_result = space.issubtype_allow_override(w_pretendtype, - w_klass_or_tuple) - else: - w_result = space.issubtype(w_pretendtype, w_klass_or_tuple) + if not allow_override: + return space.issubtype_w(w_pretendtype, w_klass_or_tuple) + w_result = space.issubtype_allow_override(w_pretendtype, + w_klass_or_tuple) except OperationError as e: if e.async(space): raise @@ -130,11 +129,9 @@ # -- case (type, type) try: - if allow_override: - w_result = space.issubtype_allow_override(w_derived, - w_klass_or_tuple) - else: - w_result = space.issubtype(w_derived, w_klass_or_tuple) + if not allow_override: + return space.issubtype_w(w_derived, w_klass_or_tuple) + w_result = space.issubtype_allow_override(w_derived, w_klass_or_tuple) except OperationError as e: # if one of the args was not a type, ignore it if not e.match(space, space.w_TypeError): raise # propagate other errors diff --git a/pypy/module/__builtin__/descriptor.py b/pypy/module/__builtin__/descriptor.py --- a/pypy/module/__builtin__/descriptor.py +++ b/pypy/module/__builtin__/descriptor.py @@ -15,12 +15,14 @@ def descr_init(self, space, w_starttype=None, w_obj_or_type=None): if space.is_none(w_starttype): - w_starttype, w_obj_or_type = _super_from_frame(space) + frame = space.getexecutioncontext().gettopframe() + w_starttype, w_obj_or_type = _super_from_frame(space, frame) + if space.is_none(w_obj_or_type): w_type = None # unbound super object w_obj_or_type = space.w_None else: - w_type = _supercheck(space, w_starttype, w_obj_or_type) + w_type = _super_check(space, w_starttype, w_obj_or_type) self.w_starttype = w_starttype self.w_objtype = w_type self.w_self = w_obj_or_type @@ -57,11 +59,10 @@ # fallback to object.__getattribute__() return space.call_function(object_getattribute(space), self, w_name) -def _super_from_frame(space): +def _super_from_frame(space, frame): """super() without args -- fill in from __class__ and first local variable on the stack. """ - frame = space.getexecutioncontext().gettopframe() code = frame.pycode if not code: raise oefmt(space.w_RuntimeError, "super(): no code object") @@ -70,8 +71,9 @@ w_obj = frame.locals_cells_stack_w[0] if not w_obj: raise oefmt(space.w_RuntimeError, "super(): arg[0] deleted") + for index, name in enumerate(code.co_freevars): - if name == "__class__": + if name == '__class__': break else: raise oefmt(space.w_RuntimeError, "super(): __class__ cell not found") @@ -83,16 +85,16 @@ raise oefmt(space.w_RuntimeError, "super(): empty __class__ cell") return w_starttype, w_obj -def _supercheck(space, w_starttype, w_obj_or_type): +def _super_check(space, w_starttype, w_obj_or_type): """Check that the super() call makes sense. Returns a type""" w_objtype = space.type(w_obj_or_type) - if (space.is_true(space.issubtype(w_objtype, space.w_type)) and - space.is_true(space.issubtype(w_obj_or_type, w_starttype))): + if (space.issubtype_w(w_objtype, space.w_type) and + space.issubtype_w(w_obj_or_type, w_starttype)): # special case for class methods return w_obj_or_type - if space.is_true(space.issubtype(w_objtype, w_starttype)): + if space.issubtype_w(w_objtype, w_starttype): # normal case return w_objtype @@ -103,7 +105,7 @@ raise w_type = w_objtype - if space.is_true(space.issubtype(w_type, w_starttype)): + if space.issubtype_w(w_type, w_starttype): return w_type raise oefmt(space.w_TypeError, "super(type, obj): obj must be an instance or subtype of type") diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py --- a/pypy/module/cpyext/api.py +++ b/pypy/module/cpyext/api.py @@ -708,7 +708,7 @@ w_obj_type = space.type(w_obj) w_type = get_w_type(space) return (space.is_w(w_obj_type, w_type) or - space.is_true(space.issubtype(w_obj_type, w_type))) + space.issubtype_w(w_obj_type, w_type)) def check_exact(space, w_obj): "Implements the Py_Xxx_CheckExact function" w_obj_type = space.type(w_obj) diff --git a/pypy/module/cpyext/modsupport.py b/pypy/module/cpyext/modsupport.py --- a/pypy/module/cpyext/modsupport.py +++ b/pypy/module/cpyext/modsupport.py @@ -100,7 +100,7 @@ w_type = space.gettypeobject(Module.typedef) w_obj_type = space.type(w_obj) return int(space.is_w(w_type, w_obj_type) or - space.is_true(space.issubtype(w_obj_type, w_type))) + space.issubtype_w(w_obj_type, w_type)) @cpython_api([PyObject], PyObject, result_borrowed=True) def PyModule_GetDict(space, w_mod): diff --git a/pypy/module/cpyext/ndarrayobject.py b/pypy/module/cpyext/ndarrayobject.py --- a/pypy/module/cpyext/ndarrayobject.py +++ b/pypy/module/cpyext/ndarrayobject.py @@ -35,7 +35,7 @@ w_obj_type = space.type(w_obj) w_type = space.gettypeobject(W_NDimArray.typedef) return (space.is_w(w_obj_type, w_type) or - space.is_true(space.issubtype(w_obj_type, w_type))) + space.issubtype_w(w_obj_type, w_type)) @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL, header=HEADER) def _PyArray_CheckExact(space, w_obj): diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py --- a/pypy/module/cpyext/slotdefs.py +++ b/pypy/module/cpyext/slotdefs.py @@ -78,8 +78,7 @@ args_w = space.fixedview(w_args) ref = make_ref(space, w_self) if (not ref.c_ob_type.c_tp_flags & Py_TPFLAGS_CHECKTYPES and - not space.is_true(space.issubtype(space.type(args_w[0]), - space.type(w_self)))): + not space.issubtype_w(space.type(args_w[0]), space.type(w_self))): return space.w_NotImplemented Py_DecRef(space, ref) return generic_cpy_call(space, func_binary, w_self, args_w[0]) @@ -90,8 +89,7 @@ args_w = space.fixedview(w_args) ref = make_ref(space, w_self) if (not ref.c_ob_type.c_tp_flags & Py_TPFLAGS_CHECKTYPES and - not space.is_true(space.issubtype(space.type(args_w[0]), - space.type(w_self)))): + not space.issubtype_w(space.type(args_w[0]), space.type(w_self))): return space.w_NotImplemented Py_DecRef(space, ref) return generic_cpy_call(space, func_binary, args_w[0], w_self) @@ -113,8 +111,7 @@ args_w = space.fixedview(w_args) ref = make_ref(space, w_self) if (not ref.c_ob_type.c_tp_flags & Py_TPFLAGS_CHECKTYPES and - not space.is_true(space.issubtype(space.type(args_w[0]), - space.type(w_self)))): + not space.issubtype_w(space.type(args_w[0]), space.type(w_self))): return space.w_NotImplemented Py_DecRef(space, ref) arg3 = space.w_None @@ -346,8 +343,7 @@ check_num_args(space, w_args, 1) w_other, = space.fixedview(w_args) - if not space.is_true(space.issubtype(space.type(w_self), - space.type(w_other))): + if not space.issubtype_w(space.type(w_self), space.type(w_other)): raise oefmt(space.w_TypeError, "%T.__cmp__(x,y) requires y to be a '%T', not a '%T'", w_self, w_self, w_other) diff --git a/pypy/module/cpyext/test/test_typeobject.py b/pypy/module/cpyext/test/test_typeobject.py --- a/pypy/module/cpyext/test/test_typeobject.py +++ b/pypy/module/cpyext/test/test_typeobject.py @@ -723,7 +723,7 @@ long intval; PyObject *name; - if (!PyArg_ParseTuple(args, "l", &intval)) + if (!PyArg_ParseTuple(args, "i", &intval)) return NULL; IntLike_Type.tp_flags |= Py_TPFLAGS_DEFAULT; diff --git a/pypy/module/cpyext/tupleobject.py b/pypy/module/cpyext/tupleobject.py --- a/pypy/module/cpyext/tupleobject.py +++ b/pypy/module/cpyext/tupleobject.py @@ -47,7 +47,7 @@ def tuple_check_ref(space, ref): w_type = from_ref(space, rffi.cast(PyObject, ref.c_ob_type)) return (w_type is space.w_tuple or - space.is_true(space.issubtype(w_type, space.w_tuple))) + space.issubtype_w(w_type, space.w_tuple)) def new_empty_tuple(space, length): """ diff --git a/pypy/module/cpyext/unicodeobject.py b/pypy/module/cpyext/unicodeobject.py --- a/pypy/module/cpyext/unicodeobject.py +++ b/pypy/module/cpyext/unicodeobject.py @@ -233,7 +233,7 @@ buffer, NULL if unicode is not a Unicode object.""" # Don't use PyUnicode_Check, it will realize the object :-( w_type = from_ref(space, rffi.cast(PyObject, ref.c_ob_type)) - if not space.is_true(space.issubtype(w_type, space.w_unicode)): + if not space.issubtype_w(w_type, space.w_unicode): raise oefmt(space.w_TypeError, "expected unicode object") return PyUnicode_AS_UNICODE(space, rffi.cast(rffi.VOIDP, ref)) diff --git a/pypy/module/imp/test/support.py b/pypy/module/imp/test/support.py --- a/pypy/module/imp/test/support.py +++ b/pypy/module/imp/test/support.py @@ -4,8 +4,10 @@ def setup_class(cls): space = cls.space - cls.w_testfn_unencodable = space.wrap(get_unencodable()) - cls.w_special_char = space.wrap(get_special_char()) + cls.testfn_unencodable = get_unencodable() + cls.w_testfn_unencodable = space.wrap(cls.testfn_unencodable) + cls.special_char = get_special_char() + cls.w_special_char = space.wrap(cls.special_char) def get_unencodable(): """Copy of the stdlib's support.TESTFN_UNENCODABLE: diff --git a/pypy/module/imp/test/test_import.py b/pypy/module/imp/test/test_import.py --- a/pypy/module/imp/test/test_import.py +++ b/pypy/module/imp/test/test_import.py @@ -133,10 +133,9 @@ line2 = "# encoding: iso-8859-1\n", bad = "# encoding: uft-8\n") - w_special_char = getattr(cls, 'w_special_char', None) - if not space.is_none(w_special_char): - special_char = space.unicode_w(w_special_char).encode( - sys.getfilesystemencoding()) + special_char = cls.special_char + if special_char is not None: + special_char = special_char.encode(sys.getfilesystemencoding()) p.join(special_char + '.py').write('pass') # create a .pyw file @@ -746,54 +745,6 @@ else: raise AssertionError("should have failed") - def test_verbose_flag_1(self): - output = [] - class StdErr(object): - def write(self, line): - output.append(line) - - import sys, imp - old_flags = sys.flags - - class Flags(object): - verbose = 1 - def __getattr__(self, name): - return getattr(old_flags, name) - - sys.flags = Flags() - sys.stderr = StdErr() - try: - import verbose1pkg.verbosemod - finally: - imp.reload(sys) - assert 'import verbose1pkg # ' in output[-2] - assert 'import verbose1pkg.verbosemod # ' in output[-1] - - def test_verbose_flag_2(self): - output = [] - class StdErr(object): - def write(self, line): - output.append(line) - - import sys, imp - old_flags = sys.flags - - class Flags(object): - verbose = 2 - def __getattr__(self, name): - return getattr(old_flags, name) - - sys.flags = Flags() - sys.stderr = StdErr() - try: - import verbose2pkg.verbosemod - finally: - imp.reload(sys) - assert any('import verbose2pkg # ' in line - for line in output[:-2]) - assert output[-2].startswith('# trying') - assert 'import verbose2pkg.verbosemod # ' in output[-1] - def test_verbose_flag_0(self): output = [] class StdErr(object): diff --git a/pypy/module/micronumpy/boxes.py b/pypy/module/micronumpy/boxes.py --- a/pypy/module/micronumpy/boxes.py +++ b/pypy/module/micronumpy/boxes.py @@ -348,8 +348,8 @@ def descr_view(self, space, w_dtype): from pypy.module.micronumpy.descriptor import W_Dtype try: - subclass = space.is_true(space.issubtype( - w_dtype, space.gettypefor(W_NDimArray))) + subclass = space.issubtype_w(w_dtype, + space.gettypefor(W_NDimArray)) except OperationError as e: if e.match(space, space.w_TypeError): subclass = False diff --git a/pypy/module/micronumpy/descriptor.py b/pypy/module/micronumpy/descriptor.py --- a/pypy/module/micronumpy/descriptor.py +++ b/pypy/module/micronumpy/descriptor.py @@ -1081,7 +1081,7 @@ if w_dtype is dtype.w_box_type: return _set_metadata_and_copy(space, w_metadata, dtype, copy) if space.isinstance_w(w_dtype, space.w_type) and \ - space.is_true(space.issubtype(w_dtype, dtype.w_box_type)): + space.issubtype_w(w_dtype, dtype.w_box_type): return _set_metadata_and_copy( space, w_metadata, W_Dtype(dtype.itemtype, w_dtype, elsize=0), copy) if space.isinstance_w(w_dtype, space.w_type): diff --git a/pypy/module/micronumpy/ndarray.py b/pypy/module/micronumpy/ndarray.py --- a/pypy/module/micronumpy/ndarray.py +++ b/pypy/module/micronumpy/ndarray.py @@ -969,8 +969,7 @@ def descr_view(self, space, w_dtype=None, w_type=None): if not w_type and w_dtype: try: - if space.is_true(space.issubtype( - w_dtype, space.gettypefor(W_NDimArray))): + if space.issubtype_w(w_dtype, space.gettypefor(W_NDimArray)): w_type = w_dtype w_dtype = None except OperationError as e: diff --git a/pypy/module/micronumpy/ufuncs.py b/pypy/module/micronumpy/ufuncs.py --- a/pypy/module/micronumpy/ufuncs.py +++ b/pypy/module/micronumpy/ufuncs.py @@ -66,10 +66,10 @@ lhs_for_subtype = w_lhs rhs_for_subtype = w_rhs #it may be something like a FlatIter, which is not an ndarray - if not space.is_true(space.issubtype(lhs_type, w_ndarray)): + if not space.issubtype_w(lhs_type, w_ndarray): lhs_type = space.type(w_lhs.base) lhs_for_subtype = w_lhs.base - if not space.is_true(space.issubtype(rhs_type, w_ndarray)): + if not space.issubtype_w(rhs_type, w_ndarray): rhs_type = space.type(w_rhs.base) rhs_for_subtype = w_rhs.base 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 @@ -166,7 +166,8 @@ def path_or_fd(allow_fd=True): return _PathOrFd if allow_fd else _JustPath -DEFAULT_DIR_FD = getattr(rposix, 'AT_FDCWD', -100) +_HAVE_AT_FDCWD = getattr(rposix, 'AT_FDCWD', None) is not None +DEFAULT_DIR_FD = rposix.AT_FDCWD if _HAVE_AT_FDCWD else -100 DIR_FD_AVAILABLE = False @specialize.arg(2) @@ -196,7 +197,7 @@ class _DirFD_Unavailable(Unwrapper): def unwrap(self, space, w_value): - dir_fd = unwrap_fd(space, w_value) + dir_fd = _unwrap_dirfd(space, w_value) if dir_fd == DEFAULT_DIR_FD: return dir_fd raise oefmt(space.w_NotImplementedError, @@ -222,11 +223,11 @@ dir_fd may not be implemented on your platform. If it is unavailable, using it will raise a NotImplementedError.""" try: - if dir_fd == DEFAULT_DIR_FD: - fd = dispatch_filename(rposix.open)(space, w_path, flags, mode) - else: + if rposix.HAVE_OPENAT and dir_fd != DEFAULT_DIR_FD: path = space.fsencode_w(w_path) fd = rposix.openat(path, flags, mode, dir_fd) + else: + fd = dispatch_filename(rposix.open)(space, w_path, flags, mode) except OSError as e: raise wrap_oserror2(space, e, w_path) return space.wrap(fd) @@ -555,7 +556,7 @@ dir_fd=DirFD(rposix.HAVE_FACCESSAT), effective_ids=kwonly(bool), follow_symlinks=kwonly(bool)) def access(space, w_path, mode, - dir_fd=DEFAULT_DIR_FD, effective_ids=True, follow_symlinks=True): + dir_fd=DEFAULT_DIR_FD, effective_ids=False, follow_symlinks=True): """\ access(path, mode, *, dir_fd=None, effective_ids=False, follow_symlinks=True) @@ -585,12 +586,14 @@ raise argument_unavailable(space, "access", "effective_ids") try: - if dir_fd == DEFAULT_DIR_FD and follow_symlinks and not effective_ids: - ok = dispatch_filename(rposix.access)(space, w_path, mode) - else: + if (rposix.HAVE_FACCESSAT and + (dir_fd != DEFAULT_DIR_FD or not follow_symlinks or + effective_ids)): path = space.fsencode_w(w_path) ok = rposix.faccessat(path, mode, dir_fd, effective_ids, follow_symlinks) + else: + ok = dispatch_filename(rposix.access)(space, w_path, mode) except OSError as e: raise wrap_oserror2(space, e, w_path) else: @@ -635,11 +638,11 @@ dir_fd may not be implemented on your platform. If it is unavailable, using it will raise a NotImplementedError.""" try: - if dir_fd == DEFAULT_DIR_FD: - dispatch_filename(rposix.unlink)(space, w_path) - else: + if rposix.HAVE_UNLINKAT and dir_fd != DEFAULT_DIR_FD: path = space.fsencode_w(w_path) rposix.unlinkat(path, dir_fd, removedir=False) + else: + dispatch_filename(rposix.unlink)(space, w_path) except OSError as e: raise wrap_oserror2(space, e, w_path) @@ -654,11 +657,11 @@ dir_fd may not be implemented on your platform. If it is unavailable, using it will raise a NotImplementedError.""" try: - if dir_fd == DEFAULT_DIR_FD: - dispatch_filename(rposix.unlink)(space, w_path) - else: + if rposix.HAVE_UNLINKAT and dir_fd != DEFAULT_DIR_FD: path = space.fsencode_w(w_path) rposix.unlinkat(path, dir_fd, removedir=False) + else: + dispatch_filename(rposix.unlink)(space, w_path) except OSError as e: raise wrap_oserror2(space, e, w_path) @@ -721,11 +724,11 @@ The mode argument is ignored on Windows.""" try: - if dir_fd == DEFAULT_DIR_FD: - dispatch_filename(rposix.mkdir)(space, w_path, mode) - else: + if rposix.HAVE_MKDIRAT and dir_fd != DEFAULT_DIR_FD: path = space.fsencode_w(w_path) rposix.mkdirat(path, mode, dir_fd) + else: + dispatch_filename(rposix.mkdir)(space, w_path, mode) except OSError as e: raise wrap_oserror2(space, e, w_path) @@ -740,11 +743,11 @@ dir_fd may not be implemented on your platform. If it is unavailable, using it will raise a NotImplementedError.""" try: - if dir_fd == DEFAULT_DIR_FD: - dispatch_filename(rposix.rmdir)(space, w_path) - else: + if rposix.HAVE_UNLINKAT and dir_fd != DEFAULT_DIR_FD: path = space.fsencode_w(w_path) rposix.unlinkat(path, dir_fd, removedir=True) + else: + dispatch_filename(rposix.rmdir)(space, w_path) except OSError as e: raise wrap_oserror2(space, e, w_path) @@ -976,7 +979,8 @@ src_dir_fd and dst_dir_fd, may not be implemented on your platform. If they are unavailable, using them will raise a NotImplementedError.""" try: - if (src_dir_fd != DEFAULT_DIR_FD or dst_dir_fd != DEFAULT_DIR_FD): + if (rposix.HAVE_RENAMEAT and + (src_dir_fd != DEFAULT_DIR_FD or dst_dir_fd != DEFAULT_DIR_FD)): src = space.fsencode_w(w_src) dst = space.fsencode_w(w_dst) rposix.renameat(src, dst, src_dir_fd, dst_dir_fd) @@ -999,7 +1003,8 @@ src_dir_fd and dst_dir_fd, may not be implemented on your platform. If they are unavailable, using them will raise a NotImplementedError.""" try: - if (src_dir_fd != DEFAULT_DIR_FD or dst_dir_fd != DEFAULT_DIR_FD): + if (rposix.HAVE_RENAMEAT and + (src_dir_fd != DEFAULT_DIR_FD or dst_dir_fd != DEFAULT_DIR_FD)): src = space.fsencode_w(w_src) dst = space.fsencode_w(w_dst) rposix.renameat(src, dst, src_dir_fd, dst_dir_fd) @@ -1110,8 +1115,9 @@ platform. If they are unavailable, using them will raise a NotImplementedError.""" try: - if (src_dir_fd != DEFAULT_DIR_FD or dst_dir_fd != DEFAULT_DIR_FD - or not follow_symlinks): + if (rposix.HAVE_LINKAT and + (src_dir_fd != DEFAULT_DIR_FD or dst_dir_fd != DEFAULT_DIR_FD + or not follow_symlinks)): rposix.linkat(src, dst, src_dir_fd, dst_dir_fd, follow_symlinks) else: rposix.link(src, dst) @@ -1136,12 +1142,12 @@ dir_fd may not be implemented on your platform. If it is unavailable, using it will raise a NotImplementedError.""" try: - if dir_fd == DEFAULT_DIR_FD: - dispatch_filename_2(rposix.symlink)(space, w_src, w_dst) - else: + if rposix.HAVE_SYMLINKAT and dir_fd != DEFAULT_DIR_FD: src = space.fsencode_w(w_src) dst = space.fsencode_w(w_dst) rposix.symlinkat(src, dst, dir_fd) + else: + dispatch_filename_2(rposix.symlink)(space, w_src, w_dst) except OSError as e: raise wrap_oserror(space, e) @@ -1159,10 +1165,10 @@ dir_fd may not be implemented on your platform. If it is unavailable, using it will raise a NotImplementedError.""" try: - if dir_fd == DEFAULT_DIR_FD: + if rposix.HAVE_READLINKAT and dir_fd != DEFAULT_DIR_FD: + result = call_rposix(rposix.readlinkat, path, dir_fd) + else: result = call_rposix(rposix.readlink, path) - else: - result = call_rposix(rposix.readlinkat, path, dir_fd) except OSError as e: raise wrap_oserror2(space, e, path.w_path) w_result = space.wrapbytes(result) @@ -1442,31 +1448,32 @@ # see comment above raise wrap_oserror(space, e) + if (rposix.HAVE_LUTIMES and + (dir_fd == DEFAULT_DIR_FD and not follow_symlinks)): + path_b = path.as_bytes + if path_b is None: + raise oefmt(space.w_NotImplementedError, + "utime: unsupported value for 'path'") + try: + if now: + rposix.lutimes(path_b, None) + else: + rposix.lutimes(path_b, (atime_s, atime_ns)) + return + except OSError as e: + # see comment above + raise wrap_oserror(space, e) + + # XXX: missing utime_dir_fd support + if not follow_symlinks: raise argument_unavailable(space, "utime", "follow_symlinks") - if not space.is_w(w_ns, space.w_None): - raise oefmt(space.w_NotImplementedError, - "utime: 'ns' unsupported on this platform on PyPy") - if now: - try: + try: + if now: call_rposix(utime_now, path, None) - except OSError as e: - # see comment above - raise wrap_oserror(space, e) - try: - msg = "utime() arg 2 must be a tuple (atime, mtime) or None" - args_w = space.fixedview(w_times) - if len(args_w) != 2: - raise oefmt(space.w_TypeError, msg) - actime = space.float_w(args_w[0], allow_conversion=False) - modtime = space.float_w(args_w[1], allow_conversion=False) - except OperationError as e: - if not e.match(space, space.w_TypeError): - raise - raise oefmt(space.w_TypeError, msg) - try: - call_rposix(rposix.utime, path, (actime, modtime)) + else: + call_rposix(rposix.utime, path, (atime_s, mtime_s)) except OSError as e: # see comment above raise wrap_oserror(space, e) diff --git a/pypy/module/posix/test/test_interp_posix.py b/pypy/module/posix/test/test_interp_posix.py --- a/pypy/module/posix/test/test_interp_posix.py +++ b/pypy/module/posix/test/test_interp_posix.py @@ -1,8 +1,6 @@ import sys import py -from hypothesis import given -from hypothesis.strategies import integers from rpython.tool.udir import udir from pypy.conftest import pypydir @@ -44,12 +42,20 @@ w_time = space.wrap(123.456) assert convert_seconds(space, w_time) == (123, 456000000) -@given(s=integers(min_value=-2**30, max_value=2**30), - ns=integers(min_value=0, max_value=10**9)) -def test_convert_seconds_full(space, s, ns): - w_time = space.wrap(s + ns * 1e-9) - sec, nsec = convert_seconds(space, w_time) - assert 0 <= nsec < 1e9 - MAX_ERR = 1e9 / 2**23 + 1 # nsec has 53 - 30 = 23 bits of precisin - err = (sec * 10**9 + nsec) - (s * 10**9 + ns) - assert -MAX_ERR < err < MAX_ERR +def test_convert_seconds_full(space): + try: + from hypothesis import given + from hypothesis.strategies import integers + except ImportError: + py.test.skip("hypothesis not found") + + @given(s=integers(min_value=-2**30, max_value=2**30), + ns=integers(min_value=0, max_value=10**9)) + def _test_convert_seconds_full(space, s, ns): + w_time = space.wrap(s + ns * 1e-9) + sec, nsec = convert_seconds(space, w_time) + assert 0 <= nsec < 1e9 + MAX_ERR = 1e9 / 2**23 + 1 # nsec has 53 - 30 = 23 bits of precisin + err = (sec * 10**9 + nsec) - (s * 10**9 + ns) + assert -MAX_ERR < err < MAX_ERR + _test_convert_seconds_full(space) diff --git a/pypy/module/time/interp_time.py b/pypy/module/time/interp_time.py --- a/pypy/module/time/interp_time.py +++ b/pypy/module/time/interp_time.py @@ -738,14 +738,16 @@ LPDWORD = rwin32.LPDWORD _GetSystemTimeAdjustment = rwin32.winexternal( 'GetSystemTimeAdjustment', - [LPDWORD, LPDWORD, rffi.LPBOOL], + [LPDWORD, LPDWORD, rwin32.LPBOOL], rffi.INT) def monotonic(space, w_info=None): result = 0 if HAS_GETTICKCOUNT64: + print('has count64'.encode('ascii')) result = _GetTickCount64() * 1e-3 else: + print("nocount64") ticks = _GetTickCount() if ticks < time_state.last_ticks: time_state.n_overflow += 1 @@ -762,9 +764,11 @@ space.setattr(w_info, space.wrap("implementation"), space.wrap("GetTickCount()")) resolution = 1e-7 - with lltype.scoped_alloc(rwin32.LPDWORD) as time_adjustment, \ - lltype.scoped_alloc(rwin32.LPDWORD) as time_increment, \ - lltype.scoped_alloc(rwin32.LPBOOL) as is_time_adjustment_disabled: + print("creating a thing".encode("ascii")) + with lltype.scoped_alloc(rwin32.LPDWORD.TO, 1) as time_adjustment, \ + lltype.scoped_alloc(rwin32.LPDWORD.TO, 1) as time_increment, \ + lltype.scoped_alloc(rwin32.LPBOOL.TO, 1) as is_time_adjustment_disabled: + print("CREATED".encode("ascii")) ok = _GetSystemTimeAdjustment(time_adjustment, time_increment, is_time_adjustment_disabled) @@ -772,8 +776,8 @@ # Is this right? Cargo culting... raise wrap_windowserror(space, rwin32.lastSavedWindowsError("GetSystemTimeAdjustment")) - resolution = resolution * time_increment - + resolution = resolution * time_increment[0] + print("out of with".encode("ascii")) space.setattr(w_info, space.wrap("monotonic"), space.w_True) space.setattr(w_info, space.wrap("adjustable"), space.w_False) space.setattr(w_info, space.wrap("resolution"), diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py --- a/pypy/objspace/descroperation.py +++ b/pypy/objspace/descroperation.py @@ -347,7 +347,7 @@ w_right_src, w_right_impl = space.lookup_in_type_where(w_typ2, '__rpow__') # sse binop_impl if (w_left_src is not w_right_src - and space.is_true(space.issubtype(w_typ2, w_typ1))): + and space.issubtype_w(w_typ2, w_typ1)): if (w_left_src and w_right_src and not space.abstract_issubclass_w(w_left_src, w_right_src) and not space.abstract_issubclass_w(w_typ1, w_right_src)): @@ -454,8 +454,11 @@ assert isinstance(w_result, W_AbstractIntObject) return w_result.descr_hash(space) + def issubtype_w(space, w_sub, w_type): + return space._type_issubtype(w_sub, w_type) + def issubtype(space, w_sub, w_type): - return space._type_issubtype(w_sub, w_type) + return space.wrap(space._type_issubtype(w_sub, w_type)) @specialize.arg_or_var(2) def isinstance_w(space, w_inst, w_type): @@ -524,7 +527,7 @@ if ((seq_bug_compat and w_typ1.flag_sequence_bug_compat and not w_typ2.flag_sequence_bug_compat) # the non-bug-compat part is the following check: - or space.is_true(space.issubtype(w_typ2, w_typ1))): + or space.issubtype_w(w_typ2, w_typ1)): if (not space.abstract_issubclass_w(w_left_src, w_right_src) and not space.abstract_issubclass_w(w_typ1, w_right_src)): w_obj1, w_obj2 = w_obj2, w_obj1 @@ -579,7 +582,7 @@ # if the type is the same, then don't reverse: try # left first, right next. pass - elif space.is_true(space.issubtype(w_typ2, w_typ1)): + elif space.issubtype_w(w_typ2, w_typ1): # if typ2 is a subclass of typ1. w_obj1, w_obj2 = w_obj2, w_obj1 w_left_impl, w_right_impl = w_right_impl, w_left_impl 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 @@ -291,6 +291,11 @@ def type(self, w_obj): return w_some_type() + def issubtype_w(self, w_sub, w_type): + is_root(w_sub) + is_root(w_type) + return NonConstant(True) + def isinstance_w(self, w_inst, w_type): is_root(w_inst) is_root(w_type) diff --git a/pypy/objspace/std/complexobject.py b/pypy/objspace/std/complexobject.py --- a/pypy/objspace/std/complexobject.py +++ b/pypy/objspace/std/complexobject.py @@ -509,7 +509,7 @@ if not isinstance(w_obj, W_ComplexObject): raise oefmt(space.w_TypeError, "descriptor is for 'complex'") return space.newfloat(getattr(w_obj, name)) - return GetSetProperty(fget, doc=doc) + return GetSetProperty(fget, doc=doc, cls=W_ComplexObject) W_ComplexObject.typedef = TypeDef("complex", __doc__ = """complex(real[, imag]) -> complex number diff --git a/pypy/objspace/std/dictproxyobject.py b/pypy/objspace/std/dictproxyobject.py --- a/pypy/objspace/std/dictproxyobject.py +++ b/pypy/objspace/std/dictproxyobject.py @@ -50,7 +50,7 @@ def getitem(self, w_dict, w_key): space = self.space w_lookup_type = space.type(w_key) - if space.is_true(space.issubtype(w_lookup_type, space.w_unicode)): + if space.issubtype_w(w_lookup_type, space.w_unicode): return self.getitem_str(w_dict, space.str_w(w_key)) else: return None 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 @@ -650,7 +650,7 @@ def _type_issubtype(self, w_sub, w_type): if isinstance(w_sub, W_TypeObject) and isinstance(w_type, W_TypeObject): - return self.wrap(w_sub.issubtype(w_type)) + return w_sub.issubtype(w_type) raise oefmt(self.w_TypeError, "need type objects") @specialize.arg_or_var(2) diff --git a/pypy/objspace/std/transparent.py b/pypy/objspace/std/transparent.py --- a/pypy/objspace/std/transparent.py +++ b/pypy/objspace/std/transparent.py @@ -52,15 +52,15 @@ raise oefmt(space.w_TypeError, "controller should be function") if isinstance(w_type, W_TypeObject): - if space.is_true(space.issubtype(w_type, space.gettypeobject(Function.typedef))): + if space.issubtype_w(w_type, space.gettypeobject(Function.typedef)): return W_TransparentFunction(space, w_type, w_controller) - if space.is_true(space.issubtype(w_type, space.gettypeobject(PyTraceback.typedef))): + if space.issubtype_w(w_type, space.gettypeobject(PyTraceback.typedef)): return W_TransparentTraceback(space, w_type, w_controller) - if space.is_true(space.issubtype(w_type, space.gettypeobject(PyFrame.typedef))): + if space.issubtype_w(w_type, space.gettypeobject(PyFrame.typedef)): return W_TransparentFrame(space, w_type, w_controller) - if space.is_true(space.issubtype(w_type, space.gettypeobject(GeneratorIterator.typedef))): + if space.issubtype_w(w_type, space.gettypeobject(GeneratorIterator.typedef)): return W_TransparentGenerator(space, w_type, w_controller) - if space.is_true(space.issubtype(w_type, space.gettypeobject(PyCode.typedef))): + if space.issubtype_w(w_type, space.gettypeobject(PyCode.typedef)): return W_TransparentCode(space, w_type, w_controller) if w_type.layout.typedef is space.w_object.layout.typedef: return W_Transparent(space, w_type, w_controller) diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py --- a/pypy/objspace/std/typeobject.py +++ b/pypy/objspace/std/typeobject.py @@ -445,7 +445,7 @@ cached_version_tag = cache.versions[method_hash] if cached_version_tag is version_tag: cached_name = cache.names[method_hash] - if cached_name is name: + if cached_name == name: tup = cache.lookup_where[method_hash] if space.config.objspace.std.withmethodcachecounter: cache.hits[name] = cache.hits.get(name, 0) + 1 @@ -710,9 +710,9 @@ w_winner = w_metaclass for base in bases_w: w_typ = space.type(base) - if space.is_true(space.issubtype(w_winner, w_typ)): + if space.issubtype_w(w_winner, w_typ): continue - if space.is_true(space.issubtype(w_typ, w_winner)): + if space.issubtype_w(w_typ, w_winner): w_winner = w_typ continue msg = ("metaclass conflict: the metaclass of a derived class must be " diff --git a/pypy/objspace/test/test_descroperation.py b/pypy/objspace/test/test_descroperation.py --- a/pypy/objspace/test/test_descroperation.py +++ b/pypy/objspace/test/test_descroperation.py @@ -25,7 +25,7 @@ pass return Base, Sub""") w_base, w_sub = space.unpackiterable(w_tup) - assert space.is_true(space.issubtype(w_sub, w_base)) + assert space.issubtype_w(w_sub, w_base) w_inst = space.call_function(w_sub) assert space.isinstance_w(w_inst, w_base) diff --git a/rpython/jit/backend/x86/test/test_rx86_32_auto_encoding.py b/rpython/jit/backend/x86/test/test_rx86_32_auto_encoding.py --- a/rpython/jit/backend/x86/test/test_rx86_32_auto_encoding.py +++ b/rpython/jit/backend/x86/test/test_rx86_32_auto_encoding.py @@ -1,4 +1,4 @@ -import os, random, struct +import sys, os, random, struct import py from rpython.jit.backend.x86 import rx86 from rpython.rlib.rarithmetic import intmask @@ -257,6 +257,9 @@ g.close() error = [line for line in got.splitlines() if 'error' in line.lower()] if error: + if (sys.maxint <= 2**32 and + 'no compiled in support for x86_64' in error[0]): + py.test.skip(error) raise Exception("Assembler got an error: %r" % error[0]) error = [line for line in got.splitlines() if 'warning' in line.lower()] diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py --- a/rpython/rlib/rposix.py +++ b/rpython/rlib/rposix.py @@ -1219,21 +1219,14 @@ if times is None: error = c_utime(path, lltype.nullptr(UTIMBUFP.TO)) else: - actime, modtime = times if HAVE_UTIMES: - import math - l_times = lltype.malloc(TIMEVAL2P.TO, 2, flavor='raw') - fracpart, intpart = math.modf(actime) - rffi.setintfield(l_times[0], 'c_tv_sec', int(intpart)) - rffi.setintfield(l_times[0], 'c_tv_usec', int(fracpart * 1e6)) - fracpart, intpart = math.modf(modtime) - rffi.setintfield(l_times[1], 'c_tv_sec', int(intpart)) - rffi.setintfield(l_times[1], 'c_tv_usec', int(fracpart * 1e6)) - error = c_utimes(path, l_times) - lltype.free(l_times, flavor='raw') + with lltype.scoped_alloc(TIMEVAL2P.TO, 2) as l_timeval2p: + times_to_timeval2p(times, l_timeval2p) + error = c_utimes(path, l_timeval2p) else: # we only have utime(), which does not allow # sub-second resolution + actime, modtime = times l_utimbuf = lltype.malloc(UTIMBUFP.TO, flavor='raw') l_utimbuf.c_actime = rffi.r_time_t(actime) l_utimbuf.c_modtime = rffi.r_time_t(modtime) @@ -1276,6 +1269,17 @@ lltype.free(atime, flavor='raw') lltype.free(mtime, flavor='raw') +def times_to_timeval2p(times, l_timeval2p): + actime, modtime = times + _time_to_timeval(actime, l_timeval2p[0]) + _time_to_timeval(modtime, l_timeval2p[1]) + +def _time_to_timeval(t, l_timeval): + import math + fracpart, intpart = math.modf(t) + rffi.setintfield(l_timeval, 'c_tv_sec', int(intpart)) + rffi.setintfield(l_timeval, 'c_tv_usec', int(fracpart * 1e6)) + if not _WIN32: TMSP = lltype.Ptr(TMS) c_times = external('times', [TMSP], CLOCK_T, @@ -1763,6 +1767,7 @@ class CConfig: _compilation_info_ = ExternalCompilationInfo( includes=['sys/stat.h', + 'sys/time.h', 'unistd.h', 'fcntl.h'], ) @@ -1918,6 +1923,21 @@ lltype.free(l_times, flavor='raw') handle_posix_error('utimensat', error) +if HAVE_LUTIMES: + c_lutimes = external('lutimes', + [rffi.CCHARP, TIMEVAL2P], rffi.INT, + save_err=rffi.RFFI_SAVE_ERRNO) + + @specialize.argtype(1) + def lutimes(pathname, times): + if times is None: + error = c_lutimes(pathname, lltype.nullptr(TIMEVAL2P.TO)) + else: + with lltype.scoped_alloc(TIMEVAL2P.TO, 2) as l_timeval2p: + times_to_timeval2p(times, l_timeval2p) + error = c_lutimes(pathname, l_timeval2p) + handle_posix_error('lutimes', error) + if HAVE_MKDIRAT: c_mkdirat = external('mkdirat', [rffi.INT, rffi.CCHARP, rffi.INT], rffi.INT, _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit