[pypy-svn] r71891 - in pypy/release/1.2.x: lib-python/modified-2.5.2/ctypes pypy/module/mmap pypy/objspace/flow pypy/objspace/flow/test pypy/rlib pypy/rpython/lltypesystem/module pypy/rpython/lltypesystem/module/test pypy/translator/c/test

arigo at codespeak.net arigo at codespeak.net
Mon Mar 8 17:10:58 CET 2010


Author: arigo
Date: Mon Mar  8 17:10:56 2010
New Revision: 71891

Modified:
   pypy/release/1.2.x/lib-python/modified-2.5.2/ctypes/__init__.py
   pypy/release/1.2.x/pypy/module/mmap/interp_mmap.py
   pypy/release/1.2.x/pypy/objspace/flow/objspace.py
   pypy/release/1.2.x/pypy/objspace/flow/test/test_objspace.py
   pypy/release/1.2.x/pypy/rlib/runicode.py
   pypy/release/1.2.x/pypy/rpython/lltypesystem/module/ll_math.py
   pypy/release/1.2.x/pypy/rpython/lltypesystem/module/test/test_ll_math.py
   pypy/release/1.2.x/pypy/translator/c/test/test_typed.py
Log:
svn merge svn+ssh://codespeak.net/svn/pypy/trunk -r71802:71824


Modified: pypy/release/1.2.x/lib-python/modified-2.5.2/ctypes/__init__.py
==============================================================================
--- pypy/release/1.2.x/lib-python/modified-2.5.2/ctypes/__init__.py	(original)
+++ pypy/release/1.2.x/lib-python/modified-2.5.2/ctypes/__init__.py	Mon Mar  8 17:10:56 2010
@@ -23,21 +23,23 @@
     from _ctypes import FormatError
 
 DEFAULT_MODE = RTLD_LOCAL
-if _os.name == "posix" and _sys.platform == "darwin":
-    import gestalt
+## --- the following is skipped because we don't have 'gestalt' so far,
+## --- but we know pypy doesn't compile on Mac OS/X 10.3.
+##if _os.name == "posix" and _sys.platform == "darwin":
+##    import gestalt
+
+##    # gestalt.gestalt("sysv") returns the version number of the
+##    # currently active system file as BCD.
+##    # On OS X 10.4.6 -> 0x1046
+##    # On OS X 10.2.8 -> 0x1028
+##    # See also http://www.rgaros.nl/gestalt/
+##    #
+##    # On OS X 10.3, we use RTLD_GLOBAL as default mode
+##    # because RTLD_LOCAL does not work at least on some
+##    # libraries.
 
-    # gestalt.gestalt("sysv") returns the version number of the
-    # currently active system file as BCD.
-    # On OS X 10.4.6 -> 0x1046
-    # On OS X 10.2.8 -> 0x1028
-    # See also http://www.rgaros.nl/gestalt/
-    #
-    # On OS X 10.3, we use RTLD_GLOBAL as default mode
-    # because RTLD_LOCAL does not work at least on some
-    # libraries.
-
-    if gestalt.gestalt("sysv") < 0x1040:
-        DEFAULT_MODE = RTLD_GLOBAL
+##    if gestalt.gestalt("sysv") < 0x1040:
+##        DEFAULT_MODE = RTLD_GLOBAL
 
 from _ctypes import FUNCFLAG_CDECL as _FUNCFLAG_CDECL, \
      FUNCFLAG_PYTHONAPI as _FUNCFLAG_PYTHONAPI

Modified: pypy/release/1.2.x/pypy/module/mmap/interp_mmap.py
==============================================================================
--- pypy/release/1.2.x/pypy/module/mmap/interp_mmap.py	(original)
+++ pypy/release/1.2.x/pypy/module/mmap/interp_mmap.py	Mon Mar  8 17:10:56 2010
@@ -54,7 +54,10 @@
     tell.unwrap_spec = ['self']
     
     def descr_size(self):
-        return self.space.wrap(self.mmap.file_size())
+        try:
+            return self.space.wrap(self.mmap.file_size())
+        except OSError, e:
+            raise wrap_oserror(self.space, e, 'w_EnvironmentError')
     descr_size.unwrap_spec = ['self']
     
     def write(self, data):
@@ -83,6 +86,8 @@
         except RValueError, v:
             raise OperationError(self.space.w_ValueError,
                                  self.space.wrap(v.message))
+        except OSError, e:
+            raise wrap_oserror(self.space, e, 'w_EnvironmentError')
     flush.unwrap_spec = ['self', int, int]
     
     def move(self, dest, src, count):
