[pypy-commit] pypy py3.6: hg merge py3.5
Author: Ronan Lamy Branch: py3.6 Changeset: r94922:326720df4fbe Date: 2018-07-29 02:06 +0100 http://bitbucket.org/pypy/pypy/changeset/326720df4fbe/ Log:hg merge py3.5 diff --git a/pypy/interpreter/astcompiler/codegen.py b/pypy/interpreter/astcompiler/codegen.py --- a/pypy/interpreter/astcompiler/codegen.py +++ b/pypy/interpreter/astcompiler/codegen.py @@ -379,8 +379,8 @@ names) self._visit_arg_annotations(args.kwonlyargs, names) kwarg = args.kwarg -if args.kwarg: -self._visit_arg_annotation(args.kwarg.arg, args.kwarg.annotation, +if kwarg: +self._visit_arg_annotation(kwarg.arg, kwarg.annotation, names) self._visit_arg_annotation("return", returns, names) l = len(names) diff --git a/pypy/interpreter/astcompiler/symtable.py b/pypy/interpreter/astcompiler/symtable.py --- a/pypy/interpreter/astcompiler/symtable.py +++ b/pypy/interpreter/astcompiler/symtable.py @@ -640,6 +640,10 @@ assert isinstance(args, ast.arguments) if args.args: self._visit_arg_annotations(args.args) +if args.vararg: +self._visit_arg_annotation(args.vararg) +if args.kwarg: +self._visit_arg_annotation(args.kwarg) if args.kwonlyargs: self._visit_arg_annotations(args.kwonlyargs) if func.returns: @@ -648,8 +652,11 @@ def _visit_arg_annotations(self, args): for arg in args: assert isinstance(arg, ast.arg) -if arg.annotation: -arg.annotation.walkabout(self) +self._visit_arg_annotation(arg) + +def _visit_arg_annotation(self, arg): +if arg.annotation: +arg.annotation.walkabout(self) def visit_Name(self, name): if name.ctx == ast.Load: 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 @@ -470,7 +470,7 @@ def test_cmd_co_name(self): child = self.spawn(['-c', -'import sys; print sys._getframe(0).f_code.co_name']) +'import sys; print(sys._getframe(0).f_code.co_name)']) child.expect('') def test_ignore_python_inspect(self): diff --git a/pypy/interpreter/test/test_executioncontext.py b/pypy/interpreter/test/test_executioncontext.py --- a/pypy/interpreter/test/test_executioncontext.py +++ b/pypy/interpreter/test/test_executioncontext.py @@ -149,7 +149,7 @@ pass """) space.getexecutioncontext().setllprofile(None, None) -assert l == ['call', 'return', 'call', 'return'] +assert l[-4:] == ['call', 'return', 'call', 'return'] def test_llprofile_c_call(self): from pypy.interpreter.function import Function, Method @@ -173,15 +173,15 @@ return """ % snippet) space.getexecutioncontext().setllprofile(None, None) -assert l == ['call', 'return', 'call', 'c_call', 'c_return', 'return'] -if isinstance(seen[0], Method): -w_class = space.type(seen[0].w_instance) +assert l[-6:] == ['call', 'return', 'call', 'c_call', 'c_return', 'return'] +if isinstance(seen[-1], Method): +w_class = space.type(seen[-1].w_instance) found = 'method %s of %s' % ( -seen[0].w_function.name, +seen[-1].w_function.name, w_class.getname(space).encode('utf-8')) else: -assert isinstance(seen[0], Function) -found = 'builtin %s' % seen[0].name +assert isinstance(seen[-1], Function) +found = 'builtin %s' % seen[-1].name assert found == expected_c_call check_snippet('l = []; l.append(42)', 'method append of list') @@ -210,7 +210,7 @@ return """ % snippet) space.getexecutioncontext().setllprofile(None, None) -assert l == ['call', 'return', 'call', 'c_call', 'c_exception', 'return'] +assert l[-6:] == ['call', 'return', 'call', 'c_call', 'c_exception', 'return'] check_snippet('d = {}; d.__getitem__(42)') diff --git a/pypy/interpreter/test/test_pyframe.py b/pypy/interpreter/test/test_pyframe.py --- a/pypy/interpreter/test/test_pyframe.py +++ b/pypy/interpreter/test/test_pyframe.py @@ -153,6 +153,8 @@ r""" seen = [] def tracer(f, event, *args): +if f.f_code.co_name == "decode": +return tracer seen.append((event, f.f_lineno)) if len(seen) == 5: f.f_lineno = 1 # bug shown only when setting lineno to 1 @@ -297,7 +299,8 @@ l = [] def trace(a,b,c): -l.append((a,b,c)) +
[pypy-commit] pypy py3.5: fix the tests in test_pyframe that fail in combination with other files
Author: Carl Friedrich Bolz-Tereick Branch: py3.5 Changeset: r94921:dfda715a5495 Date: 2018-07-28 21:31 +0200 http://bitbucket.org/pypy/pypy/changeset/dfda715a5495/ Log:fix the tests in test_pyframe that fail in combination with other files diff --git a/pypy/interpreter/test/test_pyframe.py b/pypy/interpreter/test/test_pyframe.py --- a/pypy/interpreter/test/test_pyframe.py +++ b/pypy/interpreter/test/test_pyframe.py @@ -153,6 +153,8 @@ r""" seen = [] def tracer(f, event, *args): +if f.f_code.co_name == "decode": +return tracer seen.append((event, f.f_lineno)) if len(seen) == 5: f.f_lineno = 1 # bug shown only when setting lineno to 1 @@ -297,7 +299,8 @@ l = [] def trace(a,b,c): -l.append((a,b,c)) +if a.f_code.co_name != "decode": +l.append((a,b,c)) def f(): h = _testing.Hidden() ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: fix test_executioncontext flakiness
Author: Carl Friedrich Bolz-Tereick Branch: py3.5 Changeset: r94920:0370bd9179ff Date: 2018-07-28 16:03 +0200 http://bitbucket.org/pypy/pypy/changeset/0370bd9179ff/ Log:fix test_executioncontext flakiness when run in some combinations with other test files that set the file system encoding, space.appexec causes a call to "encode" internally, which produces extra C call events. Just ignore those. diff --git a/pypy/interpreter/test/test_executioncontext.py b/pypy/interpreter/test/test_executioncontext.py --- a/pypy/interpreter/test/test_executioncontext.py +++ b/pypy/interpreter/test/test_executioncontext.py @@ -149,7 +149,7 @@ pass """) space.getexecutioncontext().setllprofile(None, None) -assert l == ['call', 'return', 'call', 'return'] +assert l[-4:] == ['call', 'return', 'call', 'return'] def test_llprofile_c_call(self): from pypy.interpreter.function import Function, Method @@ -173,15 +173,15 @@ return """ % snippet) space.getexecutioncontext().setllprofile(None, None) -assert l == ['call', 'return', 'call', 'c_call', 'c_return', 'return'] -if isinstance(seen[0], Method): -w_class = space.type(seen[0].w_instance) +assert l[-6:] == ['call', 'return', 'call', 'c_call', 'c_return', 'return'] +if isinstance(seen[-1], Method): +w_class = space.type(seen[-1].w_instance) found = 'method %s of %s' % ( -seen[0].w_function.name, +seen[-1].w_function.name, w_class.getname(space).encode('utf-8')) else: -assert isinstance(seen[0], Function) -found = 'builtin %s' % seen[0].name +assert isinstance(seen[-1], Function) +found = 'builtin %s' % seen[-1].name assert found == expected_c_call check_snippet('l = []; l.append(42)', 'method append of list') @@ -210,7 +210,7 @@ return """ % snippet) space.getexecutioncontext().setllprofile(None, None) -assert l == ['call', 'return', 'call', 'c_call', 'c_exception', 'return'] +assert l[-6:] == ['call', 'return', 'call', 'c_call', 'c_exception', 'return'] check_snippet('d = {}; d.__getitem__(42)') ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: fix a test that
Author: Carl Friedrich Bolz-Tereick Branch: py3.5 Changeset: r94919:09d5a78a60b4 Date: 2018-07-28 15:28 +0200 http://bitbucket.org/pypy/pypy/changeset/09d5a78a60b4/ Log:fix a test that 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 @@ -470,7 +470,7 @@ def test_cmd_co_name(self): child = self.spawn(['-c', -'import sys; print sys._getframe(0).f_code.co_name']) +'import sys; print(sys._getframe(0).f_code.co_name)']) child.expect('') def test_ignore_python_inspect(self): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.6: merge heads again
Author: Antoine Dupre Branch: py3.6 Changeset: r94918:5b1df32fb6f6 Date: 2018-07-28 15:25 +0200 http://bitbucket.org/pypy/pypy/changeset/5b1df32fb6f6/ Log:merge heads again diff too long, truncating to 2000 out of 2020 lines diff --git a/lib-python/3/opcode.py b/lib-python/3/opcode.py --- a/lib-python/3/opcode.py +++ b/lib-python/3/opcode.py @@ -216,6 +216,7 @@ def_op('BUILD_SET_UNPACK', 153) def_op('FORMAT_VALUE', 155) # in CPython 3.6, but available in PyPy from 3.5 +def_op('BUILD_CONST_KEY_MAP', 156) def_op('BUILD_STRING', 157) # in CPython 3.6, but available in PyPy from 3.5 # pypy modification, experimental bytecode diff --git a/lib-python/3/test/test_opcodes.py b/lib-python/3/test/test_opcodes.py --- a/lib-python/3/test/test_opcodes.py +++ b/lib-python/3/test/test_opcodes.py @@ -27,7 +27,9 @@ with open(ann_module.__file__) as f: txt = f.read() co = compile(txt, ann_module.__file__, 'exec') -self.assertEqual(co.co_firstlineno, 6) +# On PyPy, the lineno of multiline tokens is the *first* line, on +# CPython the last (CPython expects 6 here) +self.assertEqual(co.co_firstlineno, 3) except OSError: pass diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst --- a/pypy/doc/whatsnew-head.rst +++ b/pypy/doc/whatsnew-head.rst @@ -35,3 +35,7 @@ .. branch: pyparser-improvements-3 Small refactorings in the Python parser. + +.. branch: py3.6-wordcode + +implement new wordcode instruction encoding on the 3.6 branch diff --git a/pypy/interpreter/astcompiler/assemble.py b/pypy/interpreter/astcompiler/assemble.py --- a/pypy/interpreter/astcompiler/assemble.py +++ b/pypy/interpreter/astcompiler/assemble.py @@ -21,6 +21,8 @@ def __init__(self, opcode, arg=0): self.opcode = opcode self.arg = arg +if opcode < ops.HAVE_ARGUMENT: +assert arg == 0 self.lineno = 0 self.has_jump = False @@ -28,9 +30,33 @@ """Return the size of bytes of this instruction when it is encoded. """ -if self.opcode >= ops.HAVE_ARGUMENT: -return (6 if self.arg > 0x else 3) -return 1 +if self.arg <= 0xff: +return 2 +if self.arg <= 0x: +return 4 +if self.arg <= 0xff: +return 6 +return 8 + +def encode(self, code): +opcode = self.opcode + +arg = self.arg +size = self.size() +if size == 8: +code.append(chr(ops.EXTENDED_ARG)) +code.append(chr((arg >> 24) & 0xff)) +assert ((arg >> 24) & 0xff) == (arg >> 24) +if size >= 6: +code.append(chr(ops.EXTENDED_ARG)) +code.append(chr((arg >> 16) & 0xff)) +if size >= 4: +code.append(chr(ops.EXTENDED_ARG)) +code.append(chr((arg >> 8) & 0xff)) +if size >= 2: +code.append(chr(opcode)) +code.append(chr(arg & 0xff)) + def jump_to(self, target, absolute=False): """Indicate the target this jump instruction. @@ -121,20 +147,9 @@ """Encode the instructions in this block into bytecode.""" code = [] for instr in self.instructions: -opcode = instr.opcode -if opcode >= ops.HAVE_ARGUMENT: -arg = instr.arg -if instr.arg > 0x: -ext = arg >> 16 -code.append(chr(ops.EXTENDED_ARG)) -code.append(chr(ext & 0xFF)) -code.append(chr(ext >> 8)) -arg &= 0x -code.append(chr(opcode)) -code.append(chr(arg & 0xFF)) -code.append(chr(arg >> 8)) -else: -code.append(chr(opcode)) +instr.encode(code) +assert len(code) == self.code_size() +assert len(code) & 1 == 0 return ''.join(code) @@ -185,6 +200,13 @@ self.lineno = 0 self.add_none_to_final_return = True +def _check_consistency(self, blocks): +current_off = 0 +for block in blocks: +assert block.offset == current_off +for instr in block.instructions: +current_off += instr.size() + def new_block(self): return Block() @@ -315,14 +337,12 @@ def _resolve_block_targets(self, blocks): """Compute the arguments of jump instructions.""" -last_extended_arg_count = 0 # The reason for this loop is extended jumps. EXTENDED_ARG -# extends the bytecode size, so it might invalidate the offsets -# we've already given. Thus we have to loop until the number of -# extended args is stable. Any extended jump at all is -# extremely rare, so performance is not too concerning. +# extends the bytecode size, so it might
[pypy-commit] pypy py3.6: merge head
Author: Antoine Dupre Branch: py3.6 Changeset: r94917:4a8044e8da87 Date: 2018-07-28 15:23 +0200 http://bitbucket.org/pypy/pypy/changeset/4a8044e8da87/ Log:merge head diff --git a/pypy/module/posix/test/test_scandir.py b/pypy/module/posix/test/test_scandir.py --- a/pypy/module/posix/test/test_scandir.py +++ b/pypy/module/posix/test/test_scandir.py @@ -224,7 +224,7 @@ def test_lstat(self): posix = self.posix -d = next(posix.scandir()) +d = next(posix.scandir(self.dir1)) with open(d) as fp: length = len(fp.read()) assert posix.lstat(d).st_size == length ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.6: (duprean, antocuni) Test and fix for fstring exception message to mimic Cpython
Author: Antoine Dupre Branch: py3.6 Changeset: r94916:56432e26b463 Date: 2018-07-28 15:22 +0200 http://bitbucket.org/pypy/pypy/changeset/56432e26b463/ Log:(duprean, antocuni) Test and fix for fstring exception message to mimic Cpython diff --git a/pypy/objspace/std/newformat.py b/pypy/objspace/std/newformat.py --- a/pypy/objspace/std/newformat.py +++ b/pypy/objspace/std/newformat.py @@ -583,7 +583,7 @@ def _unknown_presentation(self, w_val): raise oefmt(self.space.w_ValueError, -"unknown format code %s for object of type '%T'", self._type, w_val) +"Unknown format code %s for object of type '%T'", self._type, w_val) def format_string(self, w_string): space = self.space diff --git a/pypy/objspace/std/test/test_fsting.py b/pypy/objspace/std/test/test_fsting.py new file mode 100644 --- /dev/null +++ b/pypy/objspace/std/test/test_fsting.py @@ -0,0 +1,8 @@ +class AppTestFstring: +def test_error_unknown_code(self): +""" +def fn(): +f'{1000:j}' +exc_info = raises(ValueError, fn) +assert str(exc_info.value).startswith("Unknown format code") +""" ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.6: document merged branch
Author: Carl Friedrich Bolz-Tereick Branch: py3.6 Changeset: r94915:5e596e627b4e Date: 2018-07-28 15:23 +0200 http://bitbucket.org/pypy/pypy/changeset/5e596e627b4e/ Log:document merged branch diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst --- a/pypy/doc/whatsnew-head.rst +++ b/pypy/doc/whatsnew-head.rst @@ -35,3 +35,7 @@ .. branch: pyparser-improvements-3 Small refactorings in the Python parser. + +.. branch: py3.6-wordcode + +implement new wordcode instruction encoding on the 3.6 branch ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.6: merge py3.6-wordcode
Author: Carl Friedrich Bolz-Tereick Branch: py3.6 Changeset: r94914:2e5eb984c7fa Date: 2018-07-28 15:22 +0200 http://bitbucket.org/pypy/pypy/changeset/2e5eb984c7fa/ Log:merge py3.6-wordcode switch the py3.6 over to the new wordcode format introduced in CPython 3.6. diff too long, truncating to 2000 out of 2009 lines diff --git a/lib-python/3/opcode.py b/lib-python/3/opcode.py --- a/lib-python/3/opcode.py +++ b/lib-python/3/opcode.py @@ -216,6 +216,7 @@ def_op('BUILD_SET_UNPACK', 153) def_op('FORMAT_VALUE', 155) # in CPython 3.6, but available in PyPy from 3.5 +def_op('BUILD_CONST_KEY_MAP', 156) def_op('BUILD_STRING', 157) # in CPython 3.6, but available in PyPy from 3.5 # pypy modification, experimental bytecode diff --git a/lib-python/3/test/test_opcodes.py b/lib-python/3/test/test_opcodes.py --- a/lib-python/3/test/test_opcodes.py +++ b/lib-python/3/test/test_opcodes.py @@ -27,7 +27,9 @@ with open(ann_module.__file__) as f: txt = f.read() co = compile(txt, ann_module.__file__, 'exec') -self.assertEqual(co.co_firstlineno, 6) +# On PyPy, the lineno of multiline tokens is the *first* line, on +# CPython the last (CPython expects 6 here) +self.assertEqual(co.co_firstlineno, 3) except OSError: pass diff --git a/pypy/interpreter/astcompiler/assemble.py b/pypy/interpreter/astcompiler/assemble.py --- a/pypy/interpreter/astcompiler/assemble.py +++ b/pypy/interpreter/astcompiler/assemble.py @@ -21,6 +21,8 @@ def __init__(self, opcode, arg=0): self.opcode = opcode self.arg = arg +if opcode < ops.HAVE_ARGUMENT: +assert arg == 0 self.lineno = 0 self.has_jump = False @@ -28,9 +30,33 @@ """Return the size of bytes of this instruction when it is encoded. """ -if self.opcode >= ops.HAVE_ARGUMENT: -return (6 if self.arg > 0x else 3) -return 1 +if self.arg <= 0xff: +return 2 +if self.arg <= 0x: +return 4 +if self.arg <= 0xff: +return 6 +return 8 + +def encode(self, code): +opcode = self.opcode + +arg = self.arg +size = self.size() +if size == 8: +code.append(chr(ops.EXTENDED_ARG)) +code.append(chr((arg >> 24) & 0xff)) +assert ((arg >> 24) & 0xff) == (arg >> 24) +if size >= 6: +code.append(chr(ops.EXTENDED_ARG)) +code.append(chr((arg >> 16) & 0xff)) +if size >= 4: +code.append(chr(ops.EXTENDED_ARG)) +code.append(chr((arg >> 8) & 0xff)) +if size >= 2: +code.append(chr(opcode)) +code.append(chr(arg & 0xff)) + def jump_to(self, target, absolute=False): """Indicate the target this jump instruction. @@ -121,20 +147,9 @@ """Encode the instructions in this block into bytecode.""" code = [] for instr in self.instructions: -opcode = instr.opcode -if opcode >= ops.HAVE_ARGUMENT: -arg = instr.arg -if instr.arg > 0x: -ext = arg >> 16 -code.append(chr(ops.EXTENDED_ARG)) -code.append(chr(ext & 0xFF)) -code.append(chr(ext >> 8)) -arg &= 0x -code.append(chr(opcode)) -code.append(chr(arg & 0xFF)) -code.append(chr(arg >> 8)) -else: -code.append(chr(opcode)) +instr.encode(code) +assert len(code) == self.code_size() +assert len(code) & 1 == 0 return ''.join(code) @@ -185,6 +200,13 @@ self.lineno = 0 self.add_none_to_final_return = True +def _check_consistency(self, blocks): +current_off = 0 +for block in blocks: +assert block.offset == current_off +for instr in block.instructions: +current_off += instr.size() + def new_block(self): return Block() @@ -315,14 +337,12 @@ def _resolve_block_targets(self, blocks): """Compute the arguments of jump instructions.""" -last_extended_arg_count = 0 # The reason for this loop is extended jumps. EXTENDED_ARG -# extends the bytecode size, so it might invalidate the offsets -# we've already given. Thus we have to loop until the number of -# extended args is stable. Any extended jump at all is -# extremely rare, so performance is not too concerning. +# extends the bytecode size, so it might invalidate the offsets we've +# already given. Thus we have to loop until the size of all jump +# instructions is stable. Any extended jump at all is extremely rare, +# so performance should not be too
[pypy-commit] pypy py3.5: tweak
Author: Carl Friedrich Bolz-Tereick Branch: py3.5 Changeset: r94912:18f7d184a9f7 Date: 2018-07-28 14:02 +0200 http://bitbucket.org/pypy/pypy/changeset/18f7d184a9f7/ Log:tweak diff --git a/pypy/interpreter/astcompiler/codegen.py b/pypy/interpreter/astcompiler/codegen.py --- a/pypy/interpreter/astcompiler/codegen.py +++ b/pypy/interpreter/astcompiler/codegen.py @@ -367,8 +367,8 @@ names) self._visit_arg_annotations(args.kwonlyargs, names) kwarg = args.kwarg -if args.kwarg: -self._visit_arg_annotation(args.kwarg.arg, args.kwarg.annotation, +if kwarg: +self._visit_arg_annotation(kwarg.arg, kwarg.annotation, names) self._visit_arg_annotation("return", returns, names) l = len(names) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: fix annotation bug reported by hubo on pypy-dev
Author: Carl Friedrich Bolz-Tereick Branch: py3.5 Changeset: r94913:179c172169f1 Date: 2018-07-28 14:06 +0200 http://bitbucket.org/pypy/pypy/changeset/179c172169f1/ Log:fix annotation bug reported by hubo on pypy-dev diff --git a/pypy/interpreter/astcompiler/symtable.py b/pypy/interpreter/astcompiler/symtable.py --- a/pypy/interpreter/astcompiler/symtable.py +++ b/pypy/interpreter/astcompiler/symtable.py @@ -622,6 +622,10 @@ assert isinstance(args, ast.arguments) if args.args: self._visit_arg_annotations(args.args) +if args.vararg: +self._visit_arg_annotation(args.vararg) +if args.kwarg: +self._visit_arg_annotation(args.kwarg) if args.kwonlyargs: self._visit_arg_annotations(args.kwonlyargs) if func.returns: @@ -630,8 +634,11 @@ def _visit_arg_annotations(self, args): for arg in args: assert isinstance(arg, ast.arg) -if arg.annotation: -arg.annotation.walkabout(self) +self._visit_arg_annotation(arg) + +def _visit_arg_annotation(self, arg): +if arg.annotation: +arg.annotation.walkabout(self) def visit_Name(self, name): if name.ctx == ast.Load: diff --git a/pypy/interpreter/test/test_syntax.py b/pypy/interpreter/test/test_syntax.py --- a/pypy/interpreter/test/test_syntax.py +++ b/pypy/interpreter/test/test_syntax.py @@ -691,6 +691,16 @@ "bye" : 5, "kw" : 6, "return" : 42} """ +def test_bug_annotations_lambda(self): +""" +# those used to crash +def broken(*a: lambda x: None): +pass + +def broken(**a: lambda x: None): +pass +""" + class AppTestSyntaxError: def test_tokenizer_error_location(self): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.6: Add missing argument to scandir.
Author: Johan Forsberg Branch: py3.6 Changeset: r94911:11f17afc7367 Date: 2018-07-28 12:24 +0100 http://bitbucket.org/pypy/pypy/changeset/11f17afc7367/ Log:Add missing argument to scandir. diff --git a/pypy/module/posix/test/test_scandir.py b/pypy/module/posix/test/test_scandir.py --- a/pypy/module/posix/test/test_scandir.py +++ b/pypy/module/posix/test/test_scandir.py @@ -224,7 +224,7 @@ def test_lstat(self): posix = self.posix -d = next(posix.scandir()) +d = next(posix.scandir(self.dir1)) with open(d) as fp: length = len(fp.read()) assert posix.lstat(d).st_size == length ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy cppyy-packaging: restore std::vector speedups
Author: Wim Lavrijsen Branch: cppyy-packaging Changeset: r94910:422177baf4ea Date: 2018-07-28 01:15 -0700 http://bitbucket.org/pypy/pypy/changeset/422177baf4ea/ Log:restore std::vector speedups diff --git a/pypy/module/_cppyy/capi/loadable_capi.py b/pypy/module/_cppyy/capi/loadable_capi.py --- a/pypy/module/_cppyy/capi/loadable_capi.py +++ b/pypy/module/_cppyy/capi/loadable_capi.py @@ -1,13 +1,18 @@ import os + from rpython.rtyper.lltypesystem import rffi, lltype from rpython.rlib.rarithmetic import intmask from rpython.rlib import jit, jit_libffi, libffi, rdynload, objectmodel from rpython.rlib.rarithmetic import r_singlefloat from rpython.tool import leakfinder -from pypy.interpreter.gateway import interp2app -from pypy.interpreter.error import oefmt +from pypy.interpreter.error import OperationError, oefmt +from pypy.interpreter.argument import Arguments +from pypy.interpreter.gateway import interp2app, interpindirect2app +from pypy.interpreter.typedef import TypeDef +from pypy.objspace.std.iterobject import W_AbstractSeqIterObject +from pypy.module._rawffi.array import W_ArrayInstance from pypy.module._cffi_backend import ctypefunc, ctypeprim, cdataobj, misc from pypy.module._cffi_backend import newtype from pypy.module._cppyy import ffitypes @@ -274,8 +279,9 @@ 'stdstring2charp' : ([c_object, c_voidp], c_ccharp), 'stdstring2stdstring' : ([c_object], c_object), -'stdvector_valuetype' : ([c_ccharp], c_ccharp), -'stdvector_valuesize' : ([c_ccharp], c_size_t), +'longdouble2double': ([c_voidp], c_double), +'double2longdouble': ([c_double, c_voidp],c_void), + 'vectorbool_getitem' : ([c_object, c_int], c_int), 'vectorbool_setitem' : ([c_object, c_int, c_int], c_void), } @@ -658,13 +664,6 @@ def c_stdstring2stdstring(space, cppobject): return _cdata_to_cobject(space, call_capi(space, 'stdstring2stdstring', [_ArgH(cppobject)])) -def c_stdvector_valuetype(space, pystr): -return charp2str_free(space, call_capi(space, 'stdvector_valuetype', [_ArgS(pystr)])) - -def c_stdvector_valuetype(space, pystr): -return charp2str_free(space, call_capi(space, 'stdvector_valuetype', [_ArgS(pystr)])) -def c_stdvector_valuesize(space, pystr): -return _cdata_to_size_t(space, call_capi(space, 'stdvector_valuesize', [_ArgS(pystr)])) def c_vectorbool_getitem(space, vbool, idx): return call_capi(space, 'vectorbool_getitem', [_ArgH(vbool), _ArgL(idx)]) def c_vectorbool_setitem(space, vbool, idx, value): @@ -702,6 +701,52 @@ idx = vbool_getindex(space, w_self, w_idx) c_vectorbool_setitem(space, vbool._rawobject, idx, int(space.is_true(w_value))) +class W_STLVectorIter(W_AbstractSeqIterObject): +# w_seq and index are in base class +_immutable_fields_ = ['converter', 'data', 'len', 'stride'] + +def __init__(self, space, w_vector): +W_AbstractSeqIterObject.__init__(self, w_vector) +# TODO: this should live in rpythonize.py or something so that the +# imports can move to the top w/o getting circles +from pypy.module._cppyy import interp_cppyy +assert isinstance(w_vector, interp_cppyy.W_CPPInstance) +vector = space.interp_w(interp_cppyy.W_CPPInstance, w_vector) + +v_type = c_resolve_name(space, vector.clsdecl.name+'::value_type') +v_size = c_size_of_type(space, v_type) + +if not v_type or not v_size: +raise NotImplementedError # fallback on getitem + +from pypy.module._cppyy import converter +self.converter = converter.get_converter(space, v_type, '') + +# this 'data' is from the decl, so not the pythonized data from pythonify.py +w_arr = space.call_obj_args(vector.clsdecl.get_overload('data'), w_vector, Arguments(space, [])) +arr = space.interp_w(W_ArrayInstance, w_arr, can_be_None=True) +if not arr: +raise OperationError(space.w_StopIteration, space.w_None) + +self.data= rffi.cast(rffi.CCHARP, space.uint_w(arr.getbuffer(space))) +self.len = space.uint_w(space.call_obj_args(vector.clsdecl.get_overload('size'), w_vector, Arguments(space, []))) +self.stride = v_size + +def descr_next(self, space): +if self.w_seq is None: +raise OperationError(space.w_StopIteration, space.w_None) +if self.len <= self.index: +self.w_seq = None +raise OperationError(space.w_StopIteration, space.w_None) +offset = lltype.direct_ptradd(self.data, rffi.cast(rffi.SIZE_T, self.index*self.stride)) +w_item = self.converter.from_memory(space, space.w_None, rffi.cast(rffi.LONG, offset)) +self.index += 1 +return w_item + +def stdvector_iter(space, w_self): +return