[pypy-commit] pypy py3.5: Add @unwrap_spec, fixes a translation error too

2016-11-01 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r88008:3e5d31c2b04e
Date: 2016-11-01 08:59 +
http://bitbucket.org/pypy/pypy/changeset/3e5d31c2b04e/

Log:Add @unwrap_spec, fixes a translation error too

diff --git a/pypy/module/struct/interp_struct.py 
b/pypy/module/struct/interp_struct.py
--- a/pypy/module/struct/interp_struct.py
+++ b/pypy/module/struct/interp_struct.py
@@ -128,19 +128,6 @@
 self.index += size
 return w_res
 
-def new_unpackiter(space, w_subtype, w_struct, w_buffer):
-buf = space.buffer_w(w_buffer, space.BUF_SIMPLE)
-w_res = space.allocate_instance(W_UnpackIter, w_subtype)
-w_res.__init__(w_struct, buf)
-return w_res
-
-W_UnpackIter.typedef = TypeDef("unpack_iterator",
-__new__=interp2app(new_unpackiter),
-__iter__=interp2app(W_UnpackIter.descr_iter),
-__next__=interp2app(W_UnpackIter.descr_next),
-#__length_hint__=
-)
-
 
 class W_Struct(W_Root):
 _immutable_fields_ = ["format", "size"]
@@ -185,5 +172,19 @@
 iter_unpack=interp2app(W_Struct.descr_iter_unpack),
 )
 
+@unwrap_spec(w_struct=W_Struct)
+def new_unpackiter(space, w_subtype, w_struct, w_buffer):
+buf = space.buffer_w(w_buffer, space.BUF_SIMPLE)
+w_res = space.allocate_instance(W_UnpackIter, w_subtype)
+w_res.__init__(w_struct, buf)
+return w_res
+
+W_UnpackIter.typedef = TypeDef("unpack_iterator",
+__new__=interp2app(new_unpackiter),
+__iter__=interp2app(W_UnpackIter.descr_iter),
+__next__=interp2app(W_UnpackIter.descr_next),
+#__length_hint__=
+)
+
 def clearcache(space):
 """No-op on PyPy"""
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy missing-tp_new: Fix

2016-11-01 Thread arigo
Author: Armin Rigo 
Branch: missing-tp_new
Changeset: r88009:67074ec10639
Date: 2016-11-01 09:01 +
http://bitbucket.org/pypy/pypy/changeset/67074ec10639/

Log:Fix

diff --git a/pypy/module/cpyext/userslot.py b/pypy/module/cpyext/userslot.py
--- a/pypy/module/cpyext/userslot.py
+++ b/pypy/module/cpyext/userslot.py
@@ -30,10 +30,7 @@
 
 @cpython_api([PyTypeObjectPtr, PyObject, PyObject], PyObject, header=None)
 def slot_tp_new(space, w_type, w_args, w_kwds):
-_, w_descr = space.lookup_in_type_where(w_type, '__new__')
-if w_descr is None:
-raise oefmt(space.w_RuntimeError, "cpyext: '__new__' not found")
-# w_descr is typically a StaticMethod
+w_impl = space.getattr(w_type, space.wrap('__new__'))
 args = Arguments(space, [w_type],
  w_stararg=w_args, w_starstararg=w_kwds)
-return space.call_args(space.get(w_descr, w_type), args)
+return space.call_args(w_impl, args)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Remove copy-paste-modify code

2016-11-01 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r88010:a002427e7b9c
Date: 2016-11-01 10:16 +0100
http://bitbucket.org/pypy/pypy/changeset/a002427e7b9c/

Log:Remove copy-paste-modify code

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
@@ -370,7 +370,7 @@
 l += 1
 return l
 
-def visit_FunctionDef(self, func):
+def _visit_function(self, func, function_code_generator, extra_flag):
 self.update_position(func.lineno, True)
 # Load decorators first, but apply them after the function is created.
 self.visit_sequence(func.decorator_list)
@@ -385,39 +385,22 @@
 oparg = num_defaults
 oparg |= kw_default_count << 8
 oparg |= num_annotations << 16
-code, qualname = self.sub_scope(FunctionCodeGenerator, func.name, func,
-func.lineno)
+code, qualname = self.sub_scope(function_code_generator, func.name,
+func, func.lineno)
+code.co_flags |= extra_flag
 self._make_function(code, oparg, qualname=qualname)
 # Apply decorators.
 if func.decorator_list:
 for i in range(len(func.decorator_list)):
 self.emit_op_arg(ops.CALL_FUNCTION, 1)
 self.name_op(func.name, ast.Store)
-
+
+def visit_FunctionDef(self, func):
+self._visit_function(func, FunctionCodeGenerator, 0)
+
 def visit_AsyncFunctionDef(self, func):
-self.update_position(func.lineno, True)
-# Load decorators first, but apply them after the function is created.
-self.visit_sequence(func.decorator_list)
-args = func.args
-assert isinstance(args, ast.arguments)
-kw_default_count = 0
-if args.kwonlyargs:
-kw_default_count = self._visit_kwonlydefaults(args)
-self.visit_sequence(args.defaults)
-num_annotations = self._visit_annotations(func, args, func.returns)
-num_defaults = len(args.defaults) if args.defaults is not None else 0
-oparg = num_defaults
-oparg |= kw_default_count << 8
-oparg |= num_annotations << 16
-code, qualname = self.sub_scope(AsyncFunctionCodeGenerator, func.name, 
func,
-func.lineno)
-code.co_flags |= consts.CO_COROUTINE
-self._make_function(code, oparg, qualname=qualname)
-# Apply decorators.
-if func.decorator_list:
-for i in range(len(func.decorator_list)):
-self.emit_op_arg(ops.CALL_FUNCTION, 1)
-self.name_op(func.name, ast.Store)
+self._visit_function(func, AsyncFunctionCodeGenerator,
+ consts.CO_COROUTINE)
 
 def visit_Lambda(self, lam):
 self.update_position(lam.lineno)
@@ -935,14 +918,22 @@
 
 def visit_With(self, wih):
 self.update_position(wih.lineno, True)
-self.handle_withitem(wih, 0)
+self.handle_withitem(wih, 0, is_async=False)
 
-def handle_withitem(self, wih, pos):
+def handle_withitem(self, wih, pos, is_async):
 body_block = self.new_block()
 cleanup = self.new_block()
 witem = wih.items[pos]
 witem.context_expr.walkabout(self)
-self.emit_jump(ops.SETUP_WITH, cleanup)
+if not is_async:
+self.emit_jump(ops.SETUP_WITH, cleanup)
+else:
+self.emit_op(ops.BEFORE_ASYNC_WITH)
+self.emit_op(ops.GET_AWAITABLE)
+self.load_const(self.space.w_None)
+self.emit_op(ops.YIELD_FROM)
+self.emit_jump(ops.SETUP_ASYNC_WITH, cleanup)
+
 self.use_next_block(body_block)
 self.push_frame_block(F_BLOCK_FINALLY, body_block)
 if witem.optional_vars:
@@ -952,54 +943,24 @@
 if pos == len(wih.items) - 1:
 self.visit_sequence(wih.body)
 else:
-self.handle_withitem(wih, pos + 1)
+self.handle_withitem(wih, pos + 1, is_async=is_async)
 self.emit_op(ops.POP_BLOCK)
 self.pop_frame_block(F_BLOCK_FINALLY, body_block)
 self.load_const(self.space.w_None)
 self.use_next_block(cleanup)
 self.push_frame_block(F_BLOCK_FINALLY_END, cleanup)
 self.emit_op(ops.WITH_CLEANUP_START)
+if is_async:
+self.emit_op(ops.GET_AWAITABLE)
+self.load_const(self.space.w_None)
+self.emit_op(ops.YIELD_FROM)
 self.emit_op(ops.WITH_CLEANUP_FINISH)
 self.emit_op(ops.END_FINALLY)
 self.pop_frame_block(F_BLOCK_FINALLY_END, cleanup)
 
 def visit_AsyncWith(self, wih):
 self.update_position(wih.lineno, True)
-self.handle_asyncwithitem(wih, 0)
-
-def handle_asyncwithitem(self, wih, pos):
-body_block = self.new_block()
-cleanup = self.new_block()
- 

[pypy-commit] pypy py3.5: Keyword only argument default values were evaluated before other defaults

2016-11-01 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r88011:b0a93780397a
Date: 2016-11-01 10:28 +0100
http://bitbucket.org/pypy/pypy/changeset/b0a93780397a/