@@ -96,7 +101,10 @@
     def resize(self, newsize):
         self.check_valid()
         self.check_resizeable()
-        self.mmap.resize(newsize)
+        try:
+            self.mmap.resize(newsize)
+        except OSError, e:
+            raise wrap_oserror(self.space, e, 'w_EnvironmentError')
     resize.unwrap_spec = ['self', int]
     
     def __len__(self):

Modified: pypy/release/1.2.x/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/release/1.2.x/pypy/objspace/flow/objspace.py	(original)
+++ pypy/release/1.2.x/pypy/objspace/flow/objspace.py	Mon Mar  8 17:10:56 2010
@@ -370,6 +370,9 @@
     def call_args(self, w_callable, args):
         try:
             fn = self.unwrap(w_callable)
+            if hasattr(fn, "_flowspace_rewrite_directly_as_"):
+                fn = fn._flowspace_rewrite_directly_as_
+                w_callable = self.wrap(fn)
             sc = self.specialcases[fn]   # TypeError if 'fn' not hashable
         except (UnwrapException, KeyError, TypeError):
             pass

Modified: pypy/release/1.2.x/pypy/objspace/flow/test/test_objspace.py
==============================================================================
--- pypy/release/1.2.x/pypy/objspace/flow/test/test_objspace.py	(original)
+++ pypy/release/1.2.x/pypy/objspace/flow/test/test_objspace.py	Mon Mar  8 17:10:56 2010
@@ -892,6 +892,22 @@
                     raise TypeError()
         py.test.raises(Exception, self.codetest, f)
 
+    def test__flowspace_rewrite_directly_as_(self):
+        def g(x):
+            pass
+        def f(x):
+            pass
+        f._flowspace_rewrite_directly_as_ = g
+        def h(x):
+            f(x)
+        graph = self.codetest(h)
+        assert self.all_operations(graph) == {'simple_call': 1}
+        for block in graph.iterblocks():
+            if block.operations:
+                op = block.operations[0]
+                assert op.opname == 'simple_call'
+                assert op.args[0] == Constant(g)
+
 
 class TestFlowObjSpaceDelay(Base):
     def setup_class(cls):

Modified: pypy/release/1.2.x/pypy/rlib/runicode.py
==============================================================================
--- pypy/release/1.2.x/pypy/rlib/runicode.py	(original)
+++ pypy/release/1.2.x/pypy/rlib/runicode.py	Mon Mar  8 17:10:56 2010
@@ -16,26 +16,28 @@
     # when sizeof(wchar_t) == 4.
     # Note that Python3 uses a similar implementation.
     def UNICHR(c):
-        if we_are_translated():
+        assert not we_are_translated()
+        if c < sys.maxunicode or c > MAXUNICODE:
             return unichr(c)
         else:
-            if c < sys.maxunicode or c > MAXUNICODE:
-                return unichr(c)
-            else:
-                c -= 0x10000
-                return (unichr(0xD800 + (c >> 10)) +
-                        unichr(0xDC00 + (c & 0x03FF)))
+            c -= 0x10000
+            return (unichr(0xD800 + (c >> 10)) +
+                    unichr(0xDC00 + (c & 0x03FF)))
+    UNICHR._flowspace_rewrite_directly_as_ = unichr
+    # ^^^ NB.: for translation, it's essential to use this hack instead
+    # of calling unichr() from UNICHR(), because unichr() detects if there
+    # is a "try:except ValueError" immediately around it.
 
     def ORD(u):
-        if we_are_translated():
-            return ord(u)
-        else:
-            if isinstance(u, unicode) and len(u) == 2:
-                ch1 = ord(u[0])
-                ch2 = ord(u[1])
-                if 0xD800 <= ch1 <= 0xDBFF and 0xDC00 <= ch2 <= 0xDFFF:
-                    return (((ch1 - 0xD800) << 10) | (ch2 - 0xDC00)) + 0x10000
-            return ord(u)
+        assert not we_are_translated()
+        if isinstance(u, unicode) and len(u) == 2:
+            ch1 = ord(u[0])
+            ch2 = ord(u[1])
+            if 0xD800 <= ch1 <= 0xDBFF and 0xDC00 <= ch2 <= 0xDFFF:
+                return (((ch1 - 0xD800) << 10) | (ch2 - 0xDC00)) + 0x10000
+        return ord(u)
+    ORD._flowspace_rewrite_directly_as_ = ord
+
 else:
     UNICHR = unichr
     ORD = ord

