[pypy-commit] pypy py3.5-ssl: disable the importing of the _ssl module (not a builtin module anymore)

2016-12-01 Thread plan_rich
Author: Richard Plangger 
Branch: py3.5-ssl
Changeset: r88786:ef10bb6be703
Date: 2016-11-29 16:22 +0100
http://bitbucket.org/pypy/pypy/changeset/ef10bb6be703/

Log:disable the importing of the _ssl module (not a builtin module
anymore)

diff --git a/pypy/interpreter/test/test_appinterp.py 
b/pypy/interpreter/test/test_appinterp.py
--- a/pypy/interpreter/test/test_appinterp.py
+++ b/pypy/interpreter/test/test_appinterp.py
@@ -156,7 +156,7 @@
 assert space1.str_w(w_str) == "hello"
 
 class TestMixedModuleUnfreeze:
-spaceconfig = dict(usemodules=('_ssl', '_socket'))
+spaceconfig = dict(usemodules=('_socket',))
 
 def test_random_stuff_can_unfreeze(self):
 # When a module contains an "import" statement in applevel code, the
@@ -167,13 +167,13 @@
 # at runtime, like setting os.environ (posix module) or initializing
 # the winsock library (_socket module)
 w_socket = self.space.builtin_modules['_socket']
-w_ssl = self.space.builtin_modules['_ssl']
+# _ssl is not builtin anymore, this test also tried to _cleanup_ on
+# the wrapped ssl object
+# w_ssl = self.space.builtin_modules['_ssl']
 
 # Uncomment this line for a workaround
 # space.getattr(w_ssl, space.wrap('SSLError'))
 
 w_socket._cleanup_()
 assert w_socket.startup_called == False
-w_ssl._cleanup_() # w_ssl.appleveldefs['SSLError'] imports _socket
-assert w_socket.startup_called == False
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5-ssl: fail on socket recv_into if length <= -1 or the length is bigger than the buffer can hold + test

2016-12-01 Thread plan_rich
Author: Richard Plangger 
Branch: py3.5-ssl
Changeset: r88787:3259c787b38b
Date: 2016-12-01 12:45 +0100
http://bitbucket.org/pypy/pypy/changeset/3259c787b38b/

Log:fail on socket recv_into if length <= -1 or the length is bigger
than the buffer can hold + test

diff --git a/pypy/module/_socket/interp_socket.py 
b/pypy/module/_socket/interp_socket.py
--- a/pypy/module/_socket/interp_socket.py
+++ b/pypy/module/_socket/interp_socket.py
@@ -517,8 +517,12 @@
 """
 rwbuffer = space.getarg_w('w*', w_buffer)
 lgt = rwbuffer.getlength()
-if nbytes == 0 or nbytes > lgt:
+if nbytes < 0:
+raise oefmt(space.w_ValueError, "negative buffersize in recv_into")
+if nbytes == 0:
 nbytes = lgt
+if lgt < nbytes:
+raise oefmt(space.w_ValueError, "buffer too small for requested 
bytes")
 try:
 return space.wrap(self.sock.recvinto(rwbuffer, nbytes, flags))
 except SocketError as e:
diff --git a/pypy/module/_socket/test/test_sock_app.py 
b/pypy/module/_socket/test/test_sock_app.py
--- a/pypy/module/_socket/test/test_sock_app.py
+++ b/pypy/module/_socket/test/test_sock_app.py
@@ -868,6 +868,22 @@
 posix.close(fileno)
 cli.close()
 
+def test_recv_into_params(self):
+import os
+import _socket
+cli = _socket.socket()
+cli.connect(self.serv.getsockname())
+fileno, addr = self.serv._accept()
+os.write(fileno, b"abcdef")
+#
+m = memoryview(bytearray(5))
+raises(ValueError, cli.recv_into, m, -1)
+raises(ValueError, cli.recv_into, m, 6)
+cli.recv_into(m,5)
+assert m.tobytes() == b"abcde"
+os.close(fileno)
+cli.close()
+
 
 class AppTestErrno:
 spaceconfig = {'usemodules': ['_socket', 'select']}
___
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-12-01 Thread plan_rich
Author: Richard Plangger 
Branch: py3.5-ssl
Changeset: r88788:c75ec5f968ae
Date: 2016-12-01 12:51 +0100
http://bitbucket.org/pypy/pypy/changeset/c75ec5f968ae/

Log:merge py3.5

diff --git a/lib-python/3/distutils/sysconfig_pypy.py 
b/lib-python/3/distutils/sysconfig_pypy.py
--- a/lib-python/3/distutils/sysconfig_pypy.py
+++ b/lib-python/3/distutils/sysconfig_pypy.py
@@ -60,6 +60,8 @@
 
 def _init_posix():
 """Initialize the module as appropriate for POSIX systems."""
+so_list = [s[0] for s in imp.get_suffixes() if s[2] == imp.C_EXTENSION]
+so_ext = (so_list or ['.so'])[0]
 g = {}
 g['CC'] = "gcc -pthread"
 g['CXX'] = "g++ -pthread"
@@ -67,7 +69,7 @@
 g['CFLAGS'] = "-DNDEBUG -O2"
 g['CCSHARED'] = "-fPIC"
 g['LDSHARED'] = "gcc -pthread -shared"
-g['SO'] = [s[0] for s in imp.get_suffixes() if s[2] == imp.C_EXTENSION][0]
+g['SO'] = so_ext
 g['SHLIB_SUFFIX'] = g['SO']
 g['AR'] = "ar"
 g['ARFLAGS'] = "rc"
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -192,6 +192,14 @@
 assert self._finalize_.im_func is not W_Root._finalize_.im_func
 space.finalizer_queue.register_finalizer(self)
 
+def may_unregister_rpython_finalizer(self, space):
+"""Optimization hint only: if there is no user-defined __del__()
+method, pass the hint ``don't call any finalizer'' to rgc.
+"""
+if not self.getclass(space).hasuserdel:
+from rpython.rlib import rgc
+rgc.may_ignore_finalizer(self)
+
 # hooks that the mapdict implementations needs:
 def _get_mapdict_map(self):
 return None
diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py
--- a/pypy/interpreter/generator.py
+++ b/pypy/interpreter/generator.py
@@ -3,7 +3,7 @@
 from pypy.interpreter.pyopcode import LoopBlock, SApplicationException, Yield
 from pypy.interpreter.pycode import CO_YIELD_INSIDE_TRY
 from pypy.interpreter.astcompiler import consts
-from rpython.rlib import jit
+from rpython.rlib import jit, rgc
 from rpython.rlib.objectmodel import specialize
 from rpython.rlib.rarithmetic import r_uint
 
@@ -20,7 +20,7 @@
 self.running = False
 self._name = name   # may be null, use get_name()
 self._qualname = qualname   # may be null, use get_qualname()
-if (isinstance(self, Coroutine)# XXX would be cool not to need this
+if (isinstance(self, Coroutine)
 or self.pycode.co_flags & CO_YIELD_INSIDE_TRY):
 self.register_finalizer(self.space)
 self.saved_operr = None
@@ -89,7 +89,7 @@
 
 # if the frame is now marked as finished, it was RETURNed from
 if frame.frame_finished_execution:
-self.frame = None
+self.frame_is_finished()
 if space.is_w(w_result, space.w_None):
 raise OperationError(space.w_StopIteration, space.w_None)
 else:
@@ -107,6 +107,14 @@
 if self.saved_operr is not None:
 ec.set_sys_exc_info(self.saved_operr)
 self.saved_operr = None
+#
+# Optimization only: after we've started a Coroutine without
+# CO_YIELD_INSIDE_TRY, then Coroutine._finalize_() will be a no-op
+if (isinstance(self, Coroutine)
+and frame.last_instr == -1
+and not (self.pycode.co_flags & CO_YIELD_INSIDE_TRY)):
+rgc.may_ignore_finalizer(self)
+#
 self.running = True
 try:
 w_result = frame.execute_frame(self, w_arg_or_err)
@@ -116,7 +124,7 @@
 if e.match(space, space.w_StopIteration):
 self._leak_stopiteration(e)
 finally:
-self.frame = None
+self.frame_is_finished()
 raise
 finally:
 frame.f_backref = jit.vref_None
@@ -323,6 +331,10 @@
 break
 block = block.previous
 
+def frame_is_finished(self):
+self.frame = None
+rgc.may_ignore_finalizer(self)
+
 
 class GeneratorIterator(GeneratorOrCoroutine):
 "An iterator created by a generator."
@@ -364,7 +376,7 @@
 break
 # if the frame is now marked as finished, it was RETURNed from
 if frame.frame_finished_execution:
-self.frame = None
+self.frame_is_finished()
 break
 results.append(w_result) # YIELDed
 return unpack_into
diff --git a/pypy/interpreter/module.py b/pypy/interpreter/module.py
--- a/pypy/interpreter/module.py
+++ b/pypy/interpreter/module.py
@@ -121,31 +121,8 @@
 return space.newtuple(tup_return)
 
 def descr_module__repr__(self, space):
-w_loader = space.finditem(self.w_dict, space.wrap('__loader__'))
-if w_loa

[pypy-commit] pypy default: precision loss, big number * small number has a different result then doing the calculation in order, disable the feature

2016-12-01 Thread plan_rich
Author: Richard Plangger 
Branch: 
Changeset: r88789:8096cd4c9209
Date: 2016-12-01 13:40 +0100
http://bitbucket.org/pypy/pypy/changeset/8096cd4c9209/

Log:precision loss, big number * small number has a different result
then doing the calculation in order, disable the feature

diff --git a/pypy/module/micronumpy/test/test_zjit.py 
b/pypy/module/micronumpy/test/test_zjit.py
--- a/pypy/module/micronumpy/test/test_zjit.py
+++ b/pypy/module/micronumpy/test/test_zjit.py
@@ -518,12 +518,10 @@
 def test_prod(self):
 result = self.run("prod")
 assert int(result) == 576
-self.check_vectorized(1, 1)
 
 def test_prod_zero(self):
 result = self.run("prod_zero")
 assert int(result) == 0
-self.check_vectorized(1, 1)
 
 
 def define_max():
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
@@ -76,7 +76,6 @@
 arith_comb = [
 ('sum','int', 1742, 1742, 1),
 ('sum','float', 2581, 2581, 1),
-('prod','float', 1, 3178, 1),
 ('prod','int', 1, 3178, 1),
 ('any','int', 1, 2239, 1),
 ('any','int', 0, 4912, 0),
diff --git a/rpython/jit/backend/llgraph/runner.py 
b/rpython/jit/backend/llgraph/runner.py
--- a/rpython/jit/backend/llgraph/runner.py
+++ b/rpython/jit/backend/llgraph/runner.py
@@ -1128,7 +1128,7 @@
 value = sum(value)
 elif info.accum_operation == '*':
 def prod(acc, x): return acc * x
-value = reduce(prod, value, 1)
+value = reduce(prod, value, 1.0)
 else:
 raise NotImplementedError("accum operator in fail guard")
 values[i] = value
diff --git a/rpython/jit/metainterp/optimizeopt/schedule.py 
b/rpython/jit/metainterp/optimizeopt/schedule.py
--- a/rpython/jit/metainterp/optimizeopt/schedule.py
+++ b/rpython/jit/metainterp/optimizeopt/schedule.py
@@ -980,7 +980,6 @@
 class AccumPack(Pack):
 SUPPORTED = { rop.FLOAT_ADD: '+',
   rop.INT_ADD:   '+',
-  rop.FLOAT_MUL: '*',
 }
 
 def __init__(self, nodes, operator, position):
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
@@ -847,6 +847,10 @@
  vecop, count)
 oplist.append(vecop)
 elif pack.reduce_init() == 1:
+# PRECISION loss, because the numbers are accumulated 
(associative, commutative properties must hold)
+# you can end up a small number and a huge number that is 
finally multiplied. giving an
+# inprecision result, thus this is disabled now
+raise NotImplementedError
 # multiply is only supported by floats
 vecop = OpHelpers.create_vec_expand(ConstFloat(1.0), bytesize,
 signed, count)
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
@@ -414,7 +414,9 @@
  lambda a,b: 
lltype.intmask(lltype.intmask(a)+lltype.intmask(b)), lltype.Signed)
 small_floats = st.floats(min_value=-100, max_value=100, allow_nan=False, 
allow_infinity=False)
 test_vec_float_sum = vec_reduce(small_floats, lambda a,b: a+b, rffi.DOUBLE)
-test_vec_float_prod = vec_reduce(small_floats, lambda a,b: a*b, 
rffi.DOUBLE)
+# PRECISION loss, because the numbers are accumulated (associative, 
commutative properties must hold)
+# you can end up a small number and a huge number that is finally 
multiplied losing precision
+# test_vec_float_prod = vec_reduce(small_floats, 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 space-newtext: replace more w_str and str_w instances

2016-12-01 Thread cfbolz
Author: Carl Friedrich Bolz 
Branch: space-newtext
Changeset: r88790:d05e3f3498f3
Date: 2016-12-01 13:31 +0100
http://bitbucket.org/pypy/pypy/changeset/d05e3f3498f3/

Log:replace more w_str and str_w instances

diff --git a/pypy/interpreter/pyparser/error.py 
b/pypy/interpreter/pyparser/error.py
--- a/pypy/interpreter/pyparser/error.py
+++ b/pypy/interpreter/pyparser/error.py
@@ -15,7 +15,7 @@
 if self.filename is None:
 w_filename = space.w_None
 else:
-w_filename = space.newtext(self.filename)
+w_filename = space.newtext_or_none(self.filename)
 if self.text is None:
 w_text = space.w_None
 else:
diff --git a/pypy/module/__pypy__/interp_debug.py 
b/pypy/module/__pypy__/interp_debug.py
--- a/pypy/module/__pypy__/interp_debug.py
+++ b/pypy/module/__pypy__/interp_debug.py
@@ -9,7 +9,7 @@
 
 @jit.dont_look_inside
 def debug_print(space, args_w):
-parts = [space.str_w(space.str(w_item)) for w_item in args_w]
+parts = [space.text_w(space.str(w_item)) for w_item in args_w]
 debug.debug_print(' '.join(parts))
 
 @jit.dont_look_inside
diff --git a/pypy/module/__pypy__/interp_magic.py 
b/pypy/module/__pypy__/interp_magic.py
--- a/pypy/module/__pypy__/interp_magic.py
+++ b/pypy/module/__pypy__/interp_magic.py
@@ -183,8 +183,8 @@
 jit.promote(space.int_w(w_obj))
 elif space.is_w(space.type(w_obj), space.w_float):
 jit.promote(space.float_w(w_obj))
-elif space.is_w(space.type(w_obj), space.w_str):
-jit.promote_string(space.str_w(w_obj))
+elif space.is_w(space.type(w_obj), space.w_bytes):
+jit.promote_string(space.bytes_w(w_obj))
 elif space.is_w(space.type(w_obj), space.w_unicode):
 raise oefmt(space.w_TypeError, "promoting unicode unsupported")
 else:
diff --git a/pypy/module/_io/interp_bufferedio.py 
b/pypy/module/_io/interp_bufferedio.py
--- a/pypy/module/_io/interp_bufferedio.py
+++ b/pypy/module/_io/interp_bufferedio.py
@@ -91,7 +91,7 @@
 
 if not space.isinstance_w(w_data, space.w_str):
 raise oefmt(space.w_TypeError, "read() should return bytes")
-data = space.str_w(w_data)
+data = space.bytes_w(w_data)
 rwbuffer.setslice(0, data)
 return space.newint(len(data))
 
@@ -225,7 +225,7 @@
 raise
 return space.newtext("<%s>" % (typename,))
 else:
-name_repr = space.str_w(space.repr(w_name))
+name_repr = space.text_w(space.repr(w_name))
 return space.newtext("<%s name=%s>" % (typename, name_repr))
 
 # __
diff --git a/pypy/module/_io/interp_fileio.py b/pypy/module/_io/interp_fileio.py
--- a/pypy/module/_io/interp_fileio.py
+++ b/pypy/module/_io/interp_fileio.py
@@ -326,7 +326,7 @@
 w_repr = space.repr(self.w_name)
 return space.newtext(
 "<_io.FileIO name=%s mode='%s'>" % (
-space.str_w(w_repr), self._mode()))
+space.text_w(w_repr), self._mode()))
 
 # __
 
diff --git a/pypy/module/_io/interp_textio.py b/pypy/module/_io/interp_textio.py
--- a/pypy/module/_io/interp_textio.py
+++ b/pypy/module/_io/interp_textio.py
@@ -375,9 +375,8 @@
 else:
 newline = space.unicode_w(w_newline)
 if newline and newline not in (u'\n', u'\r\n', u'\r'):
-r = space.str_w(space.repr(w_newline))
 raise oefmt(space.w_ValueError,
-"illegal newline value: %s", r)
+"illegal newline value: %R", w_newline)
 
 self.line_buffering = line_buffering
 
@@ -398,7 +397,7 @@
 # build the decoder object
 if space.is_true(space.call_method(w_buffer, "readable")):
 w_codec = interp_codecs.lookup_codec(space,
- space.str_w(self.w_encoding))
+ space.text_w(self.w_encoding))
 self.w_decoder = space.call_method(w_codec,
"incrementaldecoder", w_errors)
 if self.readuniversal:
@@ -409,7 +408,7 @@
 # build the encoder object
 if space.is_true(space.call_method(w_buffer, "writable")):
 w_codec = interp_codecs.lookup_codec(space,
- space.str_w(self.w_encoding))
+ space.text_w(self.w_encoding))
 self.w_encoder = space.call_method(w_codec,
"incrementalencoder", w_errors)
 
@@ -875,9 +874,8 @@
 whence)
 
 if space.is_true(space.lt(w_pos, space.newint(0))):
-r = space.str_w(space.repr(w_pos))
 raise oefmt(space.w_ValueError,
-"negative seek position %s", r)
+ 

[pypy-commit] pypy space-newtext: make sure that hacked_filename is a str

2016-12-01 Thread cfbolz
Author: Carl Friedrich Bolz 
Branch: space-newtext
Changeset: r88791:2c4d7a3d4373
Date: 2016-12-01 13:46 +0100
http://bitbucket.org/pypy/pypy/changeset/2c4d7a3d4373/

Log:make sure that hacked_filename is a str

diff --git a/pypy/interpreter/interactive.py b/pypy/interpreter/interactive.py
--- a/pypy/interpreter/interactive.py
+++ b/pypy/interpreter/interactive.py
@@ -169,12 +169,12 @@
 
 def runsource(self, source, ignored_filename="", symbol="single"):
 # the following hacked file name is recognized specially by error.py
-hacked_filename = '\n' + source
 compiler = self.space.getexecutioncontext().compiler
 
 # CPython 2.6 turns console input into unicode
 if isinstance(source, unicode):
 source = source.encode(sys.stdin.encoding)
+hacked_filename = '\n' + source
 
 def doit():
 # compile the provided input
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy space-newtext: str_w in micronumpy

2016-12-01 Thread cfbolz
Author: Carl Friedrich Bolz 
Branch: space-newtext
Changeset: r88792:00b54f1e2516
Date: 2016-12-01 15:05 +0100
http://bitbucket.org/pypy/pypy/changeset/00b54f1e2516/

Log:str_w in micronumpy

diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -403,7 +403,7 @@
 Supports the standard %s and %d formats, plus the following:
 
 %N - The result of w_arg.getname(space)
-%R - The result of space.str_w(space.repr(w_arg))
+%R - The result of space.text_w(space.repr(w_arg))
 %T - The result of space.type(w_arg).name
 
 """
