[pypy-commit] pypy default: merge

fijal noreply at buildbot.pypy.org
Sun Jul 12 20:11:19 CEST 2015


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: 
Changeset: r78530:9f734aff75ff
Date: 2015-07-12 20:11 +0200
http://bitbucket.org/pypy/pypy/changeset/9f734aff75ff/

Log:	merge

diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -23,14 +23,14 @@
 default_modules.update([
     "_codecs", "gc", "_weakref", "marshal", "errno", "imp", "math", "cmath",
     "_sre", "_pickle_support", "operator", "parser", "symbol", "token", "_ast",
-    "_io", "_random", "__pypy__", "_testing"
+    "_io", "_random", "__pypy__", "_testing", "time"
 ])
 
 
 # --allworkingmodules
 working_modules = default_modules.copy()
 working_modules.update([
-    "_socket", "unicodedata", "mmap", "fcntl", "_locale", "pwd", "time" ,
+    "_socket", "unicodedata", "mmap", "fcntl", "_locale", "pwd",
     "select", "zipimport", "_lsprof", "crypt", "signal", "_rawffi", "termios",
     "zlib", "bz2", "struct", "_hashlib", "_md5", "_sha", "_minimal_curses",
     "cStringIO", "thread", "itertools", "pyexpat", "_ssl", "cpyext", "array",
diff --git a/pypy/goal/targetpypystandalone.py b/pypy/goal/targetpypystandalone.py
--- a/pypy/goal/targetpypystandalone.py
+++ b/pypy/goal/targetpypystandalone.py
@@ -297,7 +297,12 @@
         options = make_dict(config)
         wrapstr = 'space.wrap(%r)' % (options)
         pypy.module.sys.Module.interpleveldefs['pypy_translation_info'] = wrapstr
+        if config.objspace.usemodules._cffi_backend:
+            self.hack_for_cffi_modules(driver)
 
+        return self.get_entry_point(config)
+    
+    def hack_for_cffi_modules(self, driver):
         # HACKHACKHACK
         # ugly hack to modify target goal from compile_c to build_cffi_imports
         # this should probably get cleaned up and merged with driver.create_exe
@@ -336,8 +341,6 @@
         driver.default_goal = 'build_cffi_imports'
         # HACKHACKHACK end
 
-        return self.get_entry_point(config)
-
     def jitpolicy(self, driver):
         from pypy.module.pypyjit.policy import PyPyJitPolicy
         from pypy.module.pypyjit.hooks import pypy_hooks
diff --git a/pypy/module/_cffi_backend/ctypeobj.py b/pypy/module/_cffi_backend/ctypeobj.py
--- a/pypy/module/_cffi_backend/ctypeobj.py
+++ b/pypy/module/_cffi_backend/ctypeobj.py
@@ -90,6 +90,16 @@
     def _convert_error(self, expected, w_got):
         space = self.space
         if isinstance(w_got, cdataobj.W_CData):
+            if self.name == w_got.ctype.name:
+                # in case we'd give the error message "initializer for
+                # ctype 'A' must be a pointer to same type, not cdata
+                # 'B'", but with A=B, then give instead a different error
+                # message to try to clear up the confusion
+                return oefmt(space.w_TypeError,
+                             "initializer for ctype '%s' appears indeed to "
+                             "be '%s', but the types are different (check "
+                             "that you are not e.g. mixing up different ffi "
+                             "instances)", self.name, w_got.ctype.name)
             return oefmt(space.w_TypeError,
                          "initializer for ctype '%s' must be a %s, not cdata "
                          "'%s'", self.name, expected, w_got.ctype.name)
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -3402,6 +3402,29 @@
     py.test.raises(RuntimeError, "p[42]")
     py.test.raises(RuntimeError, "p[42] = -1")
 
+def test_mixup():
+    BStruct1 = new_struct_type("foo")
+    BStruct2 = new_struct_type("foo")   # <= same name as BStruct1
+    BStruct3 = new_struct_type("bar")
+    BStruct1Ptr = new_pointer_type(BStruct1)
+    BStruct2Ptr = new_pointer_type(BStruct2)
+    BStruct3Ptr = new_pointer_type(BStruct3)
+    BStruct1PtrPtr = new_pointer_type(BStruct1Ptr)
+    BStruct2PtrPtr = new_pointer_type(BStruct2Ptr)
+    BStruct3PtrPtr = new_pointer_type(BStruct3Ptr)
+    pp1 = newp(BStruct1PtrPtr)
+    pp2 = newp(BStruct2PtrPtr)
+    pp3 = newp(BStruct3PtrPtr)
+    pp1[0] = pp1[0]
+    e = py.test.raises(TypeError, "pp3[0] = pp1[0]")
+    assert str(e.value).startswith("initializer for ctype 'bar *' must be a ")
+    assert str(e.value).endswith(", not cdata 'foo *'")
+    e = py.test.raises(TypeError, "pp2[0] = pp1[0]")
+    assert str(e.value) == ("initializer for ctype 'foo *' appears indeed to "
+                            "be 'foo *', but the types are different (check "
+                            "that you are not e.g. mixing up different ffi "
+                            "instances)")
+
 def test_version():
     # this test is here mostly for PyPy
     assert __version__ == "1.2.0"
diff --git a/pypy/module/_vmprof/interp_vmprof.py b/pypy/module/_vmprof/interp_vmprof.py
--- a/pypy/module/_vmprof/interp_vmprof.py
+++ b/pypy/module/_vmprof/interp_vmprof.py
@@ -23,11 +23,16 @@
 # running make inside the src dir
 DYNAMIC_VMPROF = False
 
+if sys.platform.startswith('linux'):
+    libs = ['dl']
+else:
+    libs = []
+
 eci_kwds = dict(
     include_dirs = [SRC],
     includes = ['vmprof.h', 'trampoline.h'],
     separate_module_files = [SRC.join('trampoline.vmprof.s')],
-    libraries = ['dl'],
+    libraries = libs,
     
     post_include_bits=["""
         int pypy_vmprof_init(void);
diff --git a/pypy/module/_vmprof/src/config.h b/pypy/module/_vmprof/src/config.h
--- a/pypy/module/_vmprof/src/config.h
+++ b/pypy/module/_vmprof/src/config.h
@@ -1,2 +1,6 @@
 #define HAVE_SYS_UCONTEXT_H
+#if defined(__FreeBSD__) || defined(__APPLE__)
+#define PC_FROM_UCONTEXT uc_mcontext.mc_rip
+#else
 #define PC_FROM_UCONTEXT uc_mcontext.gregs[REG_RIP]
+#endif
diff --git a/pypy/module/_vmprof/src/vmprof.c b/pypy/module/_vmprof/src/vmprof.c
--- a/pypy/module/_vmprof/src/vmprof.c
+++ b/pypy/module/_vmprof/src/vmprof.c
@@ -33,6 +33,9 @@
 //#include <libunwind.h>
 
 #include "vmprof.h"
+#if defined(__FreeBSD__) || defined(__APPLE__)
+#define sighandler_t sig_t
+#endif
 
 #define _unused(x) ((void)x)
 
diff --git a/pypy/module/micronumpy/test/test_ufuncs.py b/pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -540,6 +540,15 @@
         for v in [float('inf'), float('-inf'), float('nan'), float('-nan')]:
             assert math.isnan(fmod(v, 2))
 
+    def test_mod(self):
+        from numpy import mod
+        assert mod(5, 3) == 2
+        assert mod(5, -3) == -1
+        assert mod(-5, 3) == 1
+        assert mod(-5, -3) == -2
+        assert mod(2.5, 1) == 0.5
+        assert mod(-1.5, 2) == 0.5
+
     def test_minimum(self):
         from numpy import array, minimum, nan, isnan
 
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -759,7 +759,21 @@
 
     @simple_binary_op
     def mod(self, v1, v2):
-        return math.fmod(v1, v2)
+        # partial copy of pypy.objspace.std.floatobject.W_FloatObject.descr_mod
+        if v2 == 0.0:
+            return rfloat.NAN
+        mod = math.fmod(v1, v2)
+        if mod:
+            # ensure the remainder has the same sign as the denominator
+            if (v2 < 0.0) != (mod < 0.0):
+                mod += v2
+        else:
+            # the remainder is zero, and in the presence of signed zeroes
+            # fmod returns different results across platforms; ensure
+            # it has the same sign as the denominator; we'd like to do
+            # "mod = v2 * 0.0", but that may get optimized away
+            mod = rfloat.copysign(0.0, v2)
+        return mod
 
     @simple_binary_op
     def pow(self, v1, v2):
diff --git a/pypy/module/pypyjit/test_pypy_c/test_string.py b/pypy/module/pypyjit/test_pypy_c/test_string.py
--- a/pypy/module/pypyjit/test_pypy_c/test_string.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_string.py
@@ -238,7 +238,7 @@
         log = self.run("""
         def main(n):
             for i in xrange(n):
-                unicode('abc')
+                unicode(str(i))
             return i
         """, [1000])
         loop, = log.loops_by_filename(self.filepath)
@@ -248,10 +248,10 @@
         i50 = int_add(i47, 1)
         setfield_gc(p15, i50, descr=<FieldS pypy.module.__builtin__.functional.W_XRangeIterator.inst_current 8>)
         guard_not_invalidated(descr=...)
-        p52 = call(ConstClass(str_decode_ascii__raise_unicode_exception_decode), ConstPtr(ptr38), 3, 1, descr=<Callr . rii EF=5>)
+        p80 = call(ConstClass(ll_str__IntegerR_SignedConst_Signed), i47, descr=<Callr . i EF=3>)
         guard_no_exception(descr=...)
-        p53 = getfield_gc_pure(p52, descr=<FieldP tuple2.item0 .>)
-        guard_nonnull(p53, descr=...)
+        p53 = call(ConstClass(fast_str_decode_ascii), p80, descr=<Callr . r EF=4>)
+        guard_no_exception(descr=...)
         --TICK--
         jump(..., descr=...)
         """)
diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -6,7 +6,7 @@
 from rpython.rlib.rstring import StringBuilder, UnicodeBuilder
 from rpython.rlib.runicode import (
     make_unicode_escape_function, str_decode_ascii, str_decode_utf_8,
-    unicode_encode_ascii, unicode_encode_utf_8)
+    unicode_encode_ascii, unicode_encode_utf_8, fast_str_decode_ascii)
 
 from pypy.interpreter import unicodehelper
 from pypy.interpreter.baseobjspace import W_Root
@@ -481,9 +481,13 @@
         if encoding == 'ascii':
             # XXX error handling
             s = space.charbuf_w(w_obj)
-            eh = unicodehelper.decode_error_handler(space)
-            return space.wrap(str_decode_ascii(
-                    s, len(s), None, final=True, errorhandler=eh)[0])
+            try:
+                u = fast_str_decode_ascii(s)
+            except ValueError:
+                eh = unicodehelper.decode_error_handler(space)
+                u = str_decode_ascii(     # try again, to get the error right
+                    s, len(s), None, final=True, errorhandler=eh)[0]
+            return space.wrap(u)
         if encoding == 'utf-8':
             s = space.charbuf_w(w_obj)
             eh = unicodehelper.decode_error_handler(space)
diff --git a/rpython/rlib/runicode.py b/rpython/rlib/runicode.py
--- a/rpython/rlib/runicode.py
+++ b/rpython/rlib/runicode.py
@@ -1009,6 +1009,16 @@
             result.append(r)
     return result.build(), pos
 
+# An elidable version, for a subset of the cases
+ at jit.elidable
+def fast_str_decode_ascii(s):
+    result = UnicodeBuilder(len(s))
+    for c in s:
+        if ord(c) >= 128:
+            raise ValueError
+        result.append(unichr(ord(c)))
+    return result.build()
+
 
 # Specialize on the errorhandler when it's a constant
 @specialize.arg_or_var(3)
diff --git a/rpython/rlib/test/test_runicode.py b/rpython/rlib/test/test_runicode.py
--- a/rpython/rlib/test/test_runicode.py
+++ b/rpython/rlib/test/test_runicode.py
@@ -139,6 +139,12 @@
             for encoding in "utf-8 latin-1 ascii".split():
                 self.checkdecode(chr(i), encoding)
 
+    def test_fast_str_decode_ascii(self):
+        u = runicode.fast_str_decode_ascii("abc\x00\x7F")
+        assert type(u) is unicode
+        assert u == u"abc\x00\x7F"
+        py.test.raises(ValueError, runicode.fast_str_decode_ascii, "ab\x80")
+
     def test_all_first_256(self):
         for i in range(256):
             for encoding in ("utf-7 utf-8 latin-1 utf-16 utf-16-be utf-16-le "


More information about the pypy-commit mailing list