Modified: pypy/release/1.2.x/pypy/rpython/lltypesystem/module/ll_math.py
==============================================================================
--- pypy/release/1.2.x/pypy/rpython/lltypesystem/module/ll_math.py	(original)
+++ pypy/release/1.2.x/pypy/rpython/lltypesystem/module/ll_math.py	Mon Mar  8 17:10:56 2010
@@ -7,6 +7,7 @@
 from pypy.tool.sourcetools import func_with_new_name
 from pypy.rlib import rposix
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
+from pypy.rlib.rarithmetic import isinf
 
 math_frexp = rffi.llexternal('frexp', [rffi.DOUBLE, rffi.INTP], rffi.DOUBLE,
                              sandboxsafe=True)
@@ -26,16 +27,24 @@
 
 def ll_math_frexp(x):
     exp_p = lltype.malloc(rffi.INTP.TO, 1, flavor='raw')
-    mantissa = math_frexp(x, exp_p)
-    exponent = rffi.cast(lltype.Signed, exp_p[0])
-    lltype.free(exp_p, flavor='raw')
+    try:
+        _error_reset()
+        mantissa = math_frexp(x, exp_p)
+        _check_error(mantissa)
+        exponent = rffi.cast(lltype.Signed, exp_p[0])
+    finally:
+        lltype.free(exp_p, flavor='raw')
     return (mantissa, exponent)
 
 def ll_math_modf(x):
     intpart_p = lltype.malloc(rffi.DOUBLEP.TO, 1, flavor='raw')
-    fracpart = math_modf(x, intpart_p)
-    intpart = intpart_p[0]
-    lltype.free(intpart_p, flavor='raw')
+    try:
+        _error_reset()
+        fracpart = math_modf(x, intpart_p)
+        _check_error(fracpart)
+        intpart = intpart_p[0]
+    finally:
+        lltype.free(intpart_p, flavor='raw')
     return (fracpart, intpart)
 
 def ll_math_ldexp(x, exp):
@@ -50,6 +59,8 @@
 ERANGE = errno.ERANGE
 def _check_error(x):
     errno = rposix.get_errno()
+    if isinf(x):
+        errno = ERANGE
     if errno:
         if errno == ERANGE:
             if not x:

Modified: pypy/release/1.2.x/pypy/rpython/lltypesystem/module/test/test_ll_math.py
==============================================================================
--- pypy/release/1.2.x/pypy/rpython/lltypesystem/module/test/test_ll_math.py	(original)
+++ pypy/release/1.2.x/pypy/rpython/lltypesystem/module/test/test_ll_math.py	Mon Mar  8 17:10:56 2010
@@ -45,3 +45,26 @@
         # underflows give 0.0 with no exception raised
         assert f(1.0, -10000) == 0.0     # sanity-check the host Python
         assert self.interpret(f, [1.0, -10000]) == 0.0
+
+    def test_overflow_1(self):
+        # this (probably, depending on platform) tests the case
+        # where the C function pow() sets ERANGE.
+        def f(x, y):
+            try:
+                return math.pow(x, y)
+            except OverflowError:
+                return -42.0
+
+        assert self.interpret(f, [10.0, 40000.0]) == -42.0
+
+    def test_overflow_2(self):
+        # this (not on Linux but on Mac OS/X at least) tests the case
+        # where the C function ldexp() does not set ERANGE, but
+        # returns +infinity.
+        def f(x, y):
+            try:
+                return math.ldexp(x, y)
+            except OverflowError:
+                return -42.0
+
+        assert self.interpret(f, [10.0, 40000]) == -42.0

Modified: pypy/release/1.2.x/pypy/translator/c/test/test_typed.py
==============================================================================
--- pypy/release/1.2.x/pypy/translator/c/test/test_typed.py	(original)
+++ pypy/release/1.2.x/pypy/translator/c/test/test_typed.py	Mon Mar  8 17:10:56 2010
@@ -212,6 +212,18 @@
         assert fn(-12) == -42
         assert fn(sys.maxint) == -42
 
+    def test_UNICHR(self):
+        from pypy.rlib.runicode import UNICHR
+        def f(x):
+            try:
+                return ord(UNICHR(x))
+            except ValueError:
+                return -42
+        fn = self.getcompiled(f, [int])
+        assert fn(65) == 65
+        assert fn(-12) == -42
+        assert fn(sys.maxint) == -42
+
     def test_list_indexerror(self):
         def f(i):
             lst = [123, 456]



More information about the Pypy-commit mailing list