diff --git a/pypy/module/micronumpy/boxes.py b/pypy/module/micronumpy/boxes.py
--- a/pypy/module/micronumpy/boxes.py
+++ b/pypy/module/micronumpy/boxes.py
@@ -556,7 +556,7 @@
 class W_VoidBox(W_FlexibleBox):
 def descr_getitem(self, space, w_item):
 if space.isinstance_w(w_item, space.w_basestring):
-item = space.str_w(w_item)
+item = space.text_w(w_item)
 elif space.isinstance_w(w_item, space.w_int):
 indx = space.int_w(w_item)
 try:
@@ -587,7 +587,7 @@
 
 def descr_setitem(self, space, w_item, w_value):
 if space.isinstance_w(w_item, space.w_basestring):
-item = space.str_w(w_item)
+item = space.text_w(w_item)
 elif space.isinstance_w(w_item, space.w_int):
 indx = space.int_w(w_item)
 try:
@@ -622,7 +622,7 @@
 class W_StringBox(W_CharacterBox):
 def descr__new__string_box(space, w_subtype, w_arg):
 from pypy.module.micronumpy.descriptor import new_string_dtype
-arg = space.str_w(space.str(w_arg))
+arg = space.text_w(space.str(w_arg))
 arr = VoidBoxStorage(len(arg), new_string_dtype(space, len(arg)))
 for i in range(len(arg)):
 arr.storage[i] = arg[i]
diff --git a/pypy/module/micronumpy/compile.py 
b/pypy/module/micronumpy/compile.py
--- a/pypy/module/micronumpy/compile.py
+++ b/pypy/module/micronumpy/compile.py
@@ -76,6 +76,7 @@
 w_tuple = W_TypeObject('tuple')
 w_slice = W_TypeObject("slice")
 w_str = W_TypeObject("str")
+w_bytes = w_str
 w_unicode = W_TypeObject("unicode")
 w_complex = W_TypeObject("complex")
 w_dict = W_TypeObject("dict")
diff --git a/pypy/module/micronumpy/converters.py 
b/pypy/module/micronumpy/converters.py
--- a/pypy/module/micronumpy/converters.py
+++ b/pypy/module/micronumpy/converters.py
@@ -25,8 +25,8 @@
 def clipmode_converter(space, w_mode):
 if space.is_none(w_mode):
 return NPY.RAISE
-if space.isinstance_w(w_mode, space.w_str):
-mode = space.str_w(w_mode)
+if space.isinstance_w(w_mode, space.w_text):
+mode = space.text_w(w_mode)
 if mode.startswith('C') or mode.startswith('c'):
 return NPY.CLIP
 if mode.startswith('W') or mode.startswith('w'):
@@ -42,7 +42,7 @@
 
 def searchside_converter(space, w_obj):
 try:
-s = space.str_w(w_obj)
+s = space.text_w(w_obj)
 except OperationError:
 s = None
 if not s:
@@ -66,7 +66,7 @@
 else:
 return NPY.CORDER
 else:
-order = space.str_w(w_order)
+order = space.text_w(w_order)
 if order.startswith('C') or order.startswith('c'):
 return NPY.CORDER
 elif order.startswith('F') or order.startswith('f'):
diff --git a/pypy/module/micronumpy/ctors.py b/pypy/module/micronumpy/ctors.py
--- a/pypy/module/micronumpy/ctors.py
+++ b/pypy/module/micronumpy/ctors.py
@@ -20,11 +20,11 @@
 "argument 1 must be numpy.dtype, not %T", w_dtype)
 if w_dtype.elsize == 0:
 raise oefmt(space.w_TypeError, "Empty data-type")
-if not space.isinstance_w(w_state, space.w_str):
+if not space.isinstance_w(w_state, space.w_bytes): # py3 accepts unicode 
here too
 raise oefmt(space.w_TypeError, "initializing object must be a string")
 if space.len_w(w_state) != w_dtype.elsize:
 raise oefmt(space.w_ValueError, "initialization string is too small")
-state = rffi.str2charp(space.str_w(w_state))
+state = rffi.str2charp(space.text_w(w_state))
 box = w_dtype.itemtype.box_raw_data(state)
 lltype.free(state, flavor="raw")
 return box
@@ -212,7 +212,7 @@
 if not isinstance(w_object, W_NDimArray):
 w_array = try_array_method(space, w_object, w_dtype)
 if w_array is None:
-if (not space.isinstance_w(w_object, space.w_str) and 
+if (not space.isinstance_w(w_object, space.w_bytes) and 
 not space.isinstance_w(w_object, space.w_unicode) and
 not isinstance(w_object, W_GenericBox)):
 # use buffer interface
@@ -323,7 +323,7 @@
 return _find_shape_and_elems(space, w_iterable, is_rec_type)
 
 def is_scalar_like(space, w_obj, dtype):
-isstr = space.isinstance_w(w_obj, space.w_str)
+isstr = space.isi

[pypy-commit] pypy py3.5: Mark more tests based on gc.is_tracked() as impl detail

2016-12-01 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r88793:cd880034bb7c
Date: 2016-12-01 16:54 +0100
http://bitbucket.org/pypy/pypy/changeset/cd880034bb7c/

Log:Mark more tests based on gc.is_tracked() as impl detail

diff --git a/lib-python/3/test/test_finalization.py 
b/lib-python/3/test/test_finalization.py
--- a/lib-python/3/test/test_finalization.py
+++ b/lib-python/3/test/test_finalization.py
@@ -181,7 +181,8 @@
 def test_non_gc(self):
 with SimpleBase.test():
 s = NonGC()
-self.assertFalse(gc.is_tracked(s))
+if support.check_impl_detail():
+self.assertFalse(gc.is_tracked(s))
 ids = [id(s)]
 del s
 gc.collect()
@@ -194,7 +195,8 @@
 def test_non_gc_resurrect(self):
 with SimpleBase.test():
 s = NonGCResurrector()
-self.assertFalse(gc.is_tracked(s))
+if support.check_impl_detail():
+self.assertFalse(gc.is_tracked(s))
 ids = [id(s)]
 del s
 gc.collect()
diff --git a/lib-python/3/test/test_gc.py b/lib-python/3/test/test_gc.py
--- a/lib-python/3/test/test_gc.py
+++ b/lib-python/3/test/test_gc.py
@@ -526,6 +526,7 @@
 
 self.assertEqual(gc.get_referents(1, 'a', 4j), [])
 
+@cpython_only
 def test_is_tracked(self):
 # Atomic built-in types are not tracked, user-defined objects and
 # mutable containers are.
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Tweak gc.collect() when gc.disable() was called, see comment

2016-12-01 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r88794:2aa7dea5ad0f
Date: 2016-12-01 17:21 +0100
http://bitbucket.org/pypy/pypy/changeset/2aa7dea5ad0f/

Log:Tweak gc.collect() when gc.disable() was called, see comment

diff --git a/pypy/module/gc/interp_gc.py b/pypy/module/gc/interp_gc.py
--- a/pypy/module/gc/interp_gc.py
+++ b/pypy/module/gc/interp_gc.py
@@ -14,7 +14,19 @@
 cache.clear()
 cache = space.fromcache(MapAttrCache)
 cache.clear()
+
 rgc.collect()
+
+# if we are running in gc.disable() mode but gc.collect() is called,
+# we should still call the finalizers now.  We do this as an attempt
+# to get closer to CPython's behavior: in Py3.5 some tests
+# specifically rely on that.  This is similar to how, in CPython, an
+# explicit gc.collect() will invoke finalizers from cycles and fully
+# ignore the gc.disable() mode.
+if not space.user_del_action.enabled_at_app_level:
+enable_finalizers(space)
+disable_finalizers(space)
+
 return space.wrap(0)
 
 def enable(space):
___
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-12-01 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r88795:eb1bdeb6f204
Date: 2016-12-01 17:22 +0100
http://bitbucket.org/pypy/pypy/changeset/eb1bdeb6f204/

Log:hg merge default

diff --git a/pypy/module/gc/interp_gc.py b/pypy/module/gc/interp_gc.py
--- a/pypy/module/gc/interp_gc.py
+++ b/pypy/module/gc/interp_gc.py
@@ -14,7 +14,19 @@
 cache.clear()
 cache = space.fromcache(MapAttrCache)
 cache.clear()
+
 rgc.collect()
+
+# if we are running in gc.disable() mode but gc.collect() is called,
+# we should still call the finalizers now.  We do this as an attempt
+# to get closer to CPython's behavior: in Py3.5 some tests
+# specifically rely on that.  This is similar to how, in CPython, an
+# explicit gc.collect() will invoke finalizers from cycles and fully
+# ignore the gc.disable() mode.
+if not space.user_del_action.enabled_at_app_level:
+enable_finalizers(space)
+disable_finalizers(space)
+
 return space.wrap(0)
 
 def enable(space):
diff --git a/pypy/module/micronumpy/test/test_zjit.py 
b/pypy/module/micronumpy/test/test_zjit.py
--- a/pypy/module/micronumpy/test/test_zjit.py
+++ b/pypy/module/micronumpy/test/test_zjit.py
@@ -518,12 +518,10 @@
 def test_prod(self):
 result = self.run("prod")
 assert int(result) == 576
-self.check_vectorized(1, 1)
 
 def test_prod_zero(self):
 result = self.run("prod_zero")
 assert int(result) == 0
-self.check_vectorized(1, 1)
 
 
 def define_max():
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
@@ -77,7 +77,6 @@
 arith_comb = [
 ('sum','int', 1742, 1742, 1),
 ('sum','float', 2581, 2581, 1),
-('prod','float', 1, 3178, 1),
 ('prod','int', 1, 3178, 1),
 ('any','int', 1, 2239, 1),
 ('any','int', 0, 4912, 0),
diff --git a/rpython/jit/backend/llgraph/runner.py 
b/rpython/jit/backend/llgraph/runner.py
--- a/rpython/jit/backend/llgraph/runner.py
+++ b/rpython/jit/backend/llgraph/runner.py
@@ -1128,7 +1128,7 @@
 value = sum(value)
 elif info.accum_operation == '*':
 def prod(acc, x): return acc * x
-value = reduce(prod, value, 1)
+value = reduce(prod, value, 1.0)
 else:
 raise NotImplementedError("accum operator in fail guard")
 values[i] = value
diff --git a/rpython/jit/metainterp/optimizeopt/schedule.py 
b/rpython/jit/metainterp/optimizeopt/schedule.py
--- a/rpython/jit/metainterp/optimizeopt/schedule.py
+++ b/rpython/jit/metainterp/optimizeopt/schedule.py
@@ -980,7 +980,6 @@
 class AccumPack(Pack):
 SUPPORTED = { rop.FLOAT_ADD: '+',
   rop.INT_ADD:   '+',
-  rop.FLOAT_MUL: '*',
 }
 
 def __init__(self, nodes, operator, position):
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
@@ -847,6 +847,10 @@
  vecop, count)
 oplist.append(vecop)
 elif pack.reduce_init() == 1:
+# PRECISION loss, because the numbers are accumulated 
(associative, commutative properties must hold)
+# you can end up a small number and a huge number that is 
finally multiplied. giving an
+# inprecision result, thus this is disabled now
+raise NotImplementedError
 # multiply is only supported by floats
 vecop = OpHelpers.create_vec_expand(ConstFloat(1.0), bytesize,
 signed, count)
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
@@ -414,7 +414,9 @@
  lambda a,b: 
lltype.intmask(lltype.intmask(a)+lltype.intmask(b)), lltype.Signed)
 small_floats = st.floats(min_value=-100, max_value=100, allow_nan=False, 
allow_infinity=False)
 test_vec_float_sum = vec_reduce(small_floats, lambda a,b: a+b, rffi.DOUBLE)
-test_vec_float_prod = vec_reduce(small_floats, lambda a,b: a*b, 
rffi.DOUBLE)
+# PRECISION loss, because the numbers are accumulated (associative, 
commutative properties must hold)
+# you can end up a small number and a huge number that is finally 
multiplied losing precision
+# test_vec_float_prod = vec_reduce(small_floats, 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 py3.5: Allow cffi compilation and extension-finding to work even if cpyext is disabled

2016-12-01 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r88796:bdbd6c72e191
Date: 2016-12-01 16:48 +
http://bitbucket.org/pypy/pypy/changeset/bdbd6c72e191/

Log:Allow cffi compilation and extension-finding to work even if cpyext
is disabled

diff --git a/pypy/module/imp/interp_imp.py b/pypy/module/imp/interp_imp.py
--- a/pypy/module/imp/interp_imp.py
+++ b/pypy/module/imp/interp_imp.py
@@ -9,7 +9,7 @@
 
 def extension_suffixes(space):
 suffixes_w = []
-if space.config.objspace.usemodules.cpyext:
+if 1:   #if space.config.objspace.usemodules.cpyext:
 suffixes_w.append(space.wrap(importing.get_so_extension(space)))
 return space.newlist(suffixes_w)
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: deduplicate test defined twice, change check

2016-12-01 Thread plan_rich
Author: Richard Plangger 
Branch: 
Changeset: r88799:d6e2601a07f1
Date: 2016-12-01 17:39 +0100
http://bitbucket.org/pypy/pypy/changeset/d6e2601a07f1/

Log:deduplicate test defined twice, change check

diff --git a/pypy/module/micronumpy/test/test_zjit.py 
b/pypy/module/micronumpy/test/test_zjit.py
--- a/pypy/module/micronumpy/test/test_zjit.py
+++ b/pypy/module/micronumpy/test/test_zjit.py
@@ -374,17 +374,7 @@
 def test_sum(self):
 result = self.run("sum")
 assert result == sum(range(30))
-self.check_vectorized(1, 1)
-
-def define_sum():
-return """
-a = |30|
-sum(a)
-"""
-def test_sum(self):
-result = self.run("sum")
-assert result == sum(range(30))
-self.check_vectorized(1, 1)
+self.check_vectorized(1, 0)
 
 def define_sum_int():
 return """
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5-ssl: failing test for memoryview slicing case

2016-12-01 Thread plan_rich
Author: Richard Plangger 
Branch: py3.5-ssl
Changeset: r88797:1d009c35c573
Date: 2016-12-01 15:33 +0100
http://bitbucket.org/pypy/pypy/changeset/1d009c35c573/

Log:failing test for memoryview slicing case

diff --git a/lib-python/3/http/client.py b/lib-python/3/http/client.py
--- a/lib-python/3/http/client.py
+++ b/lib-python/3/http/client.py
@@ -541,6 +541,7 @@
 try:
 while True:
 chunk_left = self._get_chunk_left()
+print("chunk_left", chunk_left)
 if chunk_left is None:
 break
 value.append(self._safe_read(chunk_left))
@@ -590,6 +591,7 @@
 s = []
 while amt > 0:
 chunk = self.fp.read(min(amt, MAXAMOUNT))
+print("read chunk %d %d", len(chunk), min(amt, MAXAMOUNT))
 if not chunk:
 raise IncompleteRead(b''.join(s), amt)
 s.append(chunk)
diff --git a/lib-python/3/socket.py b/lib-python/3/socket.py
--- a/lib-python/3/socket.py
+++ b/lib-python/3/socket.py
@@ -572,6 +572,7 @@
 raise OSError("cannot read from timed out object")
 while True:
 try:
+import pdb; pdb.set_trace()
 return self._sock.recv_into(b)
 except timeout:
 self._timeout_occurred = True
diff --git a/pypy/objspace/std/test/test_memoryobject.py 
b/pypy/objspace/std/test/test_memoryobject.py
--- a/pypy/objspace/std/test/test_memoryobject.py
+++ b/pypy/objspace/std/test/test_memoryobject.py
@@ -409,3 +409,10 @@
 v = view.cast('h', shape=(3,2))
 assert v.tolist() == [[2,3],[4,5],[6,7]]
 raises(TypeError, "view.cast('h', shape=(3,3))")
+
+def test_reversed(self):
+bytes = b"\x01\x00\x02\x00\x03\x00"
+view = memoryview(bytes)
+revlist = list(reversed(view.tolist()))
+assert list(reversed(view)) == revlist
+assert list(reversed(view)) == view[::-1].tolist()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: change tests to match the new behaviour

2016-12-01 Thread plan_rich
Author: Richard Plangger 
Branch: 
Changeset: r88800:50e5ff8f14e9
Date: 2016-12-01 17:45 +0100
http://bitbucket.org/pypy/pypy/changeset/50e5ff8f14e9/

Log:change tests to match the new behaviour

diff --git a/pypy/module/micronumpy/test/test_zjit.py 
b/pypy/module/micronumpy/test/test_zjit.py
--- a/pypy/module/micronumpy/test/test_zjit.py
+++ b/pypy/module/micronumpy/test/test_zjit.py
@@ -398,7 +398,7 @@
 def test_sum_multi(self):
 result = self.run("sum_multi")
 assert result == sum(range(30)) + sum(range(60))
-self.check_vectorized(1, 1)
+self.check_vectorized(1, 0)
 
 def define_sum_float_to_int16():
 return """
@@ -480,7 +480,7 @@
 assert retval == sum(range(1,11))
 # check that we got only one loop
 assert len(get_stats().loops) == 1
-self.check_vectorized(2, 1)
+self.check_vectorized(2, 0)
 
 def test_reduce_axis_compile_only_once(self):
 self.compile_graph()
@@ -491,7 +491,7 @@
 retval = self.interp.eval_graph(self.graph, [i])
 # check that we got only one loop
 assert len(get_stats().loops) == 1
-self.check_vectorized(3, 1)
+self.check_vectorized(3, 0)
 
 def define_prod():
 return """
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: disable sum accumulation for floats as well (pointed out by armin, thanks)

2016-12-01 Thread plan_rich
Author: Richard Plangger 
Branch: 
Changeset: r88798:5055d03e5f24
Date: 2016-12-01 17:36 +0100
http://bitbucket.org/pypy/pypy/changeset/5055d03e5f24/

Log:disable sum accumulation for floats as well (pointed out by armin,
thanks)

diff --git a/rpython/jit/metainterp/optimizeopt/schedule.py 
b/rpython/jit/metainterp/optimizeopt/schedule.py
--- a/rpython/jit/metainterp/optimizeopt/schedule.py
+++ b/rpython/jit/metainterp/optimizeopt/schedule.py
@@ -978,9 +978,7 @@
self.right is other.right
 
 class AccumPack(Pack):
-SUPPORTED = { rop.FLOAT_ADD: '+',
-  rop.INT_ADD:   '+',
-}
+SUPPORTED = { rop.INT_ADD: '+', }
 
 def __init__(self, nodes, operator, position):
 Pack.__init__(self, nodes)
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_costmodel.py 
b/rpython/jit/metainterp/optimizeopt/test/test_costmodel.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_costmodel.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_costmodel.py
@@ -197,7 +197,7 @@
 f13 = float_add(f12, f11)
 """)
 savings = self.savings(loop1)
-assert savings == 2
+assert savings == -2
 
 @py.test.mark.parametrize("bytes,s", [(4,0),(8,0)])
 def test_sum_float_to_int(self, bytes, s):
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_vecopt.py 
b/rpython/jit/metainterp/optimizeopt/test/test_vecopt.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_vecopt.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_vecopt.py
@@ -1162,32 +1162,32 @@
 vopt = self.vectorize(loop,1)
 self.assert_equal(loop, self.parse_loop(opt))
 
-def test_accumulate_basic(self):
-trace = """
-[p0, i0, f0]
-f1 = raw_load_f(p0, i0, descr=floatarraydescr)
-f2 = float_add(f0, f1)
-i1 = int_add(i0, 8)
-i2 = int_lt(i1, 100)
-guard_true(i2) [p0, i0, f2]
-jump(p0, i1, f2)
-"""
-trace_opt = """
-[p0, i0, f0]
-v6[0xf64] = vec_f()
-v7[2xf64] = vec_float_xor(v6[0xf64], v6[0xf64])
-v2[2xf64] = vec_pack_f(v7[2xf64], f0, 0, 1)
-label(p0, i0, v2[2xf64])
-i1 = int_add(i0, 16)
-i2 = int_lt(i1, 100)
-guard_true(i2) [p0, i0, v2[2xf64]]
-v1[2xf64] = vec_load_f(p0, i0, 1, 0, descr=floatarraydescr)
-v3[2xf64] = vec_float_add(v2[2xf64], v1[2xf64])
-jump(p0, i1, v3[2xf64])
-"""
-loop = self.parse_loop(trace)
-opt = self.vectorize(loop)
-self.assert_equal(loop, self.parse_loop(trace_opt))
+#def test_accumulate_basic(self):
+#trace = """
+#[p0, i0, f0]
+#f1 = raw_load_f(p0, i0, descr=floatarraydescr)
+#f2 = float_add(f0, f1)
+#i1 = int_add(i0, 8)
+#i2 = int_lt(i1, 100)
+#guard_true(i2) [p0, i0, f2]
+#jump(p0, i1, f2)
+#"""
+#trace_opt = """
+#[p0, i0, f0]
+#v6[0xf64] = vec_f()
+#v7[2xf64] = vec_float_xor(v6[0xf64], v6[0xf64])
+#v2[2xf64] = vec_pack_f(v7[2xf64], f0, 0, 1)
+#label(p0, i0, v2[2xf64])
+#i1 = int_add(i0, 16)
+#i2 = int_lt(i1, 100)
+#guard_true(i2) [p0, i0, v2[2xf64]]
+#v1[2xf64] = vec_load_f(p0, i0, 1, 0, descr=floatarraydescr)
+#v3[2xf64] = vec_float_add(v2[2xf64], v1[2xf64])
+#jump(p0, i1, v3[2xf64])
+#"""
+#loop = self.parse_loop(trace)
+#opt = self.vectorize(loop)
+#self.assert_equal(loop, self.parse_loop(trace_opt))
 
 def test_element_f45_in_guard_failargs(self):
 trace = self.parse_loop("""
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
@@ -842,7 +842,8 @@
 oplist.append(vecop)
 opnum = rop.VEC_INT_XOR
 if datatype == FLOAT:
-opnum = rop.VEC_FLOAT_XOR
+# see PRECISION loss below
+raise NotImplementedError
 vecop = VecOperation(opnum, [vecop, vecop],
  vecop, count)
 oplist.append(vecop)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: make sure that fromfile does not emit a warning

2016-12-01 Thread cfbolz
Author: Carl Friedrich Bolz 
Branch: py3.5
Changeset: r88801:b93629909a8f
Date: 2016-12-01 18:02 +0100
http://bitbucket.org/pypy/pypy/changeset/b93629909a8f/

Log:make sure that fromfile does not emit a warning

diff --git a/pypy/module/_rawffi/array.py b/pypy/module/_rawffi/array.py
--- a/pypy/module/_rawffi/array.py
+++ b/pypy/module/_rawffi/array.py
@@ -185,7 +185,7 @@
 
 def setslice(self, space, w_slice, w_value):
 start, stop = self.decodeslice(space, w_slice)
-value = space.str_w(w_value)
+value = space.bytes_w(w_value)
 if start + len(value) != stop:
 raise oefmt(space.w_ValueError, "cannot resize array")
 ll_buffer = self.ll_buffer
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
@@ -308,7 +308,7 @@
 """ fromfile(f, n)
 
 Read n objects from the file object f and append them to the end of the
-array.  Also called as read.
+array.
 """
 try:
 size = ovfcheck(self.itemsize * n)
@@ -323,7 +323,7 @@
 item = item[0:elems]
 self._frombytes(space, item)
 raise oefmt(space.w_EOFError, "not enough items in file")
-self.descr_fromstring(space, w_item)
+self._frombytes(space, item)
 
 def descr_tofile(self, space, w_f):
 """ tofile(f)
diff --git a/pypy/module/array/test/test_array.py 
b/pypy/module/array/test/test_array.py
--- a/pypy/module/array/test/test_array.py
+++ b/pypy/module/array/test/test_array.py
@@ -227,6 +227,19 @@
 raises(EOFError, a.fromfile, myfile(b'\x01', 2 + i), 2)
 assert len(a) == 1 and a[0] == 257
 
+def test_fromfile_no_warning(self):
+import warnings
+# check that fromfile defers to frombytes, not fromstring
+class FakeF(object):
+def read(self, n):
+return b"a" * n
+a = self.array('b')
+with warnings.catch_warnings(record=True) as w:
+# Cause all warnings to always be triggered.
+warnings.simplefilter("always")
+a.fromfile(FakeF(), 4)
+assert len(w) == 0
+
 def test_fromlist(self):
 a = self.array('b')
 raises(OverflowError, a.fromlist, [1, 2, 400])
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: kill duplicate function (there is another one below)

2016-12-01 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r88802:9bed0c6cb3d1
Date: 2016-12-01 17:56 +0100
http://bitbucket.org/pypy/pypy/changeset/9bed0c6cb3d1/

Log:kill duplicate function (there is another one below)

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
@@ -83,10 +83,6 @@
 raise OperationError(get_error(space), space.wrap(e.msg))
 return space.newtuple(fmtiter.result_w[:])
 
-def clearcache(space):
-"Clear the internal cache."
-# No cache in this implementation
-
 
 @unwrap_spec(format=str)
 def unpack(space, format, w_str):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy.org extradoc: update the values

2016-12-01 Thread arigo
Author: Armin Rigo 
Branch: extradoc
Changeset: r826:43cab4e5c9a3
Date: 2016-12-01 22:37 +0100
http://bitbucket.org/pypy/pypy.org/changeset/43cab4e5c9a3/

Log:update the values

diff --git a/don1.html b/don1.html
--- a/don1.html
+++ b/don1.html
@@ -15,7 +15,7 @@
 
 

-   $66339 of $105000 (63.2%)
+   $66348 of $105000 (63.2%)


 
@@ -23,7 +23,7 @@
   
   This donation goes towards supporting Python 3 in 
PyPy.
   Current status:
-we have $2192 left
+we have $2201 left
   in the account. Read proposal
   
   
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: rename (for test_structseq)

2016-12-01 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r88805:be0cbcb1d37c
Date: 2016-12-01 18:22 +0100
http://bitbucket.org/pypy/pypy/changeset/be0cbcb1d37c/

Log:rename (for test_structseq)

diff --git a/pypy/module/posix/app_posix.py b/pypy/module/posix/app_posix.py
--- a/pypy/module/posix/app_posix.py
+++ b/pypy/module/posix/app_posix.py
@@ -19,7 +19,7 @@
 
 class stat_result(metaclass=structseqtype):
 
-name = osname + ".stat_result"
+name = "os.stat_result"
 
 st_mode  = structseqfield(0, "protection bits")
 st_ino   = structseqfield(1, "inode")
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: small fixes in struct.iter_unpack()

2016-12-01 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r88804:cca0cbd9a9d6
Date: 2016-12-01 18:19 +0100
http://bitbucket.org/pypy/pypy/changeset/cca0cbd9a9d6/

Log:small fixes in struct.iter_unpack()

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
@@ -105,7 +105,12 @@
 
 
 class W_UnpackIter(W_Root):
-def __init__(self, w_struct, buf):
+def __init__(self, space, w_struct, w_buffer):
+buf = space.buffer_w(w_buffer, space.BUF_SIMPLE)
+if buf.getlength() % w_struct.size != 0:
+raise oefmt(get_error(space),
+"iterative unpacking requires a bytes length multiple of %d",
+w_struct.size)
 self.w_struct = w_struct
 self.buf = buf
 self.index = 0
@@ -159,8 +164,7 @@
 return unpack_from(space, jit.promote_string(self.format), w_buffer, 
offset)
 
 def descr_iter_unpack(self, space, w_buffer):
-buf = space.buffer_w(w_buffer, space.BUF_SIMPLE)
-return W_UnpackIter(self, buf)
+return W_UnpackIter(space, self, w_buffer)
 
 W_Struct.typedef = TypeDef("Struct",
 __new__=interp2app(W_Struct.descr__new__.im_func),
@@ -174,15 +178,7 @@
 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__=interp2app(W_UnpackIter.descr_length_hint)
@@ -191,8 +187,7 @@
 @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)
+return W_UnpackIter(space, w_struct, w_buffer)
 
 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
@@ -403,6 +403,25 @@
 assert list(it) == [(0, 0), (0, 0)]
 it = self.struct.iter_unpack('ii', b)
 assert list(it) == [(0, 0), (0, 0)]
+#
+it = s.iter_unpack(b)
+next(it)
+assert it.__length_hint__() == 1
+next(it)
+assert it.__length_hint__() == 0
+assert list(it) == []
+assert it.__length_hint__() == 0
+
+def test_iter_unpack_bad_length(self):
+struct = self.struct
+s = struct.Struct('!i')
+lst = list(s.iter_unpack(b'1234'))
+assert lst == [(0x31323334,)]
+lst = list(s.iter_unpack(b''))
+assert lst == []
+raises(struct.error, s.iter_unpack, b'12345')
+raises(struct.error, s.iter_unpack, b'123')
+raises(struct.error, struct.iter_unpack, 'h', b'12345')
 
 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: merge heads

2016-12-01 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r88807:4e784ab053d6
Date: 2016-12-01 22:36 +0100
http://bitbucket.org/pypy/pypy/changeset/4e784ab053d6/

Log:merge heads

diff --git a/pypy/module/_rawffi/array.py b/pypy/module/_rawffi/array.py
--- a/pypy/module/_rawffi/array.py
+++ b/pypy/module/_rawffi/array.py
@@ -185,7 +185,7 @@
 
 def setslice(self, space, w_slice, w_value):
 start, stop = self.decodeslice(space, w_slice)
-value = space.str_w(w_value)
+value = space.bytes_w(w_value)
 if start + len(value) != stop:
 raise oefmt(space.w_ValueError, "cannot resize array")
 ll_buffer = self.ll_buffer
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
@@ -308,7 +308,7 @@
 """ fromfile(f, n)
 
 Read n objects from the file object f and append them to the end of the
-array.  Also called as read.
+array.
 """
 try:
 size = ovfcheck(self.itemsize * n)
@@ -323,7 +323,7 @@
 item = item[0:elems]
 self._frombytes(space, item)
 raise oefmt(space.w_EOFError, "not enough items in file")
-self.descr_fromstring(space, w_item)
+self._frombytes(space, item)
 
 def descr_tofile(self, space, w_f):
 """ tofile(f)
diff --git a/pypy/module/array/test/test_array.py 
b/pypy/module/array/test/test_array.py
--- a/pypy/module/array/test/test_array.py
+++ b/pypy/module/array/test/test_array.py
@@ -227,6 +227,19 @@
 raises(EOFError, a.fromfile, myfile(b'\x01', 2 + i), 2)
 assert len(a) == 1 and a[0] == 257
 
+def test_fromfile_no_warning(self):
+import warnings
+# check that fromfile defers to frombytes, not fromstring
+class FakeF(object):
+def read(self, n):
+return b"a" * n
+a = self.array('b')
+with warnings.catch_warnings(record=True) as w:
+# Cause all warnings to always be triggered.
+warnings.simplefilter("always")
+a.fromfile(FakeF(), 4)
+assert len(w) == 0
+
 def test_fromlist(self):
 a = self.array('b')
 raises(OverflowError, a.fromlist, [1, 2, 400])
diff --git a/pypy/module/imp/interp_imp.py b/pypy/module/imp/interp_imp.py
--- a/pypy/module/imp/interp_imp.py
+++ b/pypy/module/imp/interp_imp.py
@@ -9,7 +9,7 @@
 
 def extension_suffixes(space):
 suffixes_w = []
-if space.config.objspace.usemodules.cpyext:
+if 1:   #if space.config.objspace.usemodules.cpyext:
 suffixes_w.append(space.wrap(importing.get_so_extension(space)))
 return space.newlist(suffixes_w)
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: fix this test: it has two 'mistakes' per line and happens to test that CPython reports a specific one of them before the other, whereas PyPy reports them in opposite order so

2016-12-01 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r88803:a59665c98dd5
Date: 2016-12-01 17:59 +0100
http://bitbucket.org/pypy/pypy/changeset/a59665c98dd5/

Log:fix this test: it has two 'mistakes' per line and happens to test
that CPython reports a specific one of them before the other,
whereas PyPy reports them in opposite order so far. This was
probably not intended.

diff --git a/lib-python/3/test/test_struct.py b/lib-python/3/test/test_struct.py
--- a/lib-python/3/test/test_struct.py
+++ b/lib-python/3/test/test_struct.py
@@ -547,19 +547,19 @@
 self.assertRaises(struct.error, struct.unpack_from, '12345', store, 0)
 
 # Format lists with trailing count spec should result in an error
-self.assertRaises(struct.error, struct.pack, 'c12345', 'x')
-self.assertRaises(struct.error, struct.unpack, 'c12345', 'x')
+self.assertRaises(struct.error, struct.pack, 'c12345', b'x')
+self.assertRaises(struct.error, struct.unpack, 'c12345', b'x')
 self.assertRaises(struct.error, struct.pack_into, 'c12345', store, 0,
-   'x')
+   b'x')
 self.assertRaises(struct.error, struct.unpack_from, 'c12345', store,
0)
 
 # Mixed format tests
-self.assertRaises(struct.error, struct.pack, '14s42', 'spam and eggs')
+self.assertRaises(struct.error, struct.pack, '14s42', b'spam and eggs')
 self.assertRaises(struct.error, struct.unpack, '14s42',
-  'spam and eggs')
+  b'spam and eggs')
 self.assertRaises(struct.error, struct.pack_into, '14s42', store, 0,
-  'spam and eggs')
+  b'spam and eggs')
 self.assertRaises(struct.error, struct.unpack_from, '14s42', store, 0)
 
 def test_Struct_reinitialization(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: detail changed in AST between 3.3 and 3.5

2016-12-01 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r88806:22496395faa8
Date: 2016-12-01 18:26 +0100
http://bitbucket.org/pypy/pypy/changeset/22496395faa8/

Log:detail changed in AST between 3.3 and 3.5

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
@@ -484,9 +484,6 @@
 
 def visit_Global(self, glob):
 for name in glob.names:
-if isinstance(self.scope, ClassScope) and name == '__class__':
-raise SyntaxError("cannot make __class__ global",
-  glob.lineno, glob.col_offset)
 old_role = self.scope.lookup_role(name)
 if old_role & (SYM_USED | SYM_ASSIGNED):
 if old_role & SYM_ASSIGNED:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit