[pypy-commit] pypy py3k: hg merge default

rlamy pypy.commits at gmail.com
Sat Jul 30 09:17:53 EDT 2016


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3k
Changeset: r85926:1df40eed7b9c
Date: 2016-07-30 14:17 +0100
http://bitbucket.org/pypy/pypy/changeset/1df40eed7b9c/

Log:	hg merge default

diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -101,3 +101,7 @@
 .. branch: jitlog-32bit
 
 Resolve issues to use the new logging facility on a 32bit system
+
+.. branch: ep2016sprint
+
+Trying harder to make hash(-1) return -2, like it does on CPython
diff --git a/pypy/module/cpyext/number.py b/pypy/module/cpyext/number.py
--- a/pypy/module/cpyext/number.py
+++ b/pypy/module/cpyext/number.py
@@ -19,16 +19,12 @@
 def PyNumber_Check(space, w_obj):
     """Returns 1 if the object o provides numeric protocols, and false otherwise.
     This function always succeeds."""
-    try:
-        space.float_w(w_obj)
+    # According to CPython, this means: w_obj is not None, and
+    # the type of w_obj has got a method __int__ or __float__.
+    if w_obj is None:
+        return 0
+    if space.lookup(w_obj, '__int__') or space.lookup(w_obj, '__float__'):
         return 1
-    except OperationError:
-        pass
-    try:
-        space.int_w(w_obj)
-        return 1
-    except OperationError:
-        pass
     return 0
 
 @cpython_api([PyObject, PyObject], Py_ssize_t, error=-1)
diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py
--- a/pypy/module/cpyext/slotdefs.py
+++ b/pypy/module/cpyext/slotdefs.py
@@ -381,6 +381,7 @@
                           ('tp_as_number.c_nb_invert', '__invert__'),
                           ('tp_as_number.c_nb_index', '__index__'),
                           ('tp_as_number.c_nb_hex', '__hex__'),
+                          ('tp_as_number.c_nb_oct', '__oct__'),
                           ('tp_str', '__str__'),
                           ('tp_repr', '__repr__'),
                           ('tp_iter', '__iter__'),
diff --git a/pypy/module/cpyext/test/test_longobject.py b/pypy/module/cpyext/test/test_longobject.py
--- a/pypy/module/cpyext/test/test_longobject.py
+++ b/pypy/module/cpyext/test/test_longobject.py
@@ -264,8 +264,19 @@
                     ret = PyLong_FromLong(-1);
                 Py_DECREF(obj);
                 return ret;
+             """),
+            ("has_oct", "METH_NOARGS",
+             """
+                PyObject *ret, *obj = PyLong_FromLong(42);
+                if (obj->ob_type->tp_as_number->nb_oct)
+                    ret = obj->ob_type->tp_as_number->nb_oct(obj);
+                else
+                    ret = PyLong_FromLong(-1);
+                Py_DECREF(obj);
+                return ret;
              """)])
         assert module.has_sub() == 0
         assert module.has_pow() == 0
         assert module.has_hex() == '0x2aL'
+        assert module.has_oct() == '052L'
                 
diff --git a/pypy/module/cpyext/test/test_number.py b/pypy/module/cpyext/test/test_number.py
--- a/pypy/module/cpyext/test/test_number.py
+++ b/pypy/module/cpyext/test/test_number.py
@@ -12,7 +12,7 @@
         assert api.PyNumber_Check(space.wraplong(-12L))
         assert api.PyNumber_Check(space.wrap(12.1))
         assert not api.PyNumber_Check(space.wrap('12'))
-        assert not api.PyNumber_Check(space.wrap(1+3j))
+        assert api.PyNumber_Check(space.wrap(1+3j))
 
     def test_number_long(self, space, api):
         w_l = api.PyNumber_Long(space.wrap(123))
diff --git a/pypy/module/thread/test/test_lock.py b/pypy/module/thread/test/test_lock.py
--- a/pypy/module/thread/test/test_lock.py
+++ b/pypy/module/thread/test/test_lock.py
@@ -75,7 +75,7 @@
             else:
                 got_ovf = False
                 lock.release()
-            assert (i, got_ovf) == (i, int(timeout * 1e6 + 0.999) > maxint)
+            assert (i, got_ovf) == (i, int(timeout * 1e6) > maxint)
 
     @py.test.mark.xfail(machine()=='s390x', reason='may fail under heavy load')
     def test_ping_pong(self):
diff --git a/pypy/objspace/std/test/test_stdobjspace.py b/pypy/objspace/std/test/test_stdobjspace.py
--- a/pypy/objspace/std/test/test_stdobjspace.py
+++ b/pypy/objspace/std/test/test_stdobjspace.py
@@ -66,19 +66,20 @@
 
     def test_wrap_various_unsigned_types(self):
         import sys
+        from rpython.rlib.rarithmetic import r_uint
         from rpython.rtyper.lltypesystem import lltype, rffi
         space = self.space
         value = sys.maxint * 2
-        x = rffi.cast(lltype.Unsigned, value)
+        x = r_uint(value)
         assert space.eq_w(space.wrap(value), space.wrap(x))
-        x = rffi.cast(rffi.UINTPTR_T, value)
+        x = rffi.cast(rffi.UINTPTR_T, r_uint(value))
         assert x > 0
         assert space.eq_w(space.wrap(value), space.wrap(x))
         value = 60000
-        x = rffi.cast(rffi.USHORT, value)
+        x = rffi.cast(rffi.USHORT, r_uint(value))
         assert space.eq_w(space.wrap(value), space.wrap(x))
         value = 200
-        x = rffi.cast(rffi.UCHAR, value)
+        x = rffi.cast(rffi.UCHAR, r_uint(value))
         assert space.eq_w(space.wrap(value), space.wrap(x))
 
     def test_wrap_string(self):
diff --git a/rpython/jit/backend/x86/test/test_regloc.py b/rpython/jit/backend/x86/test/test_regloc.py
--- a/rpython/jit/backend/x86/test/test_regloc.py
+++ b/rpython/jit/backend/x86/test/test_regloc.py
@@ -147,7 +147,7 @@
             py.test.skip()
 
     def test_reuse_scratch_register(self):
-        base_addr = 0xFEDCBA9876543210
+        base_addr = intmask(0xFEDCBA9876543210)
         cb = LocationCodeBuilder64()
         cb.begin_reuse_scratch_register()
         cb.MOV(ecx, heap(base_addr))
@@ -167,7 +167,7 @@
     # ------------------------------------------------------------
 
     def test_64bit_address_1(self):
-        base_addr = 0xFEDCBA9876543210
+        base_addr = intmask(0xFEDCBA9876543210)
         cb = LocationCodeBuilder64()
         cb.CMP(ecx, AddressLoc(ImmedLoc(0), ImmedLoc(0), 0, base_addr))
         # this case is a CMP_rj
@@ -181,7 +181,7 @@
         assert cb.getvalue() == expected_instructions
 
     def test_64bit_address_2(self):
-        base_addr = 0xFEDCBA9876543210
+        base_addr = intmask(0xFEDCBA9876543210)
         cb = LocationCodeBuilder64()
         cb.MOV(ecx, AddressLoc(ImmedLoc(0), edx, 3, base_addr))
         # this case is a CMP_ra
@@ -195,7 +195,7 @@
         assert cb.getvalue() == expected_instructions
 
     def test_64bit_address_3(self):
-        base_addr = 0xFEDCBA9876543210
+        base_addr = intmask(0xFEDCBA9876543210)
         cb = LocationCodeBuilder64()
         cb.MOV(ecx, AddressLoc(edx, ImmedLoc(0), 0, base_addr))
         # this case is a CMP_rm
@@ -211,7 +211,7 @@
         assert cb.getvalue() == expected_instructions
 
     def test_64bit_address_4(self):
-        base_addr = 0xFEDCBA9876543210
+        base_addr = intmask(0xFEDCBA9876543210)
         cb = LocationCodeBuilder64()
         cb.begin_reuse_scratch_register()
         assert cb._reuse_scratch_register is True
@@ -234,7 +234,7 @@
     # ------------------------------------------------------------
 
     def test_MOV_64bit_constant_into_r11(self):
-        base_constant = 0xFEDCBA9876543210
+        base_constant = intmask(0xFEDCBA9876543210)
         cb = LocationCodeBuilder64()
         cb.MOV(r11, imm(base_constant))
 
@@ -245,7 +245,7 @@
         assert cb.getvalue() == expected_instructions
 
     def test_MOV_64bit_constant_into_rax(self):
-        base_constant = 0xFEDCBA9876543210
+        base_constant = intmask(0xFEDCBA9876543210)
         cb = LocationCodeBuilder64()
         cb.MOV(eax, imm(base_constant))
 
@@ -256,7 +256,7 @@
         assert cb.getvalue() == expected_instructions
 
     def test_MOV_64bit_address_into_r11(self):
-        base_addr = 0xFEDCBA9876543210
+        base_addr = intmask(0xFEDCBA9876543210)
         cb = LocationCodeBuilder64()
         cb.MOV(r11, heap(base_addr))
 
@@ -270,7 +270,7 @@
 
     def test_MOV_immed32_into_64bit_address_1(self):
         immed = -0x01234567
-        base_addr = 0xFEDCBA9876543210
+        base_addr = intmask(0xFEDCBA9876543210)
         cb = LocationCodeBuilder64()
         cb.MOV(AddressLoc(ImmedLoc(0), ImmedLoc(0), 0, base_addr),
                ImmedLoc(immed))
@@ -286,7 +286,7 @@
 
     def test_MOV_immed32_into_64bit_address_2(self):
         immed = -0x01234567
-        base_addr = 0xFEDCBA9876543210
+        base_addr = intmask(0xFEDCBA9876543210)
         cb = LocationCodeBuilder64()
         cb.MOV(AddressLoc(ImmedLoc(0), edx, 3, base_addr),
                ImmedLoc(immed))
@@ -302,7 +302,7 @@
 
     def test_MOV_immed32_into_64bit_address_3(self):
         immed = -0x01234567
-        base_addr = 0xFEDCBA9876543210
+        base_addr = intmask(0xFEDCBA9876543210)
         cb = LocationCodeBuilder64()
         cb.MOV(AddressLoc(edx, ImmedLoc(0), 0, base_addr),
                ImmedLoc(immed))
@@ -320,7 +320,7 @@
 
     def test_MOV_immed32_into_64bit_address_4(self):
         immed = -0x01234567
-        base_addr = 0xFEDCBA9876543210
+        base_addr = intmask(0xFEDCBA9876543210)
         cb = LocationCodeBuilder64()
         cb.MOV(AddressLoc(edx, esi, 2, base_addr), ImmedLoc(immed))
         # this case is a MOV_ai
@@ -339,7 +339,7 @@
 
     def test_MOV_immed64_into_64bit_address_1(self):
         immed = 0x0123456789ABCDEF
-        base_addr = 0xFEDCBA9876543210
+        base_addr = intmask(0xFEDCBA9876543210)
         cb = LocationCodeBuilder64()
         cb.MOV(AddressLoc(ImmedLoc(0), ImmedLoc(0), 0, base_addr),
                ImmedLoc(immed))
@@ -361,7 +361,7 @@
 
     def test_MOV_immed64_into_64bit_address_2(self):
         immed = 0x0123456789ABCDEF
-        base_addr = 0xFEDCBA9876543210
+        base_addr = intmask(0xFEDCBA9876543210)
         cb = LocationCodeBuilder64()
         cb.MOV(AddressLoc(ImmedLoc(0), edx, 3, base_addr),
                ImmedLoc(immed))
@@ -383,7 +383,7 @@
 
     def test_MOV_immed64_into_64bit_address_3(self):
         immed = 0x0123456789ABCDEF
-        base_addr = 0xFEDCBA9876543210
+        base_addr = intmask(0xFEDCBA9876543210)
         cb = LocationCodeBuilder64()
         cb.MOV(AddressLoc(eax, ImmedLoc(0), 0, base_addr),
                ImmedLoc(immed))
@@ -407,7 +407,7 @@
 
     def test_MOV_immed64_into_64bit_address_4(self):
         immed = 0x0123456789ABCDEF
-        base_addr = 0xFEDCBA9876543210
+        base_addr = intmask(0xFEDCBA9876543210)
         cb = LocationCodeBuilder64()
         cb.MOV(AddressLoc(edx, eax, 2, base_addr), ImmedLoc(immed))
         # this case is a MOV_ai
diff --git a/rpython/jit/backend/x86/test/test_ztranslation_call_assembler.py b/rpython/jit/backend/x86/test/test_ztranslation_call_assembler.py
--- a/rpython/jit/backend/x86/test/test_ztranslation_call_assembler.py
+++ b/rpython/jit/backend/x86/test/test_ztranslation_call_assembler.py
@@ -4,6 +4,16 @@
 from rpython.jit.backend.x86.arch import WORD
 import sys
 
+
+# On Windows, this test crashes obscurely, but only if compiled with
+# Boehm, not if run with no GC at all.  So for now we'll assume it is
+# really a Boehm bug, or maybe a Boehm-on-Windows-specific issue, and
+# skip.
+if sys.platform == 'win32':
+    import py
+    py.test.skip("crashes on Windows (Boehm issue?)")
+
+
 class TestTranslationCallAssemblerX86(TranslationTestCallAssembler):
     def _check_cbuilder(self, cbuilder):
         #We assume here that we have sse2.  If not, the CPUClass
diff --git a/rpython/jit/metainterp/test/test_fficall.py b/rpython/jit/metainterp/test/test_fficall.py
--- a/rpython/jit/metainterp/test/test_fficall.py
+++ b/rpython/jit/metainterp/test/test_fficall.py
@@ -11,7 +11,7 @@
 from rpython.rlib.jit_libffi import (types, CIF_DESCRIPTION, FFI_TYPE_PP,
                                      jit_ffi_call)
 from rpython.rlib.unroll import unrolling_iterable
-from rpython.rlib.rarithmetic import intmask, r_longlong, r_singlefloat
+from rpython.rlib.rarithmetic import intmask, r_longlong, r_singlefloat, r_uint
 from rpython.rlib.longlong2float import float2longlong
 
 def get_description(atypes, rtype):
@@ -230,8 +230,8 @@
 
     def test_handle_unsigned(self):
         self._run([types.ulong], types.ulong,
-                  [rffi.cast(rffi.ULONG, sys.maxint + 91348)],
-                  rffi.cast(rffi.ULONG, sys.maxint + 4242))
+                  [rffi.cast(rffi.ULONG, r_uint(sys.maxint + 91348))],
+                  rffi.cast(rffi.ULONG, r_uint(sys.maxint + 4242)))
 
     def test_handle_unsignedchar(self):
         self._run([types.uint8], types.uint8,
diff --git a/rpython/rlib/test/test_rarithmetic.py b/rpython/rlib/test/test_rarithmetic.py
--- a/rpython/rlib/test/test_rarithmetic.py
+++ b/rpython/rlib/test/test_rarithmetic.py
@@ -404,6 +404,8 @@
 def test_int_c_div_mod(x, y):
     assert int_c_div(~x, y) == -(abs(~x) // y)
     assert int_c_div( x,-y) == -(x // y)
+    if (x, y) == (sys.maxint, 1):
+        py.test.skip("would overflow")
     assert int_c_div(~x,-y) == +(abs(~x) // y)
     for x1 in [x, ~x]:
         for y1 in [y, -y]:
diff --git a/rpython/rtyper/lltypesystem/lltype.py b/rpython/rtyper/lltypesystem/lltype.py
--- a/rpython/rtyper/lltypesystem/lltype.py
+++ b/rpython/rtyper/lltypesystem/lltype.py
@@ -812,8 +812,10 @@
         if tp is long:
             if -maxint-1 <= val <= maxint:
                 return Signed
+            elif longlongmask(val) == val:
+                return SignedLongLong
             else:
-                return SignedLongLong
+                raise OverflowError("integer %r is out of bounds" % (val,))
         if tp is bool:
             return Bool
         if issubclass(tp, base_int):
diff --git a/rpython/translator/c/genc.py b/rpython/translator/c/genc.py
--- a/rpython/translator/c/genc.py
+++ b/rpython/translator/c/genc.py
@@ -422,14 +422,11 @@
             mk.definition('PROFOPT', profopt)
 
         rules = [
-            ('clean', '', 'rm -f $(OBJECTS) $(DEFAULT_TARGET) $(TARGET) $(GCMAPFILES) $(ASMFILES) *.gc?? ../module_cache/*.gc??'),
-            ('clean_noprof', '', 'rm -f $(OBJECTS) $(DEFAULT_TARGET) $(TARGET) $(GCMAPFILES) $(ASMFILES)'),
             ('debug', '', '$(MAKE) CFLAGS="$(DEBUGFLAGS) -DRPY_ASSERT" debug_target'),
             ('debug_exc', '', '$(MAKE) CFLAGS="$(DEBUGFLAGS) -DRPY_ASSERT -DDO_LOG_EXC" debug_target'),
             ('debug_mem', '', '$(MAKE) CFLAGS="$(DEBUGFLAGS) -DRPY_ASSERT -DPYPY_USE_TRIVIAL_MALLOC" debug_target'),
             ('llsafer', '', '$(MAKE) CFLAGS="-O2 -DRPY_LL_ASSERT" $(DEFAULT_TARGET)'),
             ('lldebug', '', '$(MAKE) CFLAGS="$(DEBUGFLAGS) -DRPY_ASSERT -DRPY_LL_ASSERT" debug_target'),
-            ('lldebug0','', '$(MAKE) CFLAGS="$(DEBUGFLAGS) -O0 -DMAX_STACK_SIZE=8192000 -DRPY_ASSERT -DRPY_LL_ASSERT" debug_target'),
             ('profile', '', '$(MAKE) CFLAGS="-g -O1 -pg $(CFLAGS) -fno-omit-frame-pointer" LDFLAGS="-pg $(LDFLAGS)" $(DEFAULT_TARGET)'),
             ]
         if self.has_profopt():
@@ -443,6 +440,17 @@
         for rule in rules:
             mk.rule(*rule)
 
+        if self.translator.platform.name == 'msvc':
+            mk.rule('lldebug0','', '$(MAKE) CFLAGS="$(DEBUGFLAGS) -Od -DMAX_STACK_SIZE=8192000 -DRPY_ASSERT -DRPY_LL_ASSERT" debug_target'),
+            wildcards = '..\*.obj ..\*.pdb ..\*.lib ..\*.dll ..\*.manifest ..\*.exp *.pch'
+            cmd =  r'del /s %s $(DEFAULT_TARGET) $(TARGET) $(GCMAPFILES) $(ASMFILES)' % wildcards
+            mk.rule('clean', '',  cmd + ' *.gc?? ..\module_cache\*.gc??')
+            mk.rule('clean_noprof', '', cmd)
+        else:
+            mk.rule('lldebug0','', '$(MAKE) CFLAGS="$(DEBUGFLAGS) -O0 -DMAX_STACK_SIZE=8192000 -DRPY_ASSERT -DRPY_LL_ASSERT" debug_target'),
+            mk.rule('clean', '', 'rm -f $(OBJECTS) $(DEFAULT_TARGET) $(TARGET) $(GCMAPFILES) $(ASMFILES) *.gc?? ../module_cache/*.gc??')
+            mk.rule('clean_noprof', '', 'rm -f $(OBJECTS) $(DEFAULT_TARGET) $(TARGET) $(GCMAPFILES) $(ASMFILES)')
+
         #XXX: this conditional part is not tested at all
         if self.config.translation.gcrootfinder == 'asmgcc':
             if self.translator.platform.name == 'msvc':
@@ -507,7 +515,7 @@
                 else:
                     mk.definition('DEBUGFLAGS', '-O1 -g')
         if self.translator.platform.name == 'msvc':
-            mk.rule('debug_target', '$(DEFAULT_TARGET)', 'rem')
+            mk.rule('debug_target', '$(DEFAULT_TARGET) $(WTARGET)', 'rem')
         else:
             mk.rule('debug_target', '$(DEFAULT_TARGET)', '#')
         mk.write()


More information about the pypy-commit mailing list