Log:Keyword only argument default values were evaluated before other
defaults (CPython issue #16967)

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
@@ -376,10 +376,10 @@
 self.visit_sequence(func.decorator_list)
 args = func.args
 assert isinstance(args, ast.arguments)
+self.visit_sequence(args.defaults)
 kw_default_count = 0
 if args.kwonlyargs:
 kw_default_count = self._visit_kwonlydefaults(args)
-self.visit_sequence(args.defaults)
 num_annotations = self._visit_annotations(func, args, func.returns)
 num_defaults = len(args.defaults) if args.defaults is not None else 0
 oparg = num_defaults
@@ -406,10 +406,10 @@
 self.update_position(lam.lineno)
 args = lam.args
 assert isinstance(args, ast.arguments)
+self.visit_sequence(args.defaults)
 kw_default_count = 0
 if args.kwonlyargs:
 kw_default_count = self._visit_kwonlydefaults(args)
-self.visit_sequence(args.defaults)
 default_count = len(args.defaults) if args.defaults is not None else 0
 code, qualname = self.sub_scope(
 LambdaCodeGenerator, "", lam, lam.lineno)
diff --git a/pypy/interpreter/pycode.py b/pypy/interpreter/pycode.py
--- a/pypy/interpreter/pycode.py
+++ b/pypy/interpreter/pycode.py
@@ -38,7 +38,7 @@
 # time you make pyc files incompatible.  This value ends up in the frozen
 # importlib, via MAGIC_NUMBER in module/_frozen_importlib/__init__.
 
-pypy_incremental_magic = 80 # bump it by 16
+pypy_incremental_magic = 96 # bump it by 16
 assert pypy_incremental_magic % 16 == 0
 assert pypy_incremental_magic < 3000 # the magic number of Python 3. There are
  # no known magic numbers below this value
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -1258,7 +1258,6 @@
 w_ann = space.newdict(strdict=True)
 for i in range(len(names_w) - 1, -1, -1):
 space.setitem(w_ann, names_w[i], self.popvalue())
-defaultarguments = self.popvalues(posdefaults)
 kw_defs_w = None
 if kwdefaults:
 kw_defs_w = []
@@ -1266,7 +1265,9 @@
 w_defvalue = self.popvalue()
 w_defname = self.popvalue()
 kw_defs_w.append((w_defname, w_defvalue))
-fn = function.Function(space, codeobj, self.get_w_globals(), 
defaultarguments,
+defaultarguments = self.popvalues(posdefaults)
+fn = function.Function(space, codeobj, self.get_w_globals(),
+   defaultarguments,
kw_defs_w, freevars, w_ann, qualname=qualname)
 self.pushvalue(space.wrap(fn))
 
diff --git a/pypy/interpreter/test/test_compiler.py 
b/pypy/interpreter/test/test_compiler.py
--- a/pypy/interpreter/test/test_compiler.py
+++ b/pypy/interpreter/test/test_compiler.py
@@ -944,6 +944,19 @@
 exc = raises(ValueError, compile, mod, 'filename', 'exec')
 assert str(exc.value) == "empty targets on Delete"
 
+def test_evaluate_argument_definition_order(self): """
+lst = [1, 2, 3, 4]
+def f(a=lst.pop(), b=lst.pop(), *, c=lst.pop(), d=lst.pop()):
+return (a, b, c, d)
+assert f('a') == ('a', 3, 2, 1), repr(f('a'))
+assert f() == (4, 3, 2, 1), repr(f())
+#
+lst = [1, 2, 3, 4]
+f = lambda a=lst.pop(), b=lst.pop(), *, c=lst.pop(), d=lst.pop(): (
+a, b, c, d)
+assert f('a') == ('a', 3, 2, 1), repr(f('a'))
+assert f() == (4, 3, 2, 1), repr(f())
+"""
 
 
 class AppTestOptimizer(object):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Fix docstrings (lib-python test_genexps)

2016-11-01 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r88012:ff0dd56d2098
Date: 2016-11-01 10:32 +0100
http://bitbucket.org/pypy/pypy/changeset/ff0dd56d2098/

Log:Fix docstrings (lib-python test_genexps)

diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py
--- a/pypy/interpreter/generator.py
+++ b/pypy/interpreter/generator.py
@@ -343,11 +343,11 @@
 KIND = "generator"
 
 def descr__iter__(self):
-"""x.__iter__() <==> iter(x)"""
+"""Implement iter(self)."""
 return self.space.wrap(self)
 
 def descr_next(self):
-"""x.__next__() <==> next(x)"""
+"""Implement next(self)."""
 return self.send_ex(self.space.w_None)
 
 # Results can be either an RPython list of W_Root, or it can be an
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: math.inf, math.nan

2016-11-01 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r88013:53911f563c71
Date: 2016-11-01 10:36 +0100
http://bitbucket.org/pypy/pypy/changeset/53911f563c71/

Log:math.inf, math.nan

diff --git a/pypy/module/math/__init__.py b/pypy/module/math/__init__.py
--- a/pypy/module/math/__init__.py
+++ b/pypy/module/math/__init__.py
@@ -11,6 +11,8 @@
 interpleveldefs = {
'e'  : 'interp_math.get(space).w_e',
'pi' : 'interp_math.get(space).w_pi',
+   'inf': 'interp_math.get(space).w_inf',
+   'nan': 'interp_math.get(space).w_nan',
'pow': 'interp_math.pow',
'cosh'   : 'interp_math.cosh',
'copysign'   : 'interp_math.copysign',
diff --git a/pypy/module/math/interp_math.py b/pypy/module/math/interp_math.py
--- a/pypy/module/math/interp_math.py
+++ b/pypy/module/math/interp_math.py
@@ -10,6 +10,8 @@
 def __init__(self, space):
 self.w_e = space.wrap(math.e)
 self.w_pi = space.wrap(math.pi)
+self.w_inf = space.wrap(rfloat.INFINITY)
+self.w_nan = space.wrap(rfloat.NAN)
 def get(space):
 return space.fromcache(State)
 
diff --git a/pypy/module/math/test/test_math.py 
b/pypy/module/math/test/test_math.py
--- a/pypy/module/math/test/test_math.py
+++ b/pypy/module/math/test/test_math.py
@@ -369,3 +369,9 @@
 assert math.gcd(-4, -10) == 2
 assert math.gcd(0, -10) == 10
 assert math.gcd(0, 0) == 0
+
+def test_inf_nan(self):
+import math
+assert math.isinf(math.inf)
+assert math.inf > -math.inf
+assert math.isnan(math.nan)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: math.gcd() argument types

2016-11-01 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r88014:61a25d2c08c5
Date: 2016-11-01 10:39 +0100
http://bitbucket.org/pypy/pypy/changeset/61a25d2c08c5/

Log:math.gcd() argument types

diff --git a/pypy/module/math/app_math.py b/pypy/module/math/app_math.py
--- a/pypy/module/math/app_math.py
+++ b/pypy/module/math/app_math.py
@@ -1,4 +1,5 @@
 import sys
+from _operator import index
 
 def factorial(x):
 """factorial(x) -> Integral
@@ -45,8 +46,8 @@
 
 def gcd(x, y):
 """greatest common divisor of x and y"""
-x = abs(x)
-y = abs(y)
+x = abs(index(x))
+y = abs(index(y))
 while x > 0:
 x, y = y % x, x
 return y
diff --git a/pypy/module/math/test/test_math.py 
b/pypy/module/math/test/test_math.py
--- a/pypy/module/math/test/test_math.py
+++ b/pypy/module/math/test/test_math.py
@@ -369,6 +369,7 @@
 assert math.gcd(-4, -10) == 2
 assert math.gcd(0, -10) == 10
 assert math.gcd(0, 0) == 0
+raises(TypeError, math.gcd, 0, 0.0)
 
 def test_inf_nan(self):
 import math
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: merge branch fix-struct-unpack-Q: make sure that we return an int whenever we can, instead of a long

2016-11-01 Thread antocuni
Author: Antonio Cuni 
Branch: 
Changeset: r88015:6b78c0c00c1c
Date: 2016-11-01 10:47 +0100
http://bitbucket.org/pypy/pypy/changeset/6b78c0c00c1c/

Log:merge branch fix-struct-unpack-Q: make sure that we return an int
whenever we can, instead of a long

diff --git a/pypy/module/struct/formatiterator.py 
b/pypy/module/struct/formatiterator.py
--- a/pypy/module/struct/formatiterator.py
+++ b/pypy/module/struct/formatiterator.py
@@ -1,3 +1,5 @@
+from rpython.rlib.rarithmetic import (r_uint, r_ulonglong, r_longlong,
+  maxint, intmask)
 from rpython.rlib import jit
 from rpython.rlib.objectmodel import specialize
 from rpython.rlib.rstring import StringBuilder
@@ -148,7 +150,20 @@
 
 @specialize.argtype(1)
 def appendobj(self, value):
-self.result_w.append(self.space.wrap(value))
+# CPython tries hard to return int objects whenever it can, but
+# space.wrap returns a long if we pass a r_uint, r_ulonglong or
+# r_longlong. So, we need special care in those cases.
+is_unsigned = (isinstance(value, r_uint) or
+   isinstance(value, r_ulonglong))
+if is_unsigned and value <= maxint:
+w_value = self.space.wrap(intmask(value))
+elif isinstance(value, r_longlong) and -maxint-1 <= value <= maxint:
+w_value = self.space.wrap(intmask(value))
+else:
+# generic type, just use space.wrap
+w_value = self.space.wrap(value)
+#
+self.result_w.append(w_value)
 
 def get_pos(self):
 return self.pos
diff --git a/pypy/module/struct/test/test_struct.py 
b/pypy/module/struct/test/test_struct.py
--- a/pypy/module/struct/test/test_struct.py
+++ b/pypy/module/struct/test/test_struct.py
@@ -431,6 +431,20 @@
 def test_overflow(self):
 raises(self.struct.error, self.struct.pack, 'i', 1<<65)
 
+def test_unpack_fits_into_int(self):
+import sys
+for fmt in 'ILQq':
+# check that we return an int, if it fits
+buf = self.struct.pack(fmt, 42)
+val, = self.struct.unpack(fmt, buf)
+assert val == 42
+assert type(val) is int
+#
+# check that we return a long, if it doesn't fit into an int
+buf = self.struct.pack('Q', sys.maxint+1)
+val, = self.struct.unpack('Q', buf)
+assert val == sys.maxint+1
+assert type(val) is long
 
 class AppTestStructBuffer(object):
 spaceconfig = dict(usemodules=['struct', '__pypy__'])
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: repr() for operator.attrgetter/itemgetter/methodcaller

2016-11-01 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r88016:ba41422861e0
Date: 2016-11-01 10:57 +0100
http://bitbucket.org/pypy/pypy/changeset/ba41422861e0/

Log:repr() for operator.attrgetter/itemgetter/methodcaller

diff --git a/pypy/module/operator/app_operator.py 
b/pypy/module/operator/app_operator.py
--- a/pypy/module/operator/app_operator.py
+++ b/pypy/module/operator/app_operator.py
@@ -56,6 +56,17 @@
 for attrs in self._multi_attrs
 ])
 
+def __repr__(self):
+try:
+a = repr(self._simple_attr)
+except AttributeError:
+try:
+a = repr('.'.join(self._single_attr))
+except AttributeError:
+lst = self._multi_attrs
+a = ', '.join([repr('.'.join(a1)) for a1 in lst])
+return 'operator.attrgetter(%s)' % (a,)
+
 
 class itemgetter(object):
 def __init__(self, item, *items):
@@ -71,6 +82,13 @@
 else:
 return tuple([obj[i] for i in self._idx])
 
+def __repr__(self):
+if self._single:
+a = repr(self._idx)
+else:
+a = ', '.join([repr(i) for i in self._idx])
+return 'operator.itemgetter(%s)' % (a,)
+
 
 class methodcaller(object):
 def __init__(self, method_name, *args, **kwargs):
@@ -80,3 +98,11 @@
 
 def __call__(self, obj):
 return getattr(obj, self._method_name)(*self._args, **self._kwargs)
+
+def __repr__(self):
+args = [repr(self._method_name)]
+for a in self._args:
+args.append(repr(a))
+for key, value in self._kwargs.items():
+args.append('%s=%r' % (key, value))
+return 'operator.methodcaller(%s)' % (', '.join(args),)
diff --git a/pypy/module/operator/test/test_operator.py 
b/pypy/module/operator/test/test_operator.py
--- a/pypy/module/operator/test/test_operator.py
+++ b/pypy/module/operator/test/test_operator.py
@@ -326,3 +326,23 @@
 def test_length_hint(self):
 import _operator as operator
 assert operator.length_hint([1, 2]) == 2
+
+def test_repr_attrgetter(self):
+import _operator as operator
+assert repr(operator.attrgetter("foo")) == "operator.attrgetter('foo')"
+assert repr(operator.attrgetter("foo", 'bar')) == (
+"operator.attrgetter('foo', 'bar')")
+assert repr(operator.attrgetter("foo.bar")) == (
+"operator.attrgetter('foo.bar')")
+assert repr(operator.attrgetter("foo", 'bar.baz')) == (
+"operator.attrgetter('foo', 'bar.baz')")
+
+def test_repr_itemgetter(self):
+import _operator as operator
+assert repr(operator.itemgetter(2)) == "operator.itemgetter(2)"
+assert repr(operator.itemgetter(2, 3)) == "operator.itemgetter(2, 3)"
+
+def test_repr_methodcaller(self):
+import _operator as operator
+assert repr(operator.methodcaller("foo", "bar", baz=42)) == (
+"operator.methodcaller('foo', 'bar', baz=42)")
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: test and fix

2016-11-01 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r88017:63c487334766
Date: 2016-11-01 11:00 +0100
http://bitbucket.org/pypy/pypy/changeset/63c487334766/

Log:test and fix

diff --git a/pypy/module/operator/app_operator.py 
b/pypy/module/operator/app_operator.py
--- a/pypy/module/operator/app_operator.py
+++ b/pypy/module/operator/app_operator.py
@@ -92,6 +92,8 @@
 
 class methodcaller(object):
 def __init__(self, method_name, *args, **kwargs):
+if not isinstance(method_name, str):
+raise TypeError("method name must be a string")
 self._method_name = method_name
 self._args = args
 self._kwargs = kwargs
diff --git a/pypy/module/operator/test/test_operator.py 
b/pypy/module/operator/test/test_operator.py
--- a/pypy/module/operator/test/test_operator.py
+++ b/pypy/module/operator/test/test_operator.py
@@ -182,6 +182,11 @@
 assert methodcaller("method", 4, 5)(x) == (4, 5)
 assert methodcaller("method", 4, arg2=42)(x) == (4, 42)
 
+def test_methodcaller_not_string(self):
+import _operator as operator
+e = raises(TypeError, operator.methodcaller, 42)
+assert str(e.value) == "method name must be a string"
+
 def test_index(self):
 import _operator as operator
 assert operator.index(42) == 42
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy ppc-vsx-support: modified test to do wrap arithmetic on integers, otherwise the test result within python does not wrap around

2016-11-01 Thread plan_rich
Author: Richard Plangger 
Branch: ppc-vsx-support
Changeset: r88019:4bacfc342956
Date: 2016-11-01 11:14 +0100
http://bitbucket.org/pypy/pypy/changeset/4bacfc342956/

Log:modified test to do wrap arithmetic on integers, otherwise the test
result within python does not wrap around

diff --git a/rpython/jit/metainterp/test/test_vector.py 
b/rpython/jit/metainterp/test/test_vector.py
--- a/rpython/jit/metainterp/test/test_vector.py
+++ b/rpython/jit/metainterp/test/test_vector.py
@@ -420,7 +420,7 @@
 vec_reduce = functools.partial(vec_reduce, _vec_reduce)
 
 test_vec_int_sum = vec_reduce(st.integers(min_value=-2**(64-1), 
max_value=2**(64-1)-1),
- lambda a,b: a+b, lltype.Signed)
+ lambda a,b: 
lltype.intmask(lltype.intmask(a)+lltype.intmask(b)), lltype.Signed)
 test_vec_float_sum = vec_reduce(st.floats(), lambda a,b: a+b, rffi.DOUBLE)
 test_vec_float_prod = vec_reduce(st.floats(), lambda a,b: a*b, rffi.DOUBLE)
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy ppc-vsx-support: accum reduce on integers should not extract both values into the same register

2016-11-01 Thread plan_rich
Author: Richard Plangger 
Branch: ppc-vsx-support
Changeset: r88018:7e4d2957681d
Date: 2016-11-01 10:59 +0100
http://bitbucket.org/pypy/pypy/changeset/7e4d2957681d/

Log:accum reduce on integers should not extract both values into the
same register

diff --git a/rpython/jit/backend/x86/assembler.py 
b/rpython/jit/backend/x86/assembler.py
--- a/rpython/jit/backend/x86/assembler.py
+++ b/rpython/jit/backend/x86/assembler.py
@@ -1,16 +1,14 @@
 import sys
-import os
-import py
 
-from rpython.jit.backend.llsupport import symbolic, jitframe, rewrite
-from rpython.jit.backend.llsupport.assembler import (GuardToken, 
BaseAssembler, debug_bridge)
+from rpython.jit.backend.llsupport import jitframe, rewrite
+from rpython.jit.backend.llsupport.assembler import (GuardToken, BaseAssembler)
 from rpython.jit.backend.llsupport.asmmemmgr import MachineDataBlockWrapper
 from rpython.jit.backend.llsupport.gcmap import allocate_gcmap
-from rpython.jit.metainterp.history import (Const, VOID, ConstInt)
-from rpython.jit.metainterp.history import AbstractFailDescr, INT, REF, FLOAT
+from rpython.jit.metainterp.history import (AbstractFailDescr, INT, REF, FLOAT,
+Const)
 from rpython.jit.metainterp.compile import ResumeGuardDescr
 from rpython.rlib.rjitlog import rjitlog as jl
-from rpython.rtyper.lltypesystem import lltype, rffi, rstr, llmemory
+from rpython.rtyper.lltypesystem import lltype, rffi
 from rpython.rtyper.lltypesystem.lloperation import llop
 from rpython.rtyper.annlowlevel import cast_instance_to_gcref
 from rpython.rtyper import rclass
diff --git a/rpython/jit/backend/x86/regloc.py 
b/rpython/jit/backend/x86/regloc.py
--- a/rpython/jit/backend/x86/regloc.py
+++ b/rpython/jit/backend/x86/regloc.py
@@ -589,6 +589,9 @@
 self._scratch_register_value = value
 self.MOV_ri(X86_64_SCRATCH_REG.value, value)
 
+def trap(self):
+self.INT3()
+
 def begin_reuse_scratch_register(self):
 # --NEVER CALLED (only from a specific test)--
 # Flag the beginning of a block where it is okay to reuse the value
diff --git a/rpython/jit/backend/x86/vector_ext.py 
b/rpython/jit/backend/x86/vector_ext.py
--- a/rpython/jit/backend/x86/vector_ext.py
+++ b/rpython/jit/backend/x86/vector_ext.py
@@ -10,7 +10,8 @@
 xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14,
 X86_64_SCRATCH_REG, X86_64_XMM_SCRATCH_REG, AddressLoc)
 from rpython.jit.backend.llsupport.vector_ext import VectorExt
-from rpython.jit.backend.llsupport.regalloc import get_scale, TempVar, 
NoVariableToSpill
+from rpython.jit.backend.llsupport.regalloc import (get_scale, TempVar,
+NoVariableToSpill)
 from rpython.jit.metainterp.resoperation import (rop, ResOperation,
 VectorOp, VectorGuardOp)
 from rpython.rlib.objectmodel import we_are_translated, always_inline
@@ -39,7 +40,13 @@
 def is_vector(self):
 return True
 def __repr__(self):
-return "" % (id(self),)
+return "" % (id(self),)
+
+class TempInt(TempVar):
+def __init__(self):
+self.type = INT
+def __repr__(self):
+return "" % (id(self),)
 
 class X86VectorExt(VectorExt):
 
@@ -123,12 +130,14 @@
 assert isinstance(vector_loc, RegLoc)
 assert scalar_arg is not None
 orig_scalar_loc = scalar_loc
+tmpvar = None
 if not isinstance(scalar_loc, RegLoc):
 # scalar loc might live in memory, use scratch register and 
save it back later
 if scalar_arg.type == FLOAT:
 scalar_loc = X86_64_XMM_SCRATCH_REG
 else:
-scalar_loc = X86_64_SCRATCH_REG
+tmpvar = TempInt()
+scalar_loc = regalloc.rm.try_allocate_reg(tmpvar)
 self.mov(orig_scalar_loc, scalar_loc)
 if accum_info.accum_operation == '+':
 self._accum_reduce_sum(scalar_arg, vector_loc, scalar_loc)
@@ -137,12 +146,13 @@
 else:
 not_implemented("accum operator %s not implemented" %
 (accum_info.accum_operation)) 
+if tmpvar:
+regalloc.rm.possibly_free_var(tmpvar)
 if scalar_loc is not orig_scalar_loc:
 self.mov(scalar_loc, orig_scalar_loc)
 accum_info = accum_info.next()
 
 def _accum_reduce_mul(self, arg, accumloc, targetloc):
-scratchloc = X86_64_XMM_SCRATCH_REG
 self.mov(accumloc, targetloc)
 # swap the two elements
 self.mc.SHUFPD_xxi(targetloc.value, targetloc.value, 0x01)
diff --git a/rpython/jit/backend/zarch/vector_ext.py 
b/rpython/jit/backend/zarch/vector_ext.py
--- a/rpython/jit/backend/zarch/vector_ext.py
+++ b/rpython/jit/backend/zarch/vector_ext.py
@@ -172,7 +172,7 @@
 assert scalar_arg is not None
 op = accum_info.accum_operation
 self._accum_reduce(op, scalar_arg, vector_loc, sca

[pypy-commit] pypy py3.5: Test and fix

2016-11-01 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r88020:88f5561e826f
Date: 2016-11-01 11:16 +0100
http://bitbucket.org/pypy/pypy/changeset/88f5561e826f/

Log:Test and fix

diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py
--- a/pypy/interpreter/generator.py
+++ b/pypy/interpreter/generator.py
@@ -254,12 +254,10 @@
 operr.normalize_exception(space)
 
 # note: w_yielded_from is always None if 'self.running'
-w_yf = self.w_yielded_from
-if (w_yf is not None and
+if (self.w_yielded_from is not None and
 operr.match(space, space.w_GeneratorExit)):
-self.w_yielded_from = None
 try:
-gen_close_iter(space, w_yf)
+self._gen_close_iter(space)
 except OperationError as e:
 return self.send_error(e)
 
@@ -270,6 +268,16 @@
 operr.set_traceback(tb)
 return self.send_error(operr)
 
+def _gen_close_iter(self, space):
+assert not self.running
+w_yf = self.w_yielded_from
+self.w_yielded_from = None
+self.running = True
+try:
+gen_close_iter(space, w_yf)
+finally:
+self.running = False
+
 def descr_close(self):
 """close() -> raise GeneratorExit inside generator/coroutine."""
 if self.frame is None:
@@ -279,9 +287,8 @@
 # note: w_yielded_from is always None if 'self.running'
 w_yf = self.w_yielded_from
 if w_yf is not None:
-self.w_yielded_from = None
 try:
-gen_close_iter(space, w_yf)
+self._gen_close_iter(space)
 except OperationError as e:
 operr = e
 try:
diff --git a/pypy/interpreter/test/test_generator.py 
b/pypy/interpreter/test/test_generator.py
--- a/pypy/interpreter/test/test_generator.py
+++ b/pypy/interpreter/test/test_generator.py
@@ -417,6 +417,25 @@
 assert gen.gi_yieldfrom is None
 """
 
+def test_gi_running_in_throw_generatorexit(self): """
+# We must force gi_running to be True on the outer generators
+# when running an inner custom close() method.
+class A:
+def __iter__(self):
+return self
+def __next__(self):
+return 42
+def close(self):
+closed.append(gen.gi_running)
+def g():
+yield from A()
+gen = g()
+assert next(gen) == 42
+closed = []
+raises(GeneratorExit, gen.throw, GeneratorExit)
+assert closed == [True]
+"""
+
 
 def test_should_not_inline(space):
 from pypy.interpreter.generator import should_not_inline
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Test and fix

2016-11-01 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r88021:f9dfa88ad22a
Date: 2016-11-01 11:36 +0100
http://bitbucket.org/pypy/pypy/changeset/f9dfa88ad22a/

Log:Test and fix

diff --git a/pypy/module/__builtin__/functional.py 
b/pypy/module/__builtin__/functional.py
--- a/pypy/module/__builtin__/functional.py
+++ b/pypy/module/__builtin__/functional.py
@@ -335,8 +335,16 @@
 def descr___iter__(self, space):
 return space.wrap(self)
 
-def descr_length(self, space):
-return space.wrap(0 if self.remaining == -1 else self.remaining + 1)
+def descr_length_hint(self, space):
+# bah, there is even a CPython test that checks that this
+# actually calls 'len_w(w_sequence)'.  Obscure.
+res = 0
+if self.remaining >= 0:
+total_length = space.len_w(self.w_sequence)
+rem_length = self.remaining + 1
+if rem_length <= total_length:
+res = rem_length
+return space.wrap(res)
 
 def descr_next(self, space):
 if self.remaining >= 0:
@@ -383,7 +391,7 @@
 W_ReversedIterator.typedef = TypeDef("reversed",
 __new__ = interp2app(W_ReversedIterator.descr___new__2),
 __iter__= interp2app(W_ReversedIterator.descr___iter__),
-__length_hint__ = interp2app(W_ReversedIterator.descr_length),
+__length_hint__ = interp2app(W_ReversedIterator.descr_length_hint),
 __next__= interp2app(W_ReversedIterator.descr_next),
 __reduce__  = interp2app(W_ReversedIterator.descr___reduce__),
 __setstate__  = interp2app(W_ReversedIterator.descr___setstate__),
diff --git a/pypy/module/__builtin__/test/test_functional.py 
b/pypy/module/__builtin__/test/test_functional.py
--- a/pypy/module/__builtin__/test/test_functional.py
+++ b/pypy/module/__builtin__/test/test_functional.py
@@ -527,6 +527,25 @@
 assert list(reversed(list(reversed("hello" == ['h','e','l','l','o']
 raises(TypeError, reversed, reversed("hello"))
 
+def test_reversed_length_hint(self):
+lst = [1, 2, 3]
+r = reversed(lst)
+assert r.__length_hint__() == 3
+assert next(r) == 3
+assert r.__length_hint__() == 2
+lst.pop()
+assert r.__length_hint__() == 2
+lst.pop()
+assert r.__length_hint__() == 0
+raises(StopIteration, next, r)
+#
+r = reversed(lst)
+assert r.__length_hint__() == 1
+assert next(r) == 1
+assert r.__length_hint__() == 0
+raises(StopIteration, next, r)
+assert r.__length_hint__() == 0
+
 
 class AppTestAllAny:
 """
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Improve error message in some cases, like CPython. Use '< >' around

2016-11-01 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r88022:ccec49a07062
Date: 2016-11-01 11:57 +0100
http://bitbucket.org/pypy/pypy/changeset/ccec49a07062/

Log:Improve error message in some cases, like CPython. Use '< >' around
auto-generated scope names even though these names are not really
public.

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
@@ -232,11 +232,7 @@
 class ModuleScope(Scope):
 
 def __init__(self):
-Scope.__init__(self, "top")
-
-def note_await(self, await_node):
-raise SyntaxError("'await' outside async function", await_node.lineno,
-  await_node.col_offset)
+Scope.__init__(self, "")
 
 
 class FunctionScope(Scope):
@@ -270,8 +266,11 @@
 self.has_yield_inside_try = True
 
 def note_await(self, await_node):
-raise SyntaxError("'await' outside async function", await_node.lineno,
-  await_node.col_offset)
+if self.name == '':
+msg = "'await' expressions in comprehensions are not supported"
+else:
+msg = "'await' outside async function"
+raise SyntaxError(msg, await_node.lineno, await_node.col_offset)
 
 def note_return(self, ret):
 if ret.value:
@@ -305,11 +304,9 @@
 if (self.has_free or self.child_has_free) and not self.optimized:
 raise AssertionError("unknown reason for unoptimization")
 
+
 class AsyncFunctionScope(FunctionScope):
 
-def __init__(self, name, lineno, col_offset):
-FunctionScope.__init__(self, name, lineno, col_offset)
-
 def note_yield(self, yield_node):
 raise SyntaxError("'yield' inside async function", yield_node.lineno,
   yield_node.col_offset)
@@ -521,7 +518,7 @@
 assert isinstance(args, ast.arguments)
 self.visit_sequence(args.defaults)
 self.visit_kwonlydefaults(args.kw_defaults)
-new_scope = FunctionScope("lambda", lamb.lineno, lamb.col_offset)
+new_scope = FunctionScope("", lamb.lineno, lamb.col_offset)
 self.push_scope(new_scope, lamb)
 lamb.args.walkabout(self)
 lamb.body.walkabout(self)
@@ -531,7 +528,7 @@
 outer = comps[0]
 assert isinstance(outer, ast.comprehension)
 outer.iter.walkabout(self)
-new_scope = FunctionScope("genexp", node.lineno, node.col_offset)
+new_scope = FunctionScope("", node.lineno, node.col_offset)
 self.push_scope(new_scope, node)
 self.implicit_arg(0)
 outer.target.walkabout(self)
diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py 
b/pypy/interpreter/astcompiler/test/test_compiler.py
--- a/pypy/interpreter/astcompiler/test/test_compiler.py
+++ b/pypy/interpreter/astcompiler/test/test_compiler.py
@@ -1132,6 +1132,15 @@
 """
 py.test.raises(SyntaxError, self.simple_test, source, None, None)
 
+def test_error_message_1(self):
+source = """if 1:
+async def f():
+{await a for a in b}
+"""
+e = py.test.raises(SyntaxError, self.simple_test, source, None, None)
+assert e.value.msg == (
+"'await' expressions in comprehensions are not supported")
+
 
 class AppTestCompiler:
 
diff --git a/pypy/interpreter/astcompiler/test/test_symtable.py 
b/pypy/interpreter/astcompiler/test/test_symtable.py
--- a/pypy/interpreter/astcompiler/test/test_symtable.py
+++ b/pypy/interpreter/astcompiler/test/test_symtable.py
@@ -44,7 +44,7 @@
 gen_scope = mod_scope.children[0]
 assert isinstance(gen_scope, symtable.FunctionScope)
 assert not gen_scope.children
-assert gen_scope.name == "genexp"
+assert gen_scope.name == ""
 return mod_scope, gen_scope
 
 def check_unknown(self, scp, *names):
@@ -251,7 +251,7 @@
 assert len(scp.children) == 1
 lscp = scp.children[0]
 assert isinstance(lscp, symtable.FunctionScope)
-assert lscp.name == "lambda"
+assert lscp.name == ""
 assert lscp.lookup("x") == symtable.SCOPE_LOCAL
 assert lscp.lookup("y") == symtable.SCOPE_GLOBAL_IMPLICIT
 scp = self.mod_scope("lambda x=a: b")
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy ppc-vsx-support: simplification, distinct between integer and float case at update_at_exit

2016-11-01 Thread plan_rich
Author: Richard Plangger 
Branch: ppc-vsx-support
Changeset: r88023:cd016619fb7f
Date: 2016-11-01 12:06 +0100
http://bitbucket.org/pypy/pypy/changeset/cd016619fb7f/

Log:simplification, distinct between integer and float case at
update_at_exit

diff --git a/rpython/jit/backend/zarch/assembler.py 
b/rpython/jit/backend/zarch/assembler.py
--- a/rpython/jit/backend/zarch/assembler.py
+++ b/rpython/jit/backend/zarch/assembler.py
@@ -693,11 +693,6 @@
 
 self.fixup_target_tokens(rawstart)
 self.teardown()
-# oprofile support
-#if self.cpu.profile_agent is not None:
-#name = "Loop # %s: %s" % (looptoken.number, loopname)
-#self.cpu.profile_agent.native_code_written(name,
-#   rawstart, full_size)
 #print(hex(rawstart+looppos))
 #import pdb; pdb.set_trace()
 return AsmInfo(ops_offset, rawstart + looppos,
@@ -1006,7 +1001,7 @@
 return
 # move from fp register to memory
 elif loc.is_stack():
-assert loc.type == FLOAT, "target not float location"
+assert prev_loc.type == FLOAT, "source is not a float location"
 offset = loc.value
 self.mc.STDY(prev_loc, l.addr(offset, r.SPP))
 return
@@ -1600,8 +1595,7 @@
 remap_frame_layout_mixed(self, src_locations1, dst_locations1, 
r.SCRATCH,
  src_locations2, dst_locations2, r.FP_SCRATCH, 
WORD)
 
-offset = self.mc.get_relative_pos()
-self.mc.b_abs(asminfo.rawstart)
+self.mc.b_abs(asminfo.asmaddr)
 
 rawstart = self.materialize_loop(looptoken)
 # update the guard to jump right to this custom piece of assembler
diff --git a/rpython/jit/backend/zarch/vector_ext.py 
b/rpython/jit/backend/zarch/vector_ext.py
--- a/rpython/jit/backend/zarch/vector_ext.py
+++ b/rpython/jit/backend/zarch/vector_ext.py
@@ -168,11 +168,15 @@
 scalar_arg = accum_info.getoriginal()
 orig_scalar_loc = scalar_loc
 if not scalar_loc.is_reg():
-scalar_loc = r.FP_SCRATCH
+if scalar_arg.type == FLOAT:
+scalar_loc = r.FP_SCRATCH
+else:
+scalar_loc = r.SCRATCH2
+self.regalloc_mov(orig_scalar_loc, scalar_loc)
 assert scalar_arg is not None
 op = accum_info.accum_operation
 self._accum_reduce(op, scalar_arg, vector_loc, scalar_loc)
-if scalar_loc is r.FP_SCRATCH:
+if scalar_loc is not orig_scalar_loc:
 self.regalloc_mov(scalar_loc, orig_scalar_loc)
 accum_info = accum_info.next()
 
@@ -268,9 +272,8 @@
 else:
 assert arg.type == INT
 # store the vector onto the stack, just below the stack pointer
-self.mc.VST(accumloc, l.addr(0, r.SP))
-self.mc.LG(r.SCRATCH, l.addr(0, r.SP))
-self.mc.LG(targetloc, l.addr(8, r.SP))
+self.mc.VLGV(r.SCRATCH, accumloc, l.addr(0), l.itemsize_to_mask(8))
+self.mc.VLGV(targetloc, accumloc, l.addr(1), l.itemsize_to_mask(8))
 if op == '+':
 self.mc.AGR(targetloc, r.SCRATCH)
 return
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy ppc-vsx-support: missing import

2016-11-01 Thread plan_rich
Author: Richard Plangger 
Branch: ppc-vsx-support
Changeset: r88024:8151b97480d6
Date: 2016-11-01 12:11 +0100
http://bitbucket.org/pypy/pypy/changeset/8151b97480d6/

Log:missing import

diff --git a/rpython/jit/backend/x86/assembler.py 
b/rpython/jit/backend/x86/assembler.py
--- a/rpython/jit/backend/x86/assembler.py
+++ b/rpython/jit/backend/x86/assembler.py
@@ -5,7 +5,7 @@
 from rpython.jit.backend.llsupport.asmmemmgr import MachineDataBlockWrapper
 from rpython.jit.backend.llsupport.gcmap import allocate_gcmap
 from rpython.jit.metainterp.history import (AbstractFailDescr, INT, REF, FLOAT,
-Const)
+Const, VOID)
 from rpython.jit.metainterp.compile import ResumeGuardDescr
 from rpython.rlib.rjitlog import rjitlog as jl
 from rpython.rtyper.lltypesystem import lltype, rffi
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Modules are weakrefable now

2016-11-01 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r88025:f8b3c91eca76
Date: 2016-11-01 12:33 +0100
http://bitbucket.org/pypy/pypy/changeset/f8b3c91eca76/

Log:Modules are weakrefable now

diff --git a/pypy/interpreter/test/test_module.py 
b/pypy/interpreter/test/test_module.py
--- a/pypy/interpreter/test/test_module.py
+++ b/pypy/interpreter/test/test_module.py
@@ -188,3 +188,7 @@
 excinfo = raises(AttributeError, 'nameless.does_not_exist')
 assert (excinfo.value.args[0] ==
 "module has no attribute 'does_not_exist'")
+
+def test_weakrefable(self):
+import weakref
+weakref.ref(weakref)
diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -632,7 +632,8 @@
 __dir__ = interp2app(Module.descr_module__dir__),
 __reduce__ = interp2app(Module.descr__reduce__),
 __dict__ = GetSetProperty(descr_get_dict, cls=Module), # module 
dictionaries are readonly attributes
-__doc__ = 'module(name[, doc])\n\nCreate a module object.\nThe name must 
be a string; the optional doc argument can have any type.'
+__doc__ = 'module(name[, doc])\n\nCreate a module object.\nThe name must 
be a string; the optional doc argument can have any type.',
+__weakref__ = make_weakref_descr(Module),
 )
 
 getset_func_doc = GetSetProperty(Function.fget_func_doc,
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Update comment

2016-11-01 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r88026:317199b7bd96
Date: 2016-11-01 12:41 +0100
http://bitbucket.org/pypy/pypy/changeset/317199b7bd96/

Log:Update comment

diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -106,8 +106,10 @@
 # So we create a few interp-level subclasses of W_XxxObject, which add
 # some combination of features. This is done using mapdict.
 
-# we need two subclasses of the app-level type, one to add mapdict, and then 
one
-# to add del to not slow down the GC.
+# Note that nowadays, we need not "a few" but only one subclass.  It
+# adds mapdict, which flexibly allows all features.  We handle the
+# presence or absence of an app-level '__del__' by calling
+# register_finalizer() or not.
 
 @specialize.memo()
 def get_unique_interplevel_subclass(space, cls):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy ppc-vsx-support: translation issue, moved function in file

2016-11-01 Thread plan_rich
Author: Richard Plangger 
Branch: ppc-vsx-support
Changeset: r88027:dd5a308d5427
Date: 2016-11-01 13:59 +0100
http://bitbucket.org/pypy/pypy/changeset/dd5a308d5427/

Log:translation issue, moved function in file

diff --git a/rpython/jit/backend/x86/vector_ext.py 
b/rpython/jit/backend/x86/vector_ext.py
--- a/rpython/jit/backend/x86/vector_ext.py
+++ b/rpython/jit/backend/x86/vector_ext.py
@@ -43,8 +43,8 @@
 return "" % (id(self),)
 
 class TempInt(TempVar):
-def __init__(self):
-self.type = INT
+type = INT
+
 def __repr__(self):
 return "" % (id(self),)
 
diff --git a/rpython/jit/backend/zarch/vector_ext.py 
b/rpython/jit/backend/zarch/vector_ext.py
--- a/rpython/jit/backend/zarch/vector_ext.py
+++ b/rpython/jit/backend/zarch/vector_ext.py
@@ -180,6 +180,32 @@
 self.regalloc_mov(scalar_loc, orig_scalar_loc)
 accum_info = accum_info.next()
 
+def _accum_reduce(self, op, arg, accumloc, targetloc):
+# Currently the accumulator can ONLY be 64 bit float/int
+if arg.type == FLOAT:
+self.mc.VX(targetloc, targetloc, targetloc)
+self.mc.VPDI(targetloc, accumloc, accumloc, permi(1,0))
+if op == '+':
+self.mc.VFA(targetloc, targetloc, accumloc, l.imm3, 
l.imm(0b1000), l.imm(0))
+return
+elif op == '*':
+self.mc.VFM(targetloc, targetloc, accumloc, l.imm3, 
l.imm(0b1000), l.imm(0))
+return
+else:
+assert arg.type == INT
+# store the vector onto the stack, just below the stack pointer
+self.mc.VLGV(r.SCRATCH, accumloc, l.addr(0), l.itemsize_to_mask(8))
+self.mc.VLGV(targetloc, accumloc, l.addr(1), l.itemsize_to_mask(8))
+if op == '+':
+self.mc.AGR(targetloc, r.SCRATCH)
+return
+elif op == '*':
+self.mc.MSGR(targetloc, r.SCRATCH)
+return
+not_implemented("reduce sum for %s not impl." % arg)
+
+
+
 def emit_vec_int_is_true(self, op, arglocs, regalloc):
 assert isinstance(op, VectorOp)
 resloc, argloc, sizeloc = arglocs
@@ -259,30 +285,6 @@
 else:
 self.mc.VLREP(resloc, loc0, l.itemsize_to_mask(size))
 
-def _accum_reduce(self, op, arg, accumloc, targetloc):
-# Currently the accumulator can ONLY be 64 bit float/int
-if arg.type == FLOAT:
-self.mc.VPDI(targetloc, accumloc, accumloc, permi(1,0))
-if op == '+':
-self.mc.VFA(targetloc, targetloc, accumloc, l.imm3, 
l.imm(0b1000), l.imm(0))
-return
-elif op == '*':
-self.mc.VFM(targetloc, targetloc, accumloc, l.imm3, 
l.imm(0b1000), l.imm(0))
-return
-else:
-assert arg.type == INT
-# store the vector onto the stack, just below the stack pointer
-self.mc.VLGV(r.SCRATCH, accumloc, l.addr(0), l.itemsize_to_mask(8))
-self.mc.VLGV(targetloc, accumloc, l.addr(1), l.itemsize_to_mask(8))
-if op == '+':
-self.mc.AGR(targetloc, r.SCRATCH)
-return
-elif op == '*':
-self.mc.MSGR(targetloc, r.SCRATCH)
-return
-not_implemented("reduce sum for %s not impl." % arg)
-
-
 def emit_vec_pack_i(self, op, arglocs, regalloc):
 assert isinstance(op, VectorOp)
 resloc, vecloc, sourceloc, residxloc, srcidxloc, countloc, sizeloc = 
arglocs
diff --git a/rpython/jit/metainterp/test/test_vector.py 
b/rpython/jit/metainterp/test/test_vector.py
--- a/rpython/jit/metainterp/test/test_vector.py
+++ b/rpython/jit/metainterp/test/test_vector.py
@@ -215,9 +215,6 @@
 la = data.draw(st.lists(integers, min_size=10, max_size=150))
 l = len(la)
 lb = data.draw(st.lists(integers, min_size=l, max_size=l))
-#la = [0] * 10
-#l = 10
-#lb = [0] * 10
 
 rawstorage = RawStorage()
 va = rawstorage.new(la, type)
@@ -422,7 +419,8 @@
 test_vec_int_sum = vec_reduce(st.integers(min_value=-2**(64-1), 
max_value=2**(64-1)-1),
  lambda a,b: 
lltype.intmask(lltype.intmask(a)+lltype.intmask(b)), lltype.Signed)
 test_vec_float_sum = vec_reduce(st.floats(), lambda a,b: a+b, rffi.DOUBLE)
-test_vec_float_prod = vec_reduce(st.floats(), lambda a,b: a*b, rffi.DOUBLE)
+test_vec_float_prod = vec_reduce(st.floats(min_value=-100, max_value=100,
+   allow_nan=False, 
allow_infinity=False), lambda a,b: a*b, rffi.DOUBLE)
 
 
 def test_constant_expand(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2016-11-01 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r88031:ec98ae5d2272
Date: 2016-11-01 14:43 +0100
http://bitbucket.org/pypy/pypy/changeset/ec98ae5d2272/

Log:hg merge default

diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -106,8 +106,10 @@
 # So we create a few interp-level subclasses of W_XxxObject, which add
 # some combination of features. This is done using mapdict.
 
-# we need two subclasses of the app-level type, one to add mapdict, and then 
one
-# to add del to not slow down the GC.
+# Note that nowadays, we need not "a few" but only one subclass.  It
+# adds mapdict, which flexibly allows all features.  We handle the
+# presence or absence of an app-level '__del__' by calling
+# register_finalizer() or not.
 
 @specialize.memo()
 def get_unique_interplevel_subclass(space, cls):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5-ssl: merge py3.5

2016-11-01 Thread plan_rich
Author: Richard Plangger 
Branch: py3.5-ssl
Changeset: r88030:89ea2e4a319d
Date: 2016-11-01 14:36 +0100
http://bitbucket.org/pypy/pypy/changeset/89ea2e4a319d/

Log:merge py3.5

diff too long, truncating to 2000 out of 2128 lines

diff --git a/lib-python/3/test/test_copy.py b/lib-python/3/test/test_copy.py
--- a/lib-python/3/test/test_copy.py
+++ b/lib-python/3/test/test_copy.py
@@ -7,6 +7,7 @@
 from operator import le, lt, ge, gt, eq, ne
 
 import unittest
+from test import support
 
 order_comparisons = le, lt, ge, gt
 equality_comparisons = eq, ne
diff --git a/lib-python/3/test/test_long.py b/lib-python/3/test/test_long.py
--- a/lib-python/3/test/test_long.py
+++ b/lib-python/3/test/test_long.py
@@ -967,7 +967,7 @@
 self.assertIs(type(got), int)
 
 # bad second argument
-bad_exponents = ('brian', 2.0, 0j, None)
+bad_exponents = ('brian', 2.0, 0j)
 for e in bad_exponents:
 self.assertRaises(TypeError, round, 3, e)
 
diff --git a/lib-python/3/test/test_weakset.py 
b/lib-python/3/test/test_weakset.py
--- a/lib-python/3/test/test_weakset.py
+++ b/lib-python/3/test/test_weakset.py
@@ -11,6 +11,7 @@
 from collections import UserString as ustr
 import gc
 import contextlib
+from test import support
 
 
 class Foo:
diff --git a/lib-python/3/test/test_xml_etree.py 
b/lib-python/3/test/test_xml_etree.py
--- a/lib-python/3/test/test_xml_etree.py
+++ b/lib-python/3/test/test_xml_etree.py
@@ -2085,12 +2085,14 @@
 self.assertEqual(self._ilist(doc), all_tags)
 self.assertEqual(self._ilist(doc, '*'), all_tags)
 
+@impl_detail
 def test_copy(self):
 a = ET.Element('a')
 it = a.iter()
 with self.assertRaises(TypeError):
 copy.copy(it)
 
+@impl_detail
 def test_pickle(self):
 a = ET.Element('a')
 it = a.iter()
diff --git a/lib_pypy/_tkinter/tclobj.py b/lib_pypy/_tkinter/tclobj.py
--- a/lib_pypy/_tkinter/tclobj.py
+++ b/lib_pypy/_tkinter/tclobj.py
@@ -160,7 +160,7 @@
 encoded = value.encode('utf-16')[2:]
 buf = tkffi.new("char[]", encoded)
 inbuf = tkffi.cast("Tcl_UniChar*", buf)
-return tklib.Tcl_NewUnicodeObj(inbuf, len(encoded)/2)
+return tklib.Tcl_NewUnicodeObj(inbuf, len(encoded)//2)
 if isinstance(value, Tcl_Obj):
 tklib.Tcl_IncrRefCount(value._value)
 return value._value
diff --git a/lib_pypy/cffi/cparser.py b/lib_pypy/cffi/cparser.py
--- a/lib_pypy/cffi/cparser.py
+++ b/lib_pypy/cffi/cparser.py
@@ -334,6 +334,8 @@
 realtype, quals = self._get_type_and_quals(
 decl.type, name=decl.name, partial_length_ok=True)
 self._declare('typedef ' + decl.name, realtype, 
quals=quals)
+elif decl.__class__.__name__ == 'Pragma':
+pass# skip pragma, only in pycparser 2.15
 else:
 raise api.CDefError("unrecognized construct", decl)
 except api.FFIError as e:
diff --git a/lib_pypy/cffi/model.py b/lib_pypy/cffi/model.py
--- a/lib_pypy/cffi/model.py
+++ b/lib_pypy/cffi/model.py
@@ -519,10 +519,18 @@
 smallest_value = min(self.enumvalues)
 largest_value = max(self.enumvalues)
 else:
-raise api.CDefError("%r has no values explicitly defined: "
-"refusing to guess which integer type it is "
-"meant to be (unsigned/signed, int/long)"
-% self._get_c_name())
+import warnings
+try:
+# XXX!  The goal is to ensure that the warnings.warn()
+# will not suppress the warning.  We want to get it
+# several times if we reach this point several times.
+__warningregistry__.clear()
+except NameError:
+pass
+warnings.warn("%r has no values explicitly defined; "
+  "guessing that it is equivalent to 'unsigned int'"
+  % self._get_c_name())
+smallest_value = largest_value = 0
 if smallest_value < 0:   # needs a signed type
 sign = 1
 candidate1 = PrimitiveType("int")
diff --git a/lib_pypy/cffi/setuptools_ext.py b/lib_pypy/cffi/setuptools_ext.py
--- a/lib_pypy/cffi/setuptools_ext.py
+++ b/lib_pypy/cffi/setuptools_ext.py
@@ -1,4 +1,5 @@
 import os
+import sys
 
 try:
 basestring
@@ -74,8 +75,13 @@
 Add py_limited_api to kwds if setuptools >= 26 is in use.
 Do not alter the setting if it already exists.
 Setuptools takes care of ignoring the flag on Python 2 and PyPy.
+
+CPython itself should ignore the flag in a debugging version
+(by not listing .abi3.so in the extensions it supports), but
+it doesn't so far, creating troubles.  That's why we check
+for "not sys.flags.debug". (http://bugs.python.org/issue28401)
 """
-if 'py_limi

[pypy-commit] pypy ppc-vsx-support: skip some vector tests where jit summary could not be extracted

2016-11-01 Thread plan_rich
Author: Richard Plangger 
Branch: ppc-vsx-support
Changeset: r88028:7319f8c6a1d9
Date: 2016-11-01 14:16 +0100
http://bitbucket.org/pypy/pypy/changeset/7319f8c6a1d9/

Log:skip some vector tests where jit summary could not be extracted

diff --git a/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py 
b/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py
--- a/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py
@@ -78,7 +78,7 @@
 ('sum','float', 2581, 2581, 1),
 ('prod','float', 1, 3178, 1),
 ('prod','int', 1, 3178, 1),
-('any','int', 1, 1239, 1),
+('any','int', 1, 2239, 1),
 ('any','int', 0, 4912, 0),
 ('all','int', 0, 3420, 0),
 ('all','int', 1, 6757, 1),
@@ -109,6 +109,8 @@
 vlog = self.run(main, [], vec=1)
 assert log.result == vlog.result
 assert log.result == result
+if not log.jit_summary:
+return
 assert log.jit_summary.vecopt_tried == 0
 assert log.jit_summary.vecopt_success == 0
 assert vlog.jit_summary.vecopt_tried > 0
@@ -186,30 +188,30 @@
 assert log.result is True
 assert len(log.loops) == 1
 loop = log._filter(log.loops[0])
-# loop.match("""
-# f31 = raw_load_f(i9, i29, 1, 0, descr=)
-# guard_not_invalidated(descr=...)
-# v32 = float_ne(f31, 0.00)
-# guard_true(i32, descr=...)
-# i36 = int_add(i24, 1)
-# i37 = int_add(i29, 8)
-# i38 = int_ge(i36, i30)
-# guard_false(i38, descr=...)
-# jump(..., descr=...)
-# """)
+loop.match("""
+f31 = raw_load_f(i9, i29, descr=)
+guard_not_invalidated(descr=...)
+i32 = float_ne(f31, 0.00)
+guard_true(i32, descr=...)
+i36 = int_add(i24, 1)
+i37 = int_add(i29, 8)
+i38 = int_ge(i36, i30)
+guard_false(i38, descr=...)
+jump(..., descr=...)
+""")
 # vector version
-assert loop.match("""
-guard_not_invalidated(descr=...)
-i38 = int_add(i25, 2)
-i39 = int_ge(i38, i33)
-guard_false(i39, descr=...)
-v42 = vec_load_f(i9, i32, 1, 0, descr=)
-v43 = vec_float_ne(v42, v36)
-f46 = vec_unpack_f(v42, 0, 1)
-vec_guard_true(v43, descr=...)
-i48 = int_add(i32, 16)
-i50 = int_add(i25, 2)
-jump(..., descr=...)""")
+#assert loop.match("""
+#guard_not_invalidated(descr=...)
+#i38 = int_add(i25, 2)
+#i39 = int_ge(i38, i33)
+#guard_false(i39, descr=...)
+#v42 = vec_load_f(i9, i32, 1, 0, descr=)
+#v43 = vec_float_ne(v42, v36)
+#f46 = vec_unpack_f(v42, 0, 1)
+#vec_guard_true(v43, descr=...)
+#i48 = int_add(i32, 16)
+#i50 = int_add(i25, 2)
+#jump(..., descr=...)""")
 
 def test_array_getitem_basic(self):
 def main():
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy ppc-vsx-support: merge default

2016-11-01 Thread plan_rich
Author: Richard Plangger 
Branch: ppc-vsx-support
Changeset: r88029:189e9af37446
Date: 2016-11-01 14:21 +0100
http://bitbucket.org/pypy/pypy/changeset/189e9af37446/

Log:merge default

diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -106,8 +106,10 @@
 # So we create a few interp-level subclasses of W_XxxObject, which add
 # some combination of features. This is done using mapdict.
 
-# we need two subclasses of the app-level type, one to add mapdict, and then 
one
-# to add del to not slow down the GC.
+# Note that nowadays, we need not "a few" but only one subclass.  It
+# adds mapdict, which flexibly allows all features.  We handle the
+# presence or absence of an app-level '__del__' by calling
+# register_finalizer() or not.
 
 @specialize.memo()
 def get_unique_interplevel_subclass(space, cls):
diff --git a/pypy/module/cpyext/test/test_ztranslation.py 
b/pypy/module/cpyext/test/test_ztranslation.py
deleted file mode 100644
--- a/pypy/module/cpyext/test/test_ztranslation.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from pypy.objspace.fake.checkmodule import checkmodule
-
-def test_cpyext_translates():
-checkmodule('cpyext', '_rawffi', translate_startup=False)
diff --git a/pypy/module/micronumpy/test/test_ztranslation.py 
b/pypy/module/micronumpy/test/test_ztranslation.py
deleted file mode 100644
--- a/pypy/module/micronumpy/test/test_ztranslation.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from pypy.objspace.fake.checkmodule import checkmodule
-
-def test_numpy_translates():
-checkmodule('micronumpy')
diff --git a/pypy/module/struct/formatiterator.py 
b/pypy/module/struct/formatiterator.py
--- a/pypy/module/struct/formatiterator.py
+++ b/pypy/module/struct/formatiterator.py
@@ -1,3 +1,5 @@
+from rpython.rlib.rarithmetic import (r_uint, r_ulonglong, r_longlong,
+  maxint, intmask)
 from rpython.rlib import jit
 from rpython.rlib.objectmodel import specialize
 from rpython.rlib.rstring import StringBuilder
@@ -148,7 +150,20 @@
 
 @specialize.argtype(1)
 def appendobj(self, value):
-self.result_w.append(self.space.wrap(value))
+# CPython tries hard to return int objects whenever it can, but
+# space.wrap returns a long if we pass a r_uint, r_ulonglong or
+# r_longlong. So, we need special care in those cases.
+is_unsigned = (isinstance(value, r_uint) or
+   isinstance(value, r_ulonglong))
+if is_unsigned and value <= maxint:
+w_value = self.space.wrap(intmask(value))
+elif isinstance(value, r_longlong) and -maxint-1 <= value <= maxint:
+w_value = self.space.wrap(intmask(value))
+else:
+# generic type, just use space.wrap
+w_value = self.space.wrap(value)
+#
+self.result_w.append(w_value)
 
 def get_pos(self):
 return self.pos
diff --git a/pypy/module/struct/test/test_struct.py 
b/pypy/module/struct/test/test_struct.py
--- a/pypy/module/struct/test/test_struct.py
+++ b/pypy/module/struct/test/test_struct.py
@@ -431,6 +431,20 @@
 def test_overflow(self):
 raises(self.struct.error, self.struct.pack, 'i', 1<<65)
 
+def test_unpack_fits_into_int(self):
+import sys
+for fmt in 'ILQq':
+# check that we return an int, if it fits
+buf = self.struct.pack(fmt, 42)
+val, = self.struct.unpack(fmt, buf)
+assert val == 42
+assert type(val) is int
+#
+# check that we return a long, if it doesn't fit into an int
+buf = self.struct.pack('Q', sys.maxint+1)
+val, = self.struct.unpack('Q', buf)
+assert val == sys.maxint+1
+assert type(val) is long
 
 class AppTestStructBuffer(object):
 spaceconfig = dict(usemodules=['struct', '__pypy__'])
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy ppc-vsx-support: clear the forwarding information of the prefixed operations as well

2016-11-01 Thread plan_rich
Author: Richard Plangger 
Branch: ppc-vsx-support
Changeset: r88032:ba7a27ee1304
Date: 2016-11-01 16:20 +0100
http://bitbucket.org/pypy/pypy/changeset/ba7a27ee1304/

Log:clear the forwarding information of the prefixed operations as well

diff --git a/rpython/jit/metainterp/optimizeopt/vector.py 
b/rpython/jit/metainterp/optimizeopt/vector.py
--- a/rpython/jit/metainterp/optimizeopt/vector.py
+++ b/rpython/jit/metainterp/optimizeopt/vector.py
@@ -83,7 +83,12 @@
 oplist = self.prefix
 if label:
 oplist = [self.label] + oplist
-return oplist + self.operations + [self.jump]
+if label != True:
+for op in oplist:
+op.set_forwarded(None)
+self.jump.set_forwarded(None)
+ops = oplist + self.operations + [self.jump]
+return ops
 
 def clone(self):
 renamer = Renamer()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Try to fix translation on linux32

2016-11-01 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.5
Changeset: r88033:c715b57ada9b
Date: 2016-11-01 16:28 +0100
http://bitbucket.org/pypy/pypy/changeset/c715b57ada9b/

Log:Try to fix translation on linux32

diff --git a/pypy/module/bz2/interp_bz2.py b/pypy/module/bz2/interp_bz2.py
--- a/pypy/module/bz2/interp_bz2.py
+++ b/pypy/module/bz2/interp_bz2.py
@@ -102,6 +102,8 @@
 INITIAL_BUFFER_SIZE = 8192
 
 UINT_MAX = 2**32-1
+MAX_BUFSIZE = min(sys.maxint, UINT_MAX)
+assert isinstance(MAX_BUFSIZE, int)
 
 if rffi.sizeof(rffi.INT) > 4:
 BIGCHUNK = 512 * 32
@@ -455,7 +457,7 @@
 
 def _decompress_buf(self, data, max_length):
 total_in = len(data)
-in_bufsize = min(total_in, UINT_MAX)
+in_bufsize = min(total_in, MAX_BUFSIZE)
 total_in -= in_bufsize
 with rffi.scoped_nonmovingbuffer(data) as in_buf:
 # setup the input and the size it can consume
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: fix translation

2016-11-01 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r88034:6dd9cf87c0a7
Date: 2016-11-01 15:41 +
http://bitbucket.org/pypy/pypy/changeset/6dd9cf87c0a7/

Log:fix translation

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
@@ -578,7 +578,7 @@
 self.pop_frame_block(F_BLOCK_LOOP, start)
 self.visit_sequence(fr.orelse)
 self.use_next_block(end)
-
+
 def visit_AsyncFor(self, fr):
 self.update_position(fr.lineno, True)
 b_try = self.new_block()
@@ -588,21 +588,21 @@
 b_try_cleanup = self.new_block()
 b_after_loop = self.new_block()
 b_after_loop_else = self.new_block()
-
+
 self.emit_jump(ops.SETUP_LOOP, b_after_loop)
 self.push_frame_block(F_BLOCK_LOOP, b_try)
-
+
 fr.iter.walkabout(self)
 self.emit_op(ops.GET_AITER)
 self.load_const(self.space.w_None)
 self.emit_op(ops.YIELD_FROM)
-
+
 self.use_next_block(b_try)
 # This adds another line, so each for iteration can be traced.
 self.lineno_set = False
 self.emit_jump(ops.SETUP_EXCEPT, b_except)
 self.push_frame_block(F_BLOCK_EXCEPT, b_try)
-
+
 self.emit_op(ops.GET_ANEXT)
 self.load_const(self.space.w_None)
 self.emit_op(ops.YIELD_FROM)
@@ -610,13 +610,13 @@
 self.emit_op(ops.POP_BLOCK)
 self.pop_frame_block(F_BLOCK_EXCEPT, b_try)
 self.emit_jump(ops.JUMP_FORWARD, b_after_try)
-
+
 self.use_next_block(b_except)
 self.emit_op(ops.DUP_TOP)
 self.emit_op_name(ops.LOAD_GLOBAL, self.names, "StopAsyncIteration")
 self.emit_op_arg(ops.COMPARE_OP, 10)
 self.emit_jump(ops.POP_JUMP_IF_FALSE, b_try_cleanup, True)
-
+
 self.emit_op(ops.POP_TOP)
 self.emit_op(ops.POP_TOP)
 self.emit_op(ops.POP_TOP)
@@ -630,23 +630,23 @@
 self.emit_op(ops.POP_TOP)
 self.emit_op(ops.POP_BLOCK) # for SETUP_LOOP
 self.emit_jump(ops.JUMP_ABSOLUTE, b_after_loop_else, True)
-
+
 self.use_next_block(b_try_cleanup)
 self.emit_op(ops.END_FINALLY)
-
+
 self.use_next_block(b_after_try)
 self.visit_sequence(fr.body)
 self.emit_jump(ops.JUMP_ABSOLUTE, b_try, True)
-
+
 self.emit_op(ops.POP_BLOCK) # for SETUP_LOOP
 self.pop_frame_block(F_BLOCK_LOOP, b_try)
-
+
 self.use_next_block(b_after_loop)
 self.emit_jump(ops.JUMP_ABSOLUTE, b_end, True)
-
+
 self.use_next_block(b_after_loop_else)
 self.visit_sequence(fr.orelse)
-
+
 self.use_next_block(b_end)
 
 def visit_While(self, wh):
@@ -701,7 +701,7 @@
 self.emit_op(ops.POP_TOP)
 if handler.name:
 ## generate the equivalent of:
-## 
+##
 ## try:
 ## # body
 ## except type as name:
@@ -960,7 +960,7 @@
 
 def visit_AsyncWith(self, wih):
 self.update_position(wih.lineno, True)
-self.handle_asyncwithitem(wih, 0, is_async=True)
+self.handle_withitem(wih, 0, is_async=True)
 
 def visit_Raise(self, rais):
 self.update_position(rais.lineno, True)
@@ -1008,7 +1008,7 @@
 self.emit_op(ops.GET_YIELD_FROM_ITER)
 self.load_const(self.space.w_None)
 self.emit_op(ops.YIELD_FROM)
-
+
 def visit_Await(self, aw):
 self.update_position(aw.lineno)
 aw.value.walkabout(self)
@@ -1147,7 +1147,7 @@
 self.emit_op_arg(outer_op, elt_subitems)
 else:
 self.emit_op_arg(single_op, seen_star)
-
+
 def _visit_assignment(self, node, elts, ctx):
 elt_count = len(elts) if elts else 0
 if ctx == ast.Store:
@@ -1230,7 +1230,7 @@
 self.emit_op_arg(ops.BUILD_MAP_UNPACK, oparg)
 containers -= (oparg - 1)
 is_unpacking = False
-
+
 def visit_Set(self, s):
 self._visit_starunpack(s, s.elts, ops.BUILD_SET, ops.BUILD_SET, 
ops.BUILD_SET_UNPACK)
 
@@ -1286,7 +1286,7 @@
 # If we ended up with more than one stararg, we need
 # to concatenate them into a single sequence.
 self.emit_op_arg(ops.BUILD_LIST_UNPACK, nsubargs)
-
+
 # Repeat procedure for keyword args
 nseen = 0 # the number of keyword arguments on the stack following
 if keywords is not None:
@@ -1340,7 +1340,7 @@
 return
 call.func.walkabout(self)
 self._make_call(0, call.args, call.keywords)
-
+
 def _call_has_no_star_args(self, call):
 if call.args is not None:
 for elt in call.args:
___
pypy-commit mailing list
pypy-commit

[pypy-commit] pypy py3.5: Implement struct.iter_unpack() function

2016-11-01 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r88035:bbc8635cc762
Date: 2016-11-01 15:50 +
http://bitbucket.org/pypy/pypy/changeset/bbc8635cc762/

Log:Implement struct.iter_unpack() function

diff --git a/pypy/module/struct/__init__.py b/pypy/module/struct/__init__.py
--- a/pypy/module/struct/__init__.py
+++ b/pypy/module/struct/__init__.py
@@ -55,6 +55,7 @@
 'pack_into': 'interp_struct.pack_into',
 'unpack': 'interp_struct.unpack',
 'unpack_from': 'interp_struct.unpack_from',
+'iter_unpack': 'interp_struct.iter_unpack',
 
 'Struct': 'interp_struct.W_Struct',
 '_clearcache': 'interp_struct.clearcache',
diff --git a/pypy/module/struct/interp_struct.py 
b/pypy/module/struct/interp_struct.py
--- a/pypy/module/struct/interp_struct.py
+++ b/pypy/module/struct/interp_struct.py
@@ -186,5 +186,11 @@
 #__length_hint__=
 )
 
+@unwrap_spec(format=str)
+def iter_unpack(space, format, w_buffer):
+w_struct = W_Struct(space, format)
+buf = space.buffer_w(w_buffer, space.BUF_SIMPLE)
+return W_UnpackIter(w_struct, buf)
+
 def clearcache(space):
 """No-op on PyPy"""
diff --git a/pypy/module/struct/test/test_struct.py 
b/pypy/module/struct/test/test_struct.py
--- a/pypy/module/struct/test/test_struct.py
+++ b/pypy/module/struct/test/test_struct.py
@@ -400,6 +400,8 @@
 s = self.struct.Struct('ii')
 it = s.iter_unpack(b)
 assert list(it) == [(0, 0), (0, 0)]
+it = self.struct.iter_unpack('ii', b)
+assert list(it) == [(0, 0), (0, 0)]
 
 def test___float__(self):
 class MyFloat(object):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Add unpack_iterator.__length_hint__()

2016-11-01 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r88036:8596145cda3f
Date: 2016-11-01 16:02 +
http://bitbucket.org/pypy/pypy/changeset/8596145cda3f/

Log:Add unpack_iterator.__length_hint__()

diff --git a/pypy/module/struct/interp_struct.py 
b/pypy/module/struct/interp_struct.py
--- a/pypy/module/struct/interp_struct.py
+++ b/pypy/module/struct/interp_struct.py
@@ -128,6 +128,12 @@
 self.index += size
 return w_res
 
+def descr_length_hint(self, space):
+if self.w_struct is None:
+return space.newint(0)
+length = (self.buf.getlength() - self.index) // self.w_struct.size
+return space.newint(length)
+
 
 class W_Struct(W_Root):
 _immutable_fields_ = ["format", "size"]
@@ -183,7 +189,7 @@
 __new__=interp2app(new_unpackiter),
 __iter__=interp2app(W_UnpackIter.descr_iter),
 __next__=interp2app(W_UnpackIter.descr_next),
-#__length_hint__=
+__length_hint__=interp2app(W_UnpackIter.descr_length_hint)
 )
 
 @unwrap_spec(format=str)
diff --git a/pypy/module/struct/test/test_struct.py 
b/pypy/module/struct/test/test_struct.py
--- a/pypy/module/struct/test/test_struct.py
+++ b/pypy/module/struct/test/test_struct.py
@@ -399,6 +399,7 @@
 b = array.array('b', b'\0' * 16)
 s = self.struct.Struct('ii')
 it = s.iter_unpack(b)
+assert it.__length_hint__() == 2
 assert list(it) == [(0, 0), (0, 0)]
 it = self.struct.iter_unpack('ii', b)
 assert list(it) == [(0, 0), (0, 0)]
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy openssl-1.1: Fix for Windows: fails in untranslated tests if the TLS_method()

2016-11-01 Thread arigo
Author: Armin Rigo 
Branch: openssl-1.1
Changeset: r88037:3f3f9319d227
Date: 2016-11-01 17:30 +0100
http://bitbucket.org/pypy/pypy/changeset/3f3f9319d227/

Log:Fix for Windows: fails in untranslated tests if the TLS_method()
function is made 'macro=True'. Not sure I want to dig into the
reason for that mess.

diff --git a/rpython/rlib/ropenssl.py b/rpython/rlib/ropenssl.py
--- a/rpython/rlib/ropenssl.py
+++ b/rpython/rlib/ropenssl.py
@@ -62,9 +62,6 @@
 '#if (OPENSSL_VERSION_NUMBER < 0x1010)\n'
 '#  define COMP_get_name(meth) (meth->name)\n'
 '#  define COMP_get_type(meth) (meth->type)\n'
-'#  define EVP_MD_CTX_free EVP_MD_CTX_destroy\n'
-'#  define EVP_MD_CTX_new EVP_MD_CTX_create\n'
-'#  define TLS_method SSLv23_method\n'
 '#  define X509_NAME_ENTRY_set(ne) (ne->set)\n'
 '#  define X509_OBJECT_get0_X509(obj) (obj->data.x509)\n'
 '#  define X509_OBJECT_get_type(obj) (obj->type)\n'
@@ -314,8 +311,12 @@
 ssl_external('TLSv1_2_method', [], SSL_METHOD)
 ssl_external('SSLv2_method', [], SSL_METHOD)
 ssl_external('SSLv3_method', [], SSL_METHOD)
-ssl_external('TLS_method', [], SSL_METHOD,
-macro=bool(OPENSSL_VERSION_NUMBER < 0x1010) or None)
+# Windows note: fails in untranslated tests if the following function is
+# made 'macro=True'.  Not sure I want to dig into the reason for that mess.
+libssl_TLS_method = external(
+'TLS_method' if OPENSSL_VERSION_NUMBER >= 0x1010
+else 'SSLv23_method',
+[], SSL_METHOD)
 ssl_external('SSL_CTX_use_PrivateKey_file', [SSL_CTX, rffi.CCHARP, rffi.INT], 
rffi.INT,
  save_err=rffi.RFFI_FULL_ERRNO_ZERO)
 ssl_external('SSL_CTX_use_certificate_chain_file', [SSL_CTX, rffi.CCHARP], 
rffi.INT,
@@ -498,7 +499,10 @@
 # with the GIL held, and so is allowed to run in a RPython __del__ method.
 ssl_external('SSL_free', [SSL], lltype.Void, releasegil=False)
 ssl_external('SSL_CTX_free', [SSL_CTX], lltype.Void, releasegil=False)
-ssl_external('OPENSSL_free', [rffi.VOIDP], lltype.Void, macro=True)
+libssl_OPENSSL_free = external(
+'OPENSSL_free' if OPENSSL_VERSION_NUMBER >= 0x1010
+else 'CRYPTO_free',
+[rffi.VOIDP], lltype.Void)
 
 ssl_external('SSL_write', [SSL, rffi.CCHARP, rffi.INT], rffi.INT,
  save_err=SAVE_ERR)
@@ -586,11 +590,13 @@
 EVP_MD_CTX_copy = external(
 'EVP_MD_CTX_copy', [EVP_MD_CTX, EVP_MD_CTX], rffi.INT)
 EVP_MD_CTX_new = external(
-'EVP_MD_CTX_new', [], EVP_MD_CTX,
-macro=bool(OPENSSL_VERSION_NUMBER < 0x1010) or None)
+'EVP_MD_CTX_new' if OPENSSL_VERSION_NUMBER >= 0x1010
+else 'EVP_MD_CTX_create',
+[], EVP_MD_CTX)
 EVP_MD_CTX_free = external(
-'EVP_MD_CTX_free', [EVP_MD_CTX], lltype.Void, releasegil=False,
-macro=bool(OPENSSL_VERSION_NUMBER < 0x1010) or None)
+'EVP_MD_CTX_free' if OPENSSL_VERSION_NUMBER >= 0x1010
+else 'EVP_MD_CTX_destroy',
+[EVP_MD_CTX], lltype.Void, releasegil=False)
 
 if OPENSSL_VERSION_NUMBER >= 0x1010 and not LIBRESSL:
 PKCS5_PBKDF2_HMAC = external('PKCS5_PBKDF2_HMAC', [
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Fix error messages to match CPython 3.5

2016-11-01 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.5
Changeset: r88040:879102e55ef2
Date: 2016-11-01 17:55 +0100
http://bitbucket.org/pypy/pypy/changeset/879102e55ef2/

Log:Fix error messages to match CPython 3.5

diff --git a/pypy/module/_codecs/interp_codecs.py 
b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -689,7 +689,7 @@
 return errorchar
 
 raise oefmt(space.w_TypeError,
-"character mapping must return integer, None or unicode")
+"character mapping must return integer, None or str")
 
 class Charmap_Encode:
 def __init__(self, space, w_mapping):
@@ -722,7 +722,7 @@
 return errorchar
 
 raise oefmt(space.w_TypeError,
-"character mapping must return integer, None or str")
+"character mapping must return integer, bytes or None, not str")
 
 
 @unwrap_spec(string='bufferstr', errors='str_or_None')
diff --git a/pypy/module/_codecs/test/test_codecs.py 
b/pypy/module/_codecs/test/test_codecs.py
--- a/pypy/module/_codecs/test/test_codecs.py
+++ b/pypy/module/_codecs/test/test_codecs.py
@@ -112,7 +112,7 @@
 assert charmap_decode(b'xxx\xff', 'strict', map) == ('xxx\xff', 4)
 
 exc = raises(TypeError, charmap_decode, b'\xff', "strict",  {0xff: 
b'a'})
-assert str(exc.value) == "character mapping must return integer, None 
or unicode"
+assert str(exc.value) == "character mapping must return integer, None 
or str"
 raises(TypeError, charmap_decode, b'\xff', "strict",  {0xff: 0x11})
 assert (charmap_decode(b"\x00\x01\x02", "strict",
{0: 0x10, 1: ord('b'), 2: ord('c')}) ==
@@ -687,7 +687,7 @@
 exc = raises(TypeError, codecs.charmap_encode, u'\xff', "replace",  
{0xff: 300})
 assert str(exc.value) == 'character mapping must be in range(256)'
 exc = raises(TypeError, codecs.charmap_encode, u'\xff', "replace",  
{0xff: u'a'})
-assert str(exc.value) == 'character mapping must return integer, None 
or str'
+assert str(exc.value) == 'character mapping must return integer, bytes 
or None, not str'
 raises(UnicodeError, codecs.charmap_encode, u"\xff", "replace", {0xff: 
None})
 
 def test_charmap_encode_replace(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Fix test. Testing with -A yields the same error.

2016-11-01 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.5
Changeset: r88039:82de3e6824df
Date: 2016-11-01 17:50 +0100
http://bitbucket.org/pypy/pypy/changeset/82de3e6824df/

Log:Fix test. Testing with -A yields the same error.

diff --git a/pypy/module/_codecs/test/test_codecs.py 
b/pypy/module/_codecs/test/test_codecs.py
--- a/pypy/module/_codecs/test/test_codecs.py
+++ b/pypy/module/_codecs/test/test_codecs.py
@@ -50,7 +50,7 @@
 ]
 for s in insecure:
 buf = b"S" + s + b"\012p0\012."
-raises (ValueError, pickle.loads, buf)
+raises ((ValueError, pickle.UnpicklingError), pickle.loads, buf)
 
 def test_unicodedecodeerror(self):
 assert str(UnicodeDecodeError(
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Implement the codec "namereplace" error handler.

2016-11-01 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.5
Changeset: r88038:d581f95a1c58
Date: 2016-11-01 17:44 +0100
http://bitbucket.org/pypy/pypy/changeset/d581f95a1c58/

Log:Implement the codec "namereplace" error handler. u'\uabcd' ==>
b'\N{SOME NAME}'

diff --git a/pypy/module/_codecs/interp_codecs.py 
b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -1,10 +1,11 @@
 from rpython.rlib import jit
 from rpython.rlib.objectmodel import we_are_translated
-from rpython.rlib.rstring import UnicodeBuilder
+from rpython.rlib.rstring import UnicodeBuilder, StringBuilder
 from rpython.rlib.runicode import code_to_unichr, MAXUNICODE
 
 from pypy.interpreter.error import OperationError, oefmt
 from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
+from pypy.module.unicodedata import unicodedb
 
 
 class VersionTag(object):
@@ -295,6 +296,26 @@
 raise oefmt(space.w_TypeError,
 "don't know how to handle %T in error callback", w_exc)
 
+def namereplace_errors(space, w_exc):
+check_exception(space, w_exc)
+if space.isinstance_w(w_exc, space.w_UnicodeEncodeError):
+obj = space.realunicode_w(space.getattr(w_exc, space.wrap('object')))
+start = space.int_w(space.getattr(w_exc, space.wrap('start')))
+w_end = space.getattr(w_exc, space.wrap('end'))
+end = space.int_w(w_end)
+builder = StringBuilder()
+pos = start
+while pos < end:
+oc = ord(obj[pos])
+builder.append('\\N{')
+builder.append(unicodedb.name(oc))
+builder.append('}')
+pos += 1
+return space.newtuple([space.newbytes(builder.build()), w_end])
+else:
+raise oefmt(space.w_TypeError,
+"don't know how to handle %T in error callback", w_exc)
+
 def surrogatepass_errors(space, w_exc):
 check_exception(space, w_exc)
 if space.isinstance_w(w_exc, space.w_UnicodeEncodeError):
@@ -382,7 +403,8 @@
 "NOT_RPYTHON"
 state = space.fromcache(CodecState)
 for error in ("strict", "ignore", "replace", "xmlcharrefreplace",
-  "backslashreplace", "surrogateescape", "surrogatepass"):
+  "backslashreplace", "surrogateescape", "surrogatepass",
+  "namereplace"):
 name = error + "_errors"
 state.codec_error_registry[error] = 
space.wrap(interp2app(globals()[name]))
 
diff --git a/pypy/module/_codecs/test/test_codecs.py 
b/pypy/module/_codecs/test/test_codecs.py
--- a/pypy/module/_codecs/test/test_codecs.py
+++ b/pypy/module/_codecs/test/test_codecs.py
@@ -561,9 +561,14 @@
 assert b'\xff'.decode('utf-7', 'ignore') == ''
 assert b'\x00'.decode('unicode-internal', 'ignore') == ''
 
-def test_backslahreplace(self):
+def test_backslashreplace(self):
 assert 'a\xac\u1234\u20ac\u8000'.encode('ascii', 'backslashreplace') 
== b'a\\xac\u1234\u20ac\u8000'
 
+def test_namereplace(self):
+assert 'a\xac\u1234\u20ac\u8000'.encode('ascii', 'namereplace') == (
+b'a\\N{NOT SIGN}\\N{ETHIOPIC SYLLABLE SEE}\\N{EURO SIGN}'
+b'\\N{CJK UNIFIED IDEOGRAPH-8000}')
+
 def test_surrogateescape(self):
 assert b'a\x80b'.decode('utf-8', 'surrogateescape') == 'a\udc80b'
 assert 'a\udc80b'.encode('utf-8', 'surrogateescape') == b'a\x80b'
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy space-newtext: remove wrap calls from the __builtin__ module

2016-11-01 Thread cfbolz
Author: Carl Friedrich Bolz 
Branch: space-newtext
Changeset: r88042:1bddaf521a03
Date: 2016-11-01 18:11 +0100
http://bitbucket.org/pypy/pypy/changeset/1bddaf521a03/

Log:remove wrap calls from the __builtin__ module

diff --git a/pypy/module/__builtin__/__init__.py 
b/pypy/module/__builtin__/__init__.py
--- a/pypy/module/__builtin__/__init__.py
+++ b/pypy/module/__builtin__/__init__.py
@@ -101,7 +101,7 @@
 # this is obscure and slow
 space = self.space
 try:
-w_builtin = space.getitem(w_globals, space.wrap('__builtins__'))
+w_builtin = space.getitem(w_globals, space.newtext('__builtins__'))
 except OperationError as e:
 if not e.match(space, space.w_KeyError):
 raise
@@ -114,7 +114,7 @@
 return w_builtin
 # no builtin! make a default one.  Give them None, at least.
 builtin = module.Module(space, None)
-space.setitem(builtin.w_dict, space.wrap('None'), space.w_None)
+space.setitem(builtin.w_dict, space.newtext('None'), space.w_None)
 return builtin
 
 def setup_after_space_initialization(self):
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
@@ -20,7 +20,7 @@
 no __bases__ or if cls.__bases__ is not a tuple.
 """
 try:
-w_bases = space.getattr(w_cls, space.wrap('__bases__'))
+w_bases = space.getattr(w_cls, space.newtext('__bases__'))
 except OperationError as e:
 if not e.match(space, space.w_AttributeError):
 raise   # propagate other errors
@@ -35,12 +35,12 @@
 
 def check_class(space, w_obj, msg):
 if not abstract_isclass_w(space, w_obj):
-raise OperationError(space.w_TypeError, space.wrap(msg))
+raise OperationError(space.w_TypeError, space.newtext(msg))
 
 
 def abstract_getclass(space, w_obj):
 try:
-return space.getattr(w_obj, space.wrap('__class__'))
+return space.getattr(w_obj, space.newtext('__class__'))
 except OperationError as e:
 if not e.match(space, space.w_AttributeError):
 raise   # propagate other errors
@@ -62,7 +62,7 @@
 check_class(space, w_cls, "isinstance() arg 2 must be a class, type,"
   " or tuple of classes and types")
 try:
-w_abstractclass = space.getattr(w_inst, space.wrap('__class__'))
+w_abstractclass = space.getattr(w_inst, space.newtext('__class__'))
 except OperationError as e:
 if e.async(space):  # ignore most exceptions
 raise
@@ -77,7 +77,7 @@
 if space.isinstance_w(w_inst, w_type):
 return True
 try:
-w_abstractclass = space.getattr(w_inst, space.wrap('__class__'))
+w_abstractclass = space.getattr(w_inst, space.newtext('__class__'))
 except OperationError as e:
 if e.async(space):  # ignore most exceptions
 raise
@@ -235,14 +235,14 @@
 another class.  When using a tuple as the second argument, check whether
 'cls' is a subclass of any of the classes listed in the tuple."""
 result = abstract_issubclass_w(space, w_cls, w_klass_or_tuple, True)
-return space.wrap(result)
+return space.newbool(result)
 
 def isinstance(space, w_obj, w_klass_or_tuple):
 """Check whether an object is an instance of a class (or of a subclass
 thereof).  When using a tuple as the second argument, check whether 'obj'
 is an instance of any of the classes listed in the tuple."""
 result = abstract_isinstance_w(space, w_obj, w_klass_or_tuple, True)
-return space.wrap(result)
+return space.newbool(result)
 
 # avoid namespace pollution
 app_issubclass = issubclass; del issubclass
diff --git a/pypy/module/__builtin__/compiling.py 
b/pypy/module/__builtin__/compiling.py
--- a/pypy/module/__builtin__/compiling.py
+++ b/pypy/module/__builtin__/compiling.py
@@ -39,12 +39,11 @@
 
 if space.isinstance_w(w_source, space.gettypeobject(ast.W_AST.typedef)):
 ast_node = ast.mod.from_object(space, w_source)
-code = ec.compiler.compile_ast(ast_node, filename, mode, flags)
-return space.wrap(code)
+return ec.compiler.compile_ast(ast_node, filename, mode, flags)
 
 if space.isinstance_w(w_source, space.w_unicode):
 w_utf_8_source = space.call_method(w_source, "encode",
-   space.wrap("utf-8"))
+   space.newtext("utf-8"))
 source = space.str_w(w_utf_8_source)
 # This flag tells the parser to reject any coding cookies it sees.
 flags |= consts.PyCF_SOURCE_IS_UTF8
@@ -60,8 +59,7 @@
 node = ec.compiler.compile_to_ast(source, filename, mode, flags)
 return node.to_object(space)
 else:
-code = ec.compiler.compile(source, filename, mode, flags)
-return space.wrap

[pypy-commit] pypy space-newtext: remove some str_w calls

2016-11-01 Thread cfbolz
Author: Carl Friedrich Bolz 
Branch: space-newtext
Changeset: r88041:5fef2e96ef36
Date: 2016-11-01 17:55 +0100
http://bitbucket.org/pypy/pypy/changeset/5fef2e96ef36/

Log:remove some str_w calls

diff --git a/pypy/interpreter/argument.py b/pypy/interpreter/argument.py
--- a/pypy/interpreter/argument.py
+++ b/pypy/interpreter/argument.py
@@ -359,7 +359,7 @@
 i = 0
 for w_key in keys_w:
 try:
-key = space.str_w(w_key)
+key = space.text_w(w_key)
 except OperationError as e:
 if e.match(space, space.w_TypeError):
 raise oefmt(space.w_TypeError, "keywords must be strings")
@@ -538,7 +538,7 @@
 w_err = space.newtext("replace")
 w_name = space.call_method(w_name, "encode", w_enc,
w_err)
-name = space.str_w(w_name)
+name = space.text_w(w_name)
 break
 self.kwd_name = name
 
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -636,7 +636,7 @@
 w_keys = self.call_method(w_dic, "keys")
 exc_types_w = {}
 for w_name in self.unpackiterable(w_keys):
-name = self.str_w(w_name)
+name = self.text_w(w_name)
 if not name.startswith('__'):
 excname = name
 w_exc = self.getitem(w_dic, w_name)
diff --git a/pypy/interpreter/pycode.py b/pypy/interpreter/pycode.py
--- a/pypy/interpreter/pycode.py
+++ b/pypy/interpreter/pycode.py
@@ -26,7 +26,7 @@
 # helper
 
 def unpack_str_tuple(space,w_str_tuple):
-return [space.str_w(w_el) for w_el in space.unpackiterable(w_str_tuple)]
+return [space.text_w(w_el) for w_el in space.unpackiterable(w_str_tuple)]
 
 
 # Magic numbers for the bytecode version in code objects.
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -468,7 +468,7 @@
 return self.getcode().co_consts_w[index]
 
 def getname_u(self, index):
-return self.space.str_w(self.getcode().co_names_w[index])
+return self.space.text_w(self.getcode().co_names_w[index])
 
 def getname_w(self, index):
 return self.getcode().co_names_w[index]
diff --git a/pypy/interpreter/test/test_argument.py 
b/pypy/interpreter/test/test_argument.py
--- a/pypy/interpreter/test/test_argument.py
+++ b/pypy/interpreter/test/test_argument.py
@@ -97,6 +97,8 @@
 
 def str_w(self, s):
 return str(s)
+def text_w(self, s):
+return self.str_w(s)
 
 def len(self, x):
 return len(x)
diff --git a/pypy/objspace/std/bytesobject.py b/pypy/objspace/std/bytesobject.py
--- a/pypy/objspace/std/bytesobject.py
+++ b/pypy/objspace/std/bytesobject.py
@@ -31,8 +31,8 @@
 return True
 if self.user_overridden_class or w_other.user_overridden_class:
 return False
-s1 = space.str_w(self)
-s2 = space.str_w(w_other)
+s1 = space.bytes_w(self)
+s2 = space.bytes_w(w_other)
 if len(s2) > 1:
 return s1 is s2
 else:# strings of len <= 1 are unique-ified
@@ -41,7 +41,7 @@
 def immutable_unique_id(self, space):
 if self.user_overridden_class:
 return None
-s = space.str_w(self)
+s = space.bytes_w(self)
 if len(s) > 1:
 uid = compute_unique_id(s)
 else:# strings of len <= 1 are unique-ified
@@ -571,7 +571,7 @@
 w_obj = space.str(w_object)
 if space.is_w(w_stringtype, space.w_str):
 return w_obj  # XXX might be reworked when space.str() typechecks
-value = space.str_w(w_obj)
+value = space.bytes_w(w_obj)
 w_obj = space.allocate_instance(W_BytesObject, w_stringtype)
 W_BytesObject.__init__(w_obj, value)
 return w_obj
diff --git a/pypy/objspace/std/intobject.py b/pypy/objspace/std/intobject.py
--- a/pypy/objspace/std/intobject.py
+++ b/pypy/objspace/std/intobject.py
@@ -696,7 +696,7 @@
 value = space.int_w(w_obj, allow_conversion=False)
 elif space.isinstance_w(w_value, space.w_str):
 value, w_longval = _string_to_int_or_long(space, w_value,
-  space.str_w(w_value))
+  space.text_w(w_value))
 elif space.isinstance_w(w_value, space.w_unicode):
 from pypy.objspace.std.unicodeobject import unicode_to_decimal_w
 string = unicode_to_decimal_w(space, w_value)
@@ -721,7 +721,7 @@
 s = unicode_to_decimal_w(space, w_value)
 else:
 try:
-s = space.str_w(w_value)
+s = space.text_w(w_value)

[pypy-commit] pypy openssl-1.1: Skip running this new test if ssl.get_default_verify_paths() fails (env

2016-11-01 Thread arigo
Author: Armin Rigo 
Branch: openssl-1.1
Changeset: r88043:5f122f991fba
Date: 2016-11-01 18:09 +0100
http://bitbucket.org/pypy/pypy/changeset/5f122f991fba/

Log:Skip running this new test if ssl.get_default_verify_paths() fails
(env not set up)

diff --git a/pypy/module/_ssl/test/test_ssl.py 
b/pypy/module/_ssl/test/test_ssl.py
--- a/pypy/module/_ssl/test/test_ssl.py
+++ b/pypy/module/_ssl/test/test_ssl.py
@@ -273,6 +273,8 @@
 def test_peer_certificate_verify(self):
 import _ssl, ssl, gc
 paths = ssl.get_default_verify_paths()
+if not paths.capath and not paths.cafile:
+skip("ssl.get_default_verify_paths() failed to return any path")
 
 ctx = _ssl._SSLContext(_ssl.PROTOCOL_TLS)
 ctx.verify_mode = _ssl.CERT_REQUIRED
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy openssl-1.1: We need 'OPENSSL_free' on 1.1, and we need it to be a macro there

2016-11-01 Thread arigo
Author: Armin Rigo 
Branch: openssl-1.1
Changeset: r88044:9bf5a9ff7207
Date: 2016-11-01 18:48 +0100
http://bitbucket.org/pypy/pypy/changeset/9bf5a9ff7207/

Log:We need 'OPENSSL_free' on 1.1, and we need it to be a macro there

diff --git a/rpython/rlib/ropenssl.py b/rpython/rlib/ropenssl.py
--- a/rpython/rlib/ropenssl.py
+++ b/rpython/rlib/ropenssl.py
@@ -499,10 +499,12 @@
 # with the GIL held, and so is allowed to run in a RPython __del__ method.
 ssl_external('SSL_free', [SSL], lltype.Void, releasegil=False)
 ssl_external('SSL_CTX_free', [SSL_CTX], lltype.Void, releasegil=False)
-libssl_OPENSSL_free = external(
-'OPENSSL_free' if OPENSSL_VERSION_NUMBER >= 0x1010
-else 'CRYPTO_free',
-[rffi.VOIDP], lltype.Void)
+if OPENSSL_VERSION_NUMBER >= 0x1010:
+ssl_external('OPENSSL_free', [rffi.VOIDP], lltype.Void, macro=True)
+else:
+ssl_external('CRYPTO_free', [rffi.VOIDP], lltype.Void)
+libssl_OPENSSL_free = libssl_CRYPTO_free
+del libssl_CRYPTO_free
 
 ssl_external('SSL_write', [SSL, rffi.CCHARP, rffi.INT], rffi.INT,
  save_err=SAVE_ERR)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Fix memoryview slicing and remove confusing _apply_itemsize()

2016-11-01 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r88045:dad399a5cc08
Date: 2016-11-01 17:50 +
http://bitbucket.org/pypy/pypy/changeset/dad399a5cc08/

Log:Fix memoryview slicing and remove confusing _apply_itemsize()

diff --git a/pypy/objspace/std/bytesobject.py b/pypy/objspace/std/bytesobject.py
--- a/pypy/objspace/std/bytesobject.py
+++ b/pypy/objspace/std/bytesobject.py
@@ -728,6 +728,7 @@
 # Unicode with encoding
 if space.isinstance_w(w_source, space.w_unicode):
 if encoding is None:
+raise RuntimeError
 raise oefmt(space.w_TypeError,
 "string argument without an encoding")
 from pypy.objspace.std.unicodeobject import encode_object
diff --git a/pypy/objspace/std/memoryobject.py 
b/pypy/objspace/std/memoryobject.py
--- a/pypy/objspace/std/memoryobject.py
+++ b/pypy/objspace/std/memoryobject.py
@@ -259,40 +259,38 @@
 
 start, stop, step, size = space.decode_index4(w_index, 
self.getlength())
 # ^^^ for a non-slice index, this returns (index, 0, 0, 1)
-itemsize = self.getitemsize()
-start, stop, size = self._apply_itemsize(space, start, size, itemsize)
 if step == 0:  # index only
+itemsize = self.getitemsize()
 if itemsize == 1:
 ch = self.buf.getitem(start)
 return space.newint(ord(ch))
 else:
 # TODO: this probably isn't very fast
-buf = SubBuffer(self.buf, start, itemsize)
+buf = SubBuffer(self.buf, start*itemsize, itemsize)
 fmtiter = UnpackFormatIterator(space, buf)
 fmtiter.interpret(self.format)
 return fmtiter.result_w[0]
 elif step == 1:
 mv = W_MemoryView.copy(self)
-mv.slice(start, stop, step, size)
+mv.slice(start, step, size)
 mv._init_flags()
 return mv
 else:
 mv = W_MemoryView.copy(self)
-mv.slice(start, stop, step, size)
+mv.slice(start, step, size)
 mv.length = mv.bytecount_from_shape()
 mv._init_flags()
 return mv
 
-def slice(self, start, stop, step, size):
+def slice(self, start, step, size):
 # modifies the buffer, shape and stride to allow step to be > 1
-# NOTE that start, stop & size are already byte offsets/count
 # TODO subbuffer
 strides = self.getstrides()[:]
 shape = self.getshape()[:]
 itemsize = self.getitemsize()
 dim = 0
-self.buf = SubBuffer(self.buf, strides[dim] * (start//itemsize), 
size*step)
-shape[dim] = size//itemsize
+self.buf = SubBuffer(self.buf, strides[dim] * start, 
size*step*itemsize)
+shape[dim] = size
 strides[dim] = strides[dim] * step
 self.strides = strides
 self.shape = shape
@@ -313,18 +311,6 @@
 return W_MemoryView(buf, view.getformat(), view.getitemsize(),
 view.getndim(), view.getshape()[:], 
view.getstrides()[:])
 
-def _apply_itemsize(self, space, start, size, itemsize):
-if itemsize > 1:
-start *= itemsize
-size *= itemsize
-
-stop  = start + size
-# start & stop are now byte offset, thus use self.buf.getlength()
-if stop > self.buf.getlength():
-raise oefmt(space.w_IndexError, 'index out of range')
-
-return start, stop, size
-
 def descr_setitem(self, space, w_index, w_obj):
 self._check_released(space)
 if self.buf.readonly:
@@ -333,7 +319,6 @@
 raise oefmt(space.w_NotImplementedError, "")
 start, stop, step, size = space.decode_index4(w_index, 
self.getlength())
 itemsize = self.getitemsize()
-start, stop, size = self._apply_itemsize(space, start, size, itemsize)
 if step == 0:  # index only
 if itemsize == 1:
 ch = getbytevalue(space, w_obj)
@@ -347,13 +332,13 @@
 raise oefmt(space.w_TypeError,
 "memoryview: invalid type for format '%s'",
 self.format)
-self.buf.setslice(start, fmtiter.result.build())
+self.buf.setslice(start * itemsize, fmtiter.result.build())
 elif step == 1:
 value = space.buffer_w(w_obj, space.BUF_CONTIG_RO)
-if value.getlength() != size:
+if value.getlength() != size * itemsize:
 raise oefmt(space.w_ValueError,
 "cannot modify size of memoryview object")
-self.buf.setslice(start, value.as_str())
+self.buf.setslice(start * itemsize, value.as_str())
 else:
 if self.getndim() != 1:
 raise oefmt(space.w_NotImplementedError,
@@ -366,11 +351,11 @@
 src = space.buffer_w(w_obj, space.BUF_CONTIG_RO)
 

[pypy-commit] pypy py3.5: merge heads

2016-11-01 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r88046:22a3e8d96787
Date: 2016-11-01 17:59 +
http://bitbucket.org/pypy/pypy/changeset/22a3e8d96787/

Log:merge heads

diff --git a/pypy/module/_codecs/interp_codecs.py 
b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -1,10 +1,11 @@
 from rpython.rlib import jit
 from rpython.rlib.objectmodel import we_are_translated
-from rpython.rlib.rstring import UnicodeBuilder
+from rpython.rlib.rstring import UnicodeBuilder, StringBuilder
 from rpython.rlib.runicode import code_to_unichr, MAXUNICODE
 
 from pypy.interpreter.error import OperationError, oefmt
 from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
+from pypy.module.unicodedata import unicodedb
 
 
 class VersionTag(object):
@@ -295,6 +296,26 @@
 raise oefmt(space.w_TypeError,
 "don't know how to handle %T in error callback", w_exc)
 
+def namereplace_errors(space, w_exc):
+check_exception(space, w_exc)
+if space.isinstance_w(w_exc, space.w_UnicodeEncodeError):
+obj = space.realunicode_w(space.getattr(w_exc, space.wrap('object')))
+start = space.int_w(space.getattr(w_exc, space.wrap('start')))
+w_end = space.getattr(w_exc, space.wrap('end'))
+end = space.int_w(w_end)
+builder = StringBuilder()
+pos = start
+while pos < end:
+oc = ord(obj[pos])
+builder.append('\\N{')
+builder.append(unicodedb.name(oc))
+builder.append('}')
+pos += 1
+return space.newtuple([space.newbytes(builder.build()), w_end])
+else:
+raise oefmt(space.w_TypeError,
+"don't know how to handle %T in error callback", w_exc)
+
 def surrogatepass_errors(space, w_exc):
 check_exception(space, w_exc)
 if space.isinstance_w(w_exc, space.w_UnicodeEncodeError):
@@ -382,7 +403,8 @@
 "NOT_RPYTHON"
 state = space.fromcache(CodecState)
 for error in ("strict", "ignore", "replace", "xmlcharrefreplace",
-  "backslashreplace", "surrogateescape", "surrogatepass"):
+  "backslashreplace", "surrogateescape", "surrogatepass",
+  "namereplace"):
 name = error + "_errors"
 state.codec_error_registry[error] = 
space.wrap(interp2app(globals()[name]))
 
@@ -667,7 +689,7 @@
 return errorchar
 
 raise oefmt(space.w_TypeError,
-"character mapping must return integer, None or unicode")
+"character mapping must return integer, None or str")
 
 class Charmap_Encode:
 def __init__(self, space, w_mapping):
@@ -700,7 +722,7 @@
 return errorchar
 
 raise oefmt(space.w_TypeError,
-"character mapping must return integer, None or str")
+"character mapping must return integer, bytes or None, not str")
 
 
 @unwrap_spec(string='bufferstr', errors='str_or_None')
diff --git a/pypy/module/_codecs/test/test_codecs.py 
b/pypy/module/_codecs/test/test_codecs.py
--- a/pypy/module/_codecs/test/test_codecs.py
+++ b/pypy/module/_codecs/test/test_codecs.py
@@ -50,7 +50,7 @@
 ]
 for s in insecure:
 buf = b"S" + s + b"\012p0\012."
-raises (ValueError, pickle.loads, buf)
+raises ((ValueError, pickle.UnpicklingError), pickle.loads, buf)
 
 def test_unicodedecodeerror(self):
 assert str(UnicodeDecodeError(
@@ -112,7 +112,7 @@
 assert charmap_decode(b'xxx\xff', 'strict', map) == ('xxx\xff', 4)
 
 exc = raises(TypeError, charmap_decode, b'\xff', "strict",  {0xff: 
b'a'})
-assert str(exc.value) == "character mapping must return integer, None 
or unicode"
+assert str(exc.value) == "character mapping must return integer, None 
or str"
 raises(TypeError, charmap_decode, b'\xff', "strict",  {0xff: 0x11})
 assert (charmap_decode(b"\x00\x01\x02", "strict",
{0: 0x10, 1: ord('b'), 2: ord('c')}) ==
@@ -561,9 +561,14 @@
 assert b'\xff'.decode('utf-7', 'ignore') == ''
 assert b'\x00'.decode('unicode-internal', 'ignore') == ''
 
-def test_backslahreplace(self):
+def test_backslashreplace(self):
 assert 'a\xac\u1234\u20ac\u8000'.encode('ascii', 'backslashreplace') 
== b'a\\xac\u1234\u20ac\u8000'
 
+def test_namereplace(self):
+assert 'a\xac\u1234\u20ac\u8000'.encode('ascii', 'namereplace') == (
+b'a\\N{NOT SIGN}\\N{ETHIOPIC SYLLABLE SEE}\\N{EURO SIGN}'
+b'\\N{CJK UNIFIED IDEOGRAPH-8000}')
+
 def test_surrogateescape(self):
 assert b'a\x80b'.decode('utf-8', 'surrogateescape') == 'a\udc80b'
 assert 'a\udc80b'.encode('utf-8', 'surrogateescape') == b'a\x80b'
@@ -682,7 +687,7 @@
 exc = raises(TypeError, codecs.charmap_encode, u'\xff', "replace",  
{0xff: 300})
 assert str(exc.value) ==

[pypy-commit] pypy openssl-1.1: some blind LibreSSL fixes

2016-11-01 Thread arigo
Author: Armin Rigo 
Branch: openssl-1.1
Changeset: r88047:a11c8673e565
Date: 2016-11-01 19:15 +0100
http://bitbucket.org/pypy/pypy/changeset/a11c8673e565/

Log:some blind LibreSSL fixes

diff --git a/rpython/rlib/ropenssl.py b/rpython/rlib/ropenssl.py
--- a/rpython/rlib/ropenssl.py
+++ b/rpython/rlib/ropenssl.py
@@ -59,7 +59,7 @@
 '#define pypy_GENERAL_NAME_pop_free(names) 
(sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free))',
 '#define pypy_DIST_POINT_fullname(obj) 
(obj->distpoint->name.fullname)',
 # Backwards compatibility for functions introduced in 1.1
-'#if (OPENSSL_VERSION_NUMBER < 0x1010)\n'
+'#if (OPENSSL_VERSION_NUMBER < 0x1010) || 
defined(LIBRESSL_VERSION_NUMBER)\n'
 '#  define COMP_get_name(meth) (meth->name)\n'
 '#  define COMP_get_type(meth) (meth->type)\n'
 '#  define X509_NAME_ENTRY_set(ne) (ne->set)\n'
@@ -67,9 +67,9 @@
 '#  define X509_OBJECT_get_type(obj) (obj->type)\n'
 '#  define X509_STORE_get0_objects(store) (store->objs)\n'
 '#  define X509_STORE_get0_param(store) (store->param)\n'
-'#else /* (OPENSSL_VERSION_NUMBER < 0x1010) */\n'
+'#else\n'
 '#  define OPENSSL_NO_SSL2\n'
-'#endif /* (OPENSSL_VERSION_NUMBER < 0x1010) */',
+'#endif',
 ],
 )
 
@@ -108,6 +108,7 @@
 ASN1_ITEM_EXP = ASN1_ITEM
 OPENSSL_VERSION_NUMBER = cconfig["OPENSSL_VERSION_NUMBER"]
 LIBRESSL = cconfig["LIBRESSL"]
+OPENSSL_1_1 = OPENSSL_VERSION_NUMBER >= 0x1010 and not LIBRESSL
 HAVE_TLSv1_2 = OPENSSL_VERSION_NUMBER >= 0x10001000
 
 
@@ -137,7 +138,7 @@
 SSL_OP_SINGLE_ECDH_USE = rffi_platform.ConstantInteger(
 "SSL_OP_SINGLE_ECDH_USE")
 SSL_OP_NO_COMPRESSION = rffi_platform.DefinedConstantInteger(
- "SSL_OP_NO_COMPRESSION")
+"SSL_OP_NO_COMPRESSION")
 SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS = rffi_platform.ConstantInteger(
 "SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS")
 SSL_OP_CIPHER_SERVER_PREFERENCE = rffi_platform.ConstantInteger(
@@ -283,9 +284,9 @@
 name, argtypes, restype, **kw)
 
 ssl_external('SSL_load_error_strings', [], lltype.Void,
-macro=bool(OPENSSL_VERSION_NUMBER >= 0x1010 and not LIBRESSL) or None)
+macro=OPENSSL_1_1 or None)
 ssl_external('SSL_library_init', [], rffi.INT,
-macro=bool(OPENSSL_VERSION_NUMBER >= 0x1010 and not LIBRESSL) or None)
+macro=OPENSSL_1_1 or None)
 ssl_external('CRYPTO_num_locks', [], rffi.INT)
 ssl_external('CRYPTO_set_locking_callback',
  [lltype.Ptr(lltype.FuncType(
@@ -314,8 +315,7 @@
 # Windows note: fails in untranslated tests if the following function is
 # made 'macro=True'.  Not sure I want to dig into the reason for that mess.
 libssl_TLS_method = external(
-'TLS_method' if OPENSSL_VERSION_NUMBER >= 0x1010
-else 'SSLv23_method',
+'TLS_method' if OPENSSL_1_1 else 'SSLv23_method',
 [], SSL_METHOD)
 ssl_external('SSL_CTX_use_PrivateKey_file', [SSL_CTX, rffi.CCHARP, rffi.INT], 
rffi.INT,
  save_err=rffi.RFFI_FULL_ERRNO_ZERO)
@@ -345,7 +345,7 @@
  lltype.Void, macro=True)
 ssl_external('SSL_CTX_set_tlsext_servername_arg', [SSL_CTX, rffi.VOIDP], 
lltype.Void, macro=True)
 ssl_external('SSL_CTX_set_tmp_ecdh', [SSL_CTX, EC_KEY], lltype.Void, 
macro=True)
-if 0x1010 > OPENSSL_VERSION_NUMBER >= 0x10002000:
+if OPENSSL_VERSION_NUMBER >= 0x10002000 and not OPENSSL_1_1:
 ssl_external('SSL_CTX_set_ecdh_auto', [SSL_CTX, rffi.INT], lltype.Void,
  macro=True)
 else:
@@ -392,7 +392,7 @@
 ssl_external('X509_NAME_ENTRY_get_object', [X509_NAME_ENTRY], ASN1_OBJECT)
 ssl_external('X509_NAME_ENTRY_get_data', [X509_NAME_ENTRY], ASN1_STRING)
 ssl_external('X509_NAME_ENTRY_set', [X509_NAME_ENTRY], rffi.INT,
-macro=bool(OPENSSL_VERSION_NUMBER < 0x1010) or None)
+macro=(not OPENSSL_1_1) or None)
 ssl_external('i2d_X509', [X509, rffi.CCHARPP], rffi.INT, save_err=SAVE_ERR)
 ssl_external('X509_free', [X509], lltype.Void, releasegil=False)
 ssl_external('X509_check_ca', [X509], rffi.INT)
@@ -411,9 +411,9 @@
 ssl_external('X509_VERIFY_PARAM_clear_flags', [X509_VERIFY_PARAM, rffi.ULONG], 
rffi.INT)
 ssl_external('X509_STORE_add_cert', [X509_STORE, X509], rffi.INT)
 ssl_external('X509_STORE_get0_objects', [X509_STORE], stack_st_X509_OBJECT,
-macro=bool(OPENSSL_VERSION_NUMBER < 0x1010) or None)
+macro=bool(not OPENSSL_1_1) or None)
 ssl_external('X509_STORE_get0_param', [X509_STORE], X509_VERIFY_PARAM,
-macro=bool(OPENSSL_VERSION_NUMBER < 0x1010) or None)
+macro=bool(not OPENSSL_1_1) or None)
 
 ssl_external('X509_get_default_cert_file_env', [], rffi.CCHARP)
 ssl_external('X509_get_default_cert_file', [], rffi.CCHARP)
@@ -451,13 +451,13 @@
 ssl_external('sk_X509_OBJECT_value', [stack_st_X509_OBJECT, rffi.INT],
  X509_OBJECT, macro=True)
 ssl_external('X509_OBJECT_get0_X509', [X509_OBJECT], X509,
- macro=bool(OPENSSL_VERSION_NUMBER < 0x1010)

[pypy-commit] pypy space-newtext: remove wraps in struct module

2016-11-01 Thread cfbolz
Author: Carl Friedrich Bolz 
Branch: space-newtext
Changeset: r88049:e725a8848ced
Date: 2016-11-01 19:04 +0100
http://bitbucket.org/pypy/pypy/changeset/e725a8848ced/

Log:remove wraps in struct module

diff --git a/pypy/module/_pickle_support/maker.py 
b/pypy/module/_pickle_support/maker.py
--- a/pypy/module/_pickle_support/maker.py
+++ b/pypy/module/_pickle_support/maker.py
@@ -15,7 +15,7 @@
 #  Stackless does use this so it might be needed here as well.
 
 def cell_new(space):
-return space.wrap(instantiate(Cell))
+return instantiate(Cell)
 
 def code_new(space, __args__):
 w_type = space.gettypeobject(PyCode.typedef)
@@ -24,11 +24,11 @@
 def func_new(space):
 fu = instantiate(Function)
 fu.w_func_dict = space.newdict()
-return space.wrap(fu)
+return fu
 
 def module_new(space, w_name, w_dict):
 new_mod = Module(space, w_name, w_dict, add_package=False)
-return space.wrap(new_mod)
+return new_mod
 
 def method_new(space, __args__):
 w_type = space.gettypeobject(Method.typedef)
@@ -57,21 +57,21 @@
 
 def frame_new(space):
 new_frame = instantiate(space.FrameClass)   # XXX fish
-return space.wrap(new_frame)
+return new_frame
 
 def traceback_new(space):
 tb = instantiate(PyTraceback)
-return space.wrap(tb)
+return tb
 
 def generator_new(space):
 new_generator = instantiate(GeneratorIterator)
-return space.wrap(new_generator)
+return new_generator
 
 @unwrap_spec(current=int, remaining=int, step=int)
 def xrangeiter_new(space, current, remaining, step):
 from pypy.module.__builtin__.functional import W_XRangeIterator
 new_iter = W_XRangeIterator(space, current, remaining, step)
-return space.wrap(new_iter)
+return new_iter
 
 @unwrap_spec(identifier=str)
 def builtin_code(space, identifier):
@@ -112,13 +112,12 @@
 a tuple with the positions of NULLs as first element.
 """
 tup = [None] * (len(seq_w) + 1)
-w = space.wrap
 num = 1
 nulls = [None for i in seq_w if i is None]
 null_num = 0
 for w_obj in seq_w:
 if w_obj is None:
-nulls[null_num] = w(num - 1)
+nulls[null_num] = space.newint(num - 1)
 null_num += 1
 w_obj = space.w_None
 tup[num] = w_obj
diff --git a/pypy/module/struct/formatiterator.py 
b/pypy/module/struct/formatiterator.py
--- a/pypy/module/struct/formatiterator.py
+++ b/pypy/module/struct/formatiterator.py
@@ -78,7 +78,7 @@
 else:
 msg = "integer argument expected, got non-integer" \
   " (implicit conversion using __int__ is deprecated)"
-space.warn(space.wrap(msg), space.w_DeprecationWarning)
+space.warn(space.newtext(msg), space.w_DeprecationWarning)
 w_index = space.int(w_obj)   # wrapped float -> wrapped int or 
long
 if w_index is None:
 raise StructError("cannot convert argument to integer")
@@ -148,7 +148,7 @@
 
 @specialize.argtype(1)
 def appendobj(self, value):
-self.result_w.append(self.space.wrap(value))
+self.result_w.append(self.space.wrap(value)) # YYY
 
 def get_pos(self):
 return self.pos
diff --git a/pypy/module/struct/interp_struct.py 
b/pypy/module/struct/interp_struct.py
--- a/pypy/module/struct/interp_struct.py
+++ b/pypy/module/struct/interp_struct.py
@@ -26,15 +26,15 @@
 try:
 fmtiter.interpret(format)
 except StructOverflowError as e:
-raise OperationError(space.w_OverflowError, space.wrap(e.msg))
+raise OperationError(space.w_OverflowError, space.newtext(e.msg))
 except StructError as e:
-raise OperationError(get_error(space), space.wrap(e.msg))
+raise OperationError(get_error(space), space.newtext(e.msg))
 return fmtiter.totalsize
 
 
 @unwrap_spec(format=str)
 def calcsize(space, format):
-return space.wrap(_calcsize(space, format))
+return space.newint(_calcsize(space, format))
 
 
 def _pack(space, format, args_w):
@@ -46,15 +46,15 @@
 try:
 fmtiter.interpret(format)
 except StructOverflowError as e:
-raise OperationError(space.w_OverflowError, space.wrap(e.msg))
+raise OperationError(space.w_OverflowError, space.newtext(e.msg))
 except StructError as e:
-raise OperationError(get_error(space), space.wrap(e.msg))
+raise OperationError(get_error(space), space.newtext(e.msg))
 return fmtiter.result.build()
 
 
 @unwrap_spec(format=str)
 def pack(space, format, args_w):
-return space.wrap(_pack(space, format, args_w))
+return space.newbytes(_pack(space, format, args_w))
 
 
 # XXX inefficient
@@ -77,9 +77,9 @@
 try:
 fmtiter.interpret(format)
 except StructOverflowError as e:
-raise OperationError(space.w_OverflowError, space.wrap(e.msg))
+raise OperationError(space.w_OverflowError, space.newtext(e.msg))
 except StructError as e:
-

[pypy-commit] pypy space-newtext: itertools

2016-11-01 Thread cfbolz
Author: Carl Friedrich Bolz 
Branch: space-newtext
Changeset: r88051:3c3faf4c7f55
Date: 2016-11-01 19:13 +0100
http://bitbucket.org/pypy/pypy/changeset/3c3faf4c7f55/

Log:itertools

diff --git a/pypy/module/errno/__init__.py b/pypy/module/errno/__init__.py
--- a/pypy/module/errno/__init__.py
+++ b/pypy/module/errno/__init__.py
@@ -22,5 +22,5 @@
 for name in dir(errno):
 if name.startswith('__') or name in Module.interpleveldefs:
 continue
-Module.interpleveldefs[name] = ("space.wrap(%s)" %
+Module.interpleveldefs[name] = ("space.newint(%s)" %
 (getattr(errno, name), ))
diff --git a/pypy/module/errno/interp_errno.py 
b/pypy/module/errno/interp_errno.py
--- a/pypy/module/errno/interp_errno.py
+++ b/pypy/module/errno/interp_errno.py
@@ -1,5 +1,5 @@
 import errno
 
 def get_errorcode(space):
-return space.wrap(errno.errorcode)
+return space.newint(errno.errorcode)
 
diff --git a/pypy/module/itertools/interp_itertools.py 
b/pypy/module/itertools/interp_itertools.py
--- a/pypy/module/itertools/interp_itertools.py
+++ b/pypy/module/itertools/interp_itertools.py
@@ -12,7 +12,7 @@
 self.w_step = w_step
 
 def iter_w(self):
-return self.space.wrap(self)
+return self
 
 def next_w(self):
 w_c = self.w_c
@@ -22,7 +22,7 @@
 def single_argument(self):
 space = self.space
 return (space.isinstance_w(self.w_step, space.w_int) and
-space.eq_w(self.w_step, space.wrap(1)))
+space.eq_w(self.w_step, space.newint(1)))
 
 def repr_w(self):
 space = self.space
@@ -32,7 +32,7 @@
 else:
 step = space.str_w(space.repr(self.w_step))
 s = 'count(%s, %s)' % (c, step)
-return self.space.wrap(s)
+return self.space.newtext(s)
 
 def reduce_w(self):
 space = self.space
@@ -54,7 +54,7 @@
 check_number(space, w_step)
 r = space.allocate_instance(W_Count, w_subtype)
 r.__init__(space, w_start, w_step)
-return space.wrap(r)
+return r
 
 W_Count.typedef = TypeDef(
 'itertools.count',
@@ -98,12 +98,12 @@
 return self.w_obj
 
 def iter_w(self):
-return self.space.wrap(self)
+return self
 
 def length_w(self):
 if not self.counting:
 return self.space.w_NotImplemented
-return self.space.wrap(self.count)
+return self.space.newint(self.count)
 
 def repr_w(self):
 objrepr = self.space.str_w(self.space.repr(self.w_obj))
@@ -111,12 +111,12 @@
 s = 'repeat(%s, %d)' % (objrepr, self.count)
 else:
 s = 'repeat(%s)' % (objrepr,)
-return self.space.wrap(s)
+return self.space.newtext(s)
 
 def W_Repeat___new__(space, w_subtype, w_object, w_times=None):
 r = space.allocate_instance(W_Repeat, w_subtype)
 r.__init__(space, w_object, w_times)
-return space.wrap(r)
+return r
 
 W_Repeat.typedef = TypeDef(
 'itertools.repeat',
@@ -151,7 +151,7 @@
 self.stopped = False
 
 def iter_w(self):
-return self.space.wrap(self)
+return self
 
 def next_w(self):
 if self.stopped:
@@ -168,7 +168,7 @@
 def W_TakeWhile___new__(space, w_subtype, w_predicate, w_iterable):
 r = space.allocate_instance(W_TakeWhile, w_subtype)
 r.__init__(space, w_predicate, w_iterable)
-return space.wrap(r)
+return r
 
 
 W_TakeWhile.typedef = TypeDef(
@@ -198,7 +198,7 @@
 self.started = False
 
 def iter_w(self):
-return self.space.wrap(self)
+return self
 
 def next_w(self):
 if self.started:
@@ -216,7 +216,7 @@
 def W_DropWhile___new__(space, w_subtype, w_predicate, w_iterable):
 r = space.allocate_instance(W_DropWhile, w_subtype)
 r.__init__(space, w_predicate, w_iterable)
-return space.wrap(r)
+return r
 
 
 W_DropWhile.typedef = TypeDef(
@@ -253,7 +253,7 @@
 self.iterable = space.iter(w_iterable)
 
 def iter_w(self):
-return self.space.wrap(self)
+return self
 
 def next_w(self):
 while True:
@@ -273,7 +273,7 @@
 def W_IFilter___new__(space, w_subtype, w_predicate, w_iterable):
 r = space.allocate_instance(W_IFilter, w_subtype)
 r.__init__(space, w_predicate, w_iterable)
-return space.wrap(r)
+return r
 
 W_IFilter.typedef = TypeDef(
 'itertools.ifilter',
@@ -300,7 +300,7 @@
 def W_IFilterFalse___new__(space, w_subtype, w_predicate, w_iterable):
 r = space.allocate_instance(W_IFilterFalse, w_subtype)
 r.__init__(space, w_predicate, w_iterable)
-return space.wrap(r)
+return r
 
 W_IFilterFalse.typedef = TypeDef(
 'itertools.ifilterfalse',
@@ -379,11 +379,11 @@
 raise
 result = -1
 if result < minimum:
-raise OperationError(space.w_ValueError, space.wrap(errormsg))
+raise OperationError(space.w_ValueError, space.newtext(errormsg))
   

[pypy-commit] pypy space-newtext: remove space.wrap from the array module (one left)

2016-11-01 Thread cfbolz
Author: Carl Friedrich Bolz 
Branch: space-newtext
Changeset: r88048:fea7fb1fd7fb
Date: 2016-11-01 18:21 +0100
http://bitbucket.org/pypy/pypy/changeset/fea7fb1fd7fb/

Log:remove space.wrap from the array module (one left)

diff --git a/pypy/module/array/interp_array.py 
b/pypy/module/array/interp_array.py
--- a/pypy/module/array/interp_array.py
+++ b/pypy/module/array/interp_array.py
@@ -53,11 +53,11 @@
 
 
 def descr_itemsize(space, self):
-return space.wrap(self.itemsize)
+return space.newint(self.itemsize)
 
 
 def descr_typecode(space, self):
-return space.wrap(self.typecode)
+return space.newint(self.typecode)
 
 arr_eq_driver = jit.JitDriver(name='array_eq_driver', greens=['comp_func'],
   reds='auto')
@@ -265,14 +265,14 @@
 size = ovfcheck(self.itemsize * n)
 except OverflowError:
 raise MemoryError
-w_item = space.call_method(w_f, 'read', space.wrap(size))
+w_item = space.call_method(w_f, 'read', space.newint(size))
 item = space.bytes_w(w_item)
 if len(item) < size:
 n = len(item) % self.itemsize
 elems = max(0, len(item) - (len(item) % self.itemsize))
 if n != 0:
 item = item[0:elems]
-self.descr_fromstring(space, space.wrap(item))
+self.descr_fromstring(space, space.newint(item))
 raise oefmt(space.w_EOFError, "not enough items in file")
 self.descr_fromstring(space, w_item)
 
@@ -315,7 +315,7 @@
 """
 if self.typecode == 'u':
 buf = rffi.cast(UNICODE_ARRAY, self._buffer_as_unsigned())
-return space.wrap(rffi.wcharpsize2unicode(buf, self.len))
+return space.newunicode(rffi.wcharpsize2unicode(buf, self.len))
 else:
 raise oefmt(space.w_ValueError,
 "tounicode() may only be called on type 'u' arrays")
@@ -328,8 +328,8 @@
 The length should be multiplied by the itemsize attribute to calculate
 the buffer length in bytes.
 """
-w_ptr = space.wrap(self._buffer_as_unsigned())
-w_len = space.wrap(self.len)
+w_ptr = space.newint(self._buffer_as_unsigned())
+w_len = space.newint(self.len)
 return space.newtuple([w_ptr, w_len])
 
 def descr_reduce(self, space):
@@ -337,11 +337,11 @@
 """
 if self.len > 0:
 w_s = self.descr_tostring(space)
-args = [space.wrap(self.typecode), w_s]
+args = [space.newtext(self.typecode), w_s]
 else:
-args = [space.wrap(self.typecode)]
+args = [space.newtext(self.typecode)]
 try:
-w_dict = space.getattr(self, space.wrap('__dict__'))
+w_dict = space.getattr(self, space.newtext('__dict__'))
 except OperationError:
 w_dict = space.w_None
 return space.newtuple([space.type(self), space.newtuple(args), w_dict])
@@ -382,7 +382,7 @@
 self._charbuf_stop()
 
 def descr_len(self, space):
-return space.wrap(self.len)
+return space.newint(self.len)
 
 def descr_eq(self, space, w_arr2):
 "x.__eq__(y) <==> x==y"
@@ -474,19 +474,19 @@
 
 def descr_repr(self, space):
 if self.len == 0:
-return space.wrap("array('%s')" % self.typecode)
+return space.newtext("array('%s')" % self.typecode)
 elif self.typecode == "c":
 r = space.repr(self.descr_tostring(space))
 s = "array('%s', %s)" % (self.typecode, space.str_w(r))
-return space.wrap(s)
+return space.newtext(s)
 elif self.typecode == "u":
 r = space.repr(self.descr_tounicode(space))
 s = "array('%s', %s)" % (self.typecode, space.str_w(r))
-return space.wrap(s)
+return space.newtext(s)
 else:
 r = space.repr(self.descr_tolist(space))
 s = "array('%s', %s)" % (self.typecode, space.str_w(r))
-return space.wrap(s)
+return space.newtext(s)
 
 W_ArrayBase.typedef = TypeDef(
 'array.array',
@@ -706,7 +706,7 @@
 if not mytype.signed:
 msg = 'un' + msg  # 'signed' => 'unsigned'
 raise OperationError(self.space.w_OverflowError,
- self.space.wrap(msg))
+ self.space.newtext(msg))
 return result
 
 @rgc.must_be_light_finalizer
@@ -845,9 +845,11 @@
 item = self.buffer[idx]
 if mytype.typecode in 'bBhHil':
 item = rffi.cast(lltype.Signed, item)
+return space.newint(item)
 elif mytype.typecode == 'f':
 item = float(item)
-return space.wrap(item)
+return space.newfloat(item)
+return space.wrap(item) # YYY
 
 # interfa

[pypy-commit] pypy space-newtext: warning module

2016-11-01 Thread cfbolz
Author: Carl Friedrich Bolz 
Branch: space-newtext
Changeset: r88050:3e9bc4ff4247
Date: 2016-11-01 19:08 +0100
http://bitbucket.org/pypy/pypy/changeset/3e9bc4ff4247/

Log:warning module

diff --git a/pypy/module/_warnings/interp_warnings.py 
b/pypy/module/_warnings/interp_warnings.py
--- a/pypy/module/_warnings/interp_warnings.py
+++ b/pypy/module/_warnings/interp_warnings.py
@@ -3,14 +3,14 @@
 
 def create_filter(space, w_category, action):
 return space.newtuple([
-space.wrap(action), space.w_None, w_category,
-space.w_None, space.wrap(0)])
+space.newtext(action), space.w_None, w_category,
+space.w_None, space.newint(0)])
 
 class State:
 def __init__(self, space):
 self.init_filters(space)
 self.w_once_registry = space.newdict()
-self.w_default_action = space.wrap("default")
+self.w_default_action = space.newtext("default")
 
 def init_filters(self, space):
 filters_w = []
@@ -40,14 +40,14 @@
 def get_warnings_attr(space, name):
 try:
 w_module = space.getitem(space.sys.get('modules'),
- space.wrap('warnings'))
+ space.newtext('warnings'))
 except OperationError as e:
 if not e.match(space, space.w_KeyError):
 raise
 return None
 
 try:
-return space.getattr(w_module, space.wrap(name))
+return space.getattr(w_module, space.newtext(name))
 except OperationError as e:
 if not e.match(space, space.w_AttributeError):
 raise
@@ -83,43 +83,43 @@
 
 # setup registry
 try:
-w_registry = space.getitem(w_globals, 
space.wrap("__warningregistry__"))
+w_registry = space.getitem(w_globals, 
space.newtext("__warningregistry__"))
 except OperationError as e:
 if not e.match(space, space.w_KeyError):
 raise
 w_registry = space.newdict()
-space.setitem(w_globals, space.wrap("__warningregistry__"), w_registry)
+space.setitem(w_globals, space.newtext("__warningregistry__"), 
w_registry)
 
 # setup module
 try:
-w_module = space.getitem(w_globals, space.wrap("__name__"))
+w_module = space.getitem(w_globals, space.newtext("__name__"))
 except OperationError as e:
 if not e.match(space, space.w_KeyError):
 raise
-w_module = space.wrap("")
+w_module = space.newtext("")
 
 # setup filename
 try:
-w_filename = space.getitem(w_globals, space.wrap("__file__"))
+w_filename = space.getitem(w_globals, space.newtext("__file__"))
 filename = space.str_w(w_filename)
 except OperationError as e:
 if space.str_w(w_module) == '__main__':
 w_argv = space.sys.getdictvalue(space, 'argv')
 if w_argv and space.len_w(w_argv) > 0:
-w_filename = space.getitem(w_argv, space.wrap(0))
+w_filename = space.getitem(w_argv, space.newint(0))
 if not space.is_true(w_filename):
-w_filename = space.wrap('__main__')
+w_filename = space.newtext('__main__')
 else:
 # embedded interpreters don't have sys.argv
-w_filename = space.wrap('__main__')
+w_filename = space.newtext('__main__')
 else:
 w_filename = w_module
 else:
 lc_filename = filename.lower()
-if (lc_filename.endswith(".pyc") or 
+if (lc_filename.endswith(".pyc") or
 lc_filename.endswith(".pyo")):
 # strip last character
-w_filename = space.wrap(filename[:-1])
+w_filename = space.newtext(filename[:-1])
 
 return (w_filename, lineno, w_module, w_registry)
 
@@ -186,24 +186,24 @@
 
 def normalize_module(space, w_filename):
 if not space.is_true(w_filename):
-return space.wrap("")
+return space.newtext("")
 
 filename = space.str_w(w_filename)
 if filename.endswith(".py"):
 n = len(filename) - 3
 assert n >= 0
 filename = filename[:n]
-return space.wrap(filename)
+return space.newtext(filename)
 
 def show_warning(space, w_filename, lineno, w_text, w_category,
  w_sourceline=None):
-w_name = space.getattr(w_category, space.wrap("__name__"))
+w_name = space.getattr(w_category, space.newtext("__name__"))
 w_stderr = space.sys.get("stderr")
 
 # Print "filename:lineno: category: text\n"
 message = "%s:%d: %s: %s\n" % (space.str_w(w_filename), lineno,
space.str_w(w_name), space.str_w(w_text))
-space.call_method(w_stderr, "write", space.wrap(message))
+space.call_method(w_stderr, "write", space.newtext(message))
 
 # Print "  source_line\n"
 if not w_sourceline:
@@ -211,9 +211,9 @@
 # sourceline = linecache.getline(filename, lineno).strip()
 w_builtins = space.g

[pypy-commit] pypy openssl-1.1: close branch, ready to merge

2016-11-01 Thread arigo
Author: Armin Rigo 
Branch: openssl-1.1
Changeset: r88052:36d8204e4025
Date: 2016-11-01 22:55 +0100
http://bitbucket.org/pypy/pypy/changeset/36d8204e4025/

Log:close branch, ready to merge

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: hg merge openssl-1.1

2016-11-01 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r88053:30e64025212d
Date: 2016-11-01 22:58 +0100
http://bitbucket.org/pypy/pypy/changeset/30e64025212d/

Log:hg merge openssl-1.1

Support for OpenSSL version 1.1 (in addition to version 1.0). Thanks
tumbleweed for doing this! Tested on Linux (1.1, 1.0) and on Windows
and Mac (1.0 only).

Tumbleweed says LibreSSL still segfaults _ssl tests and fails
_hashlib tests, just like previously.

diff --git a/lib-python/2.7/test/test_ssl.py b/lib-python/2.7/test/test_ssl.py
--- a/lib-python/2.7/test/test_ssl.py
+++ b/lib-python/2.7/test/test_ssl.py
@@ -26,6 +26,8 @@
 
 PROTOCOLS = sorted(ssl._PROTOCOL_NAMES)
 HOST = support.HOST
+IS_LIBRESSL = ssl.OPENSSL_VERSION.startswith('LibreSSL')
+IS_OPENSSL_1_1 = not IS_LIBRESSL and ssl.OPENSSL_VERSION_INFO >= (1, 1, 0)
 
 def data_file(*name):
 return os.path.join(os.path.dirname(__file__), *name)
@@ -742,15 +744,15 @@
 def test_options(self):
 ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
 # OP_ALL | OP_NO_SSLv2 | OP_NO_SSLv3 is the default value
-self.assertEqual(ssl.OP_ALL | ssl.OP_NO_SSLv2 | ssl.OP_NO_SSLv3,
- ctx.options)
+default = (ssl.OP_ALL | ssl.OP_NO_SSLv2 | ssl.OP_NO_SSLv3)
+if not IS_LIBRESSL and ssl.OPENSSL_VERSION_INFO >= (1, 1, 0):
+default |= ssl.OP_NO_COMPRESSION
+self.assertEqual(default, ctx.options)
 ctx.options |= ssl.OP_NO_TLSv1
-self.assertEqual(ssl.OP_ALL | ssl.OP_NO_SSLv2 | ssl.OP_NO_SSLv3 | 
ssl.OP_NO_TLSv1,
- ctx.options)
+self.assertEqual(default | ssl.OP_NO_TLSv1, ctx.options)
 if can_clear_options():
-ctx.options = (ctx.options & ~ssl.OP_NO_SSLv2) | ssl.OP_NO_TLSv1
-self.assertEqual(ssl.OP_ALL | ssl.OP_NO_TLSv1 | ssl.OP_NO_SSLv3,
- ctx.options)
+ctx.options = (ctx.options & ~ssl.OP_NO_TLSv1)
+self.assertEqual(default, ctx.options)
 ctx.options = 0
 self.assertEqual(0, ctx.options)
 else:
@@ -2918,18 +2920,27 @@
 client_context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
 client_context.load_cert_chain(CERTFILE)
 client_context.set_alpn_protocols(client_protocols)
-stats = server_params_test(client_context, server_context,
-   chatty=True, connectionchatty=True)
-
-msg = "failed trying %s (s) and %s (c).\n" \
-  "was expecting %s, but got %%s from the %%s" \
-  % (str(server_protocols), str(client_protocols),
- str(expected))
-client_result = stats['client_alpn_protocol']
-self.assertEqual(client_result, expected, msg % 
(client_result, "client"))
-server_result = stats['server_alpn_protocols'][-1] \
-if len(stats['server_alpn_protocols']) else 'nothing'
-self.assertEqual(server_result, expected, msg % 
(server_result, "server"))
+try:
+stats = server_params_test(client_context, server_context,
+   chatty=True, 
connectionchatty=True)
+except ssl.SSLError as e:
+stats = e
+
+if expected is None and IS_OPENSSL_1_1:
+# OpenSSL 1.1.0 raises handshake error
+self.assertIsInstance(stats, ssl.SSLError)
+else:
+msg = "failed trying %s (s) and %s (c).\n" \
+  "was expecting %s, but got %%s from the %%s" \
+  % (str(server_protocols), str(client_protocols),
+ str(expected))
+client_result = stats['client_alpn_protocol']
+self.assertEqual(client_result, expected,
+ msg % (client_result, "client"))
+server_result = stats['server_alpn_protocols'][-1] \
+if len(stats['server_alpn_protocols']) else 'nothing'
+self.assertEqual(server_result, expected,
+ msg % (server_result, "server"))
 
 def test_selected_npn_protocol(self):
 # selected_npn_protocol() is None unless NPN is used
diff --git a/pypy/module/_hashlib/__init__.py b/pypy/module/_hashlib/__init__.py
--- a/pypy/module/_hashlib/__init__.py
+++ b/pypy/module/_hashlib/__init__.py
@@ -1,5 +1,6 @@
 from pypy.interpreter.mixedmodule import MixedModule
-from pypy.module._hashlib.interp_hashlib import algorithms, fetch_names
+from pypy.module._hashlib.interp_hashlib import (
+algorithms, fetch_names, HAS_FAST_PKCS5_PBKDF2_HMAC)
 
 
 class Module(MixedModule):
@@ -13,6 +14,9 @@
 for name in algorithms:
 interpleveldefs['ope

[pypy-commit] pypy default: Fix minor transcription error from cpython C extension

2016-11-01 Thread stefanor
Author: Stefano Rivera 
Branch: 
Changeset: r88054:ed8820ed0ae8
Date: 2016-11-01 15:35 -0700
http://bitbucket.org/pypy/pypy/changeset/ed8820ed0ae8/

Log:Fix minor transcription error from cpython C extension

diff --git a/pypy/module/pyexpat/interp_pyexpat.py 
b/pypy/module/pyexpat/interp_pyexpat.py
--- a/pypy/module/pyexpat/interp_pyexpat.py
+++ b/pypy/module/pyexpat/interp_pyexpat.py
@@ -524,8 +524,8 @@
 maxindex = XML_GetSpecifiedAttributeCount(self.itself)
 else:
 maxindex = 0
-while attrs[maxindex]:
-maxindex += 2 # copied
+while attrs[maxindex]:
+maxindex += 2 # copied
 
 if self.ordered_attributes:
 w_attrs = space.newlist([
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: document recent changes for upcoming release

2016-11-01 Thread mattip
Author: Matti Picus 
Branch: 
Changeset: r88055:b8196f0b4a7b
Date: 2016-11-02 01:04 +0200
http://bitbucket.org/pypy/pypy/changeset/b8196f0b4a7b/

Log:document recent changes for upcoming release

diff --git a/pypy/doc/release-pypy2.7-v5.6.0.rst 
b/pypy/doc/release-pypy2.7-v5.6.0.rst
--- a/pypy/doc/release-pypy2.7-v5.6.0.rst
+++ b/pypy/doc/release-pypy2.7-v5.6.0.rst
@@ -16,6 +16,9 @@
 We changed ``timeit`` to now report average +- standard deviation, which is
 better than the misleading minimum value reported in CPython.
 
+We now support building PyPy with OpenSSL 1.1 in our built-in _sll module, as
+well as maintaining support for previous versions.
+
 XXX
 
 As always, this release fixed many issues and bugs raised by the
@@ -72,7 +75,7 @@
 * New features
   * Allow tests run with `-A` to find `libm.so` even if it is a script not a
 dynamically loadable file
-  * Backport fixes to rposix on windows from py2.5
+  * Backport fixes to rposix on windows from py3.5
   * Allow user-defined ``__getitem__`` on subclasses of ``str`` and ``unicode``
   * Add ``inode`` to ``scandir()`` on posix systems
   * Support more attributes on ``super``
@@ -98,6 +101,8 @@
   * Support translation on FreeBSD running on PowerPC
   * Implement ``__rmod__`` on ``str`` and ``unicode`` types
   * Issue warnings for stricter handling of ``__new__``, ``__init__`` args
+  * When using ``struct.unpack('q', ...`` try harder to prefer int to long
+  * Support OpenSSL version 1.1 (in addition to version 1.0)
 
 * Bug Fixes
   * Tweak a float comparison with 0 in `backendopt.inline` to avoid rounding 
errors
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit