[pypy-commit] pypy numpy-dtype-refactor: merged default in

alex_gaynor noreply at buildbot.pypy.org
Thu Nov 10 19:13:25 CET 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: numpy-dtype-refactor
Changeset: r49285:59aca542f69a
Date: 2011-11-09 18:19 -0500
http://bitbucket.org/pypy/pypy/changeset/59aca542f69a/

Log:	merged default in

diff --git a/lib-python/2.7/test/test_os.py b/lib-python/2.7/test/test_os.py
--- a/lib-python/2.7/test/test_os.py
+++ b/lib-python/2.7/test/test_os.py
@@ -74,7 +74,8 @@
         self.assertFalse(os.path.exists(name),
                     "file already exists for temporary file")
         # make sure we can create the file
-        open(name, "w")
+        f = open(name, "w")
+        f.close()
         self.files.append(name)
 
     def test_tempnam(self):
diff --git a/lib-python/2.7/pkgutil.py b/lib-python/modified-2.7/pkgutil.py
copy from lib-python/2.7/pkgutil.py
copy to lib-python/modified-2.7/pkgutil.py
--- a/lib-python/2.7/pkgutil.py
+++ b/lib-python/modified-2.7/pkgutil.py
@@ -244,7 +244,8 @@
         return mod
 
     def get_data(self, pathname):
-        return open(pathname, "rb").read()
+        with open(pathname, "rb") as f:
+            return f.read()
 
     def _reopen(self):
         if self.file and self.file.closed:
diff --git a/pypy/interpreter/test/test_typedef.py b/pypy/interpreter/test/test_typedef.py
--- a/pypy/interpreter/test/test_typedef.py
+++ b/pypy/interpreter/test/test_typedef.py
@@ -2,7 +2,7 @@
 from pypy.interpreter import typedef
 from pypy.tool.udir import udir
 from pypy.interpreter.baseobjspace import Wrappable
-from pypy.interpreter.gateway import ObjSpace
+from pypy.interpreter.gateway import ObjSpace, interp2app
 
 # this test isn't so much to test that the objspace interface *works*
 # -- it's more to test that it's *there*
@@ -260,6 +260,50 @@
         gc.collect(); gc.collect()
         assert space.unwrap(w_seen) == [6, 2]
 
+    def test_multiple_inheritance(self):
+        class W_A(Wrappable):
+            a = 1
+            b = 2
+        class W_C(W_A):
+            b = 3
+        W_A.typedef = typedef.TypeDef("A",
+            a = typedef.interp_attrproperty("a", cls=W_A),
+            b = typedef.interp_attrproperty("b", cls=W_A),
+        )
+        class W_B(Wrappable):
+            pass
+        def standalone_method(space, w_obj):
+            if isinstance(w_obj, W_A):
+                return space.w_True
+            else:
+                return space.w_False
+        W_B.typedef = typedef.TypeDef("B",
+            c = interp2app(standalone_method)
+        )
+        W_C.typedef = typedef.TypeDef("C", (W_A.typedef, W_B.typedef,))
+
+        w_o1 = self.space.wrap(W_C())
+        w_o2 = self.space.wrap(W_B())
+        w_c = self.space.gettypefor(W_C)
+        w_b = self.space.gettypefor(W_B)
+        w_a = self.space.gettypefor(W_A)
+        assert w_c.mro_w == [
+            w_c,
+            w_a,
+            w_b,
+            self.space.w_object,
+        ]
+        for w_tp in w_c.mro_w:
+            assert self.space.isinstance_w(w_o1, w_tp)
+        def assert_attr(w_obj, name, value):
+            assert self.space.unwrap(self.space.getattr(w_obj, self.space.wrap(name))) == value
+        def assert_method(w_obj, name, value):
+            assert self.space.unwrap(self.space.call_method(w_obj, name)) == value
+        assert_attr(w_o1, "a", 1)
+        assert_attr(w_o1, "b", 3)
+        assert_method(w_o1, "c", True)
+        assert_method(w_o2, "c", False)
+
 
 class AppTestTypeDef:
 
diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -15,13 +15,19 @@
     def __init__(self, __name, __base=None, **rawdict):
         "NOT_RPYTHON: initialization-time only"
         self.name = __name
-        self.base = __base
+        if __base is None:
+            bases = []
+        elif isinstance(__base, tuple):
+            bases = list(__base)
+        else:
+            bases = [__base]
+        self.bases = bases
         self.hasdict = '__dict__' in rawdict
         self.weakrefable = '__weakref__' in rawdict
         self.doc = rawdict.pop('__doc__', None)
-        if __base is not None:
-            self.hasdict     |= __base.hasdict
-            self.weakrefable |= __base.weakrefable
+        for base in bases:
+            self.hasdict     |= base.hasdict
+            self.weakrefable |= base.weakrefable
         self.rawdict = {}
         self.acceptable_as_base_class = '__new__' in rawdict
         self.applevel_subclasses_base = None
diff --git a/pypy/jit/backend/llsupport/descr.py b/pypy/jit/backend/llsupport/descr.py
--- a/pypy/jit/backend/llsupport/descr.py
+++ b/pypy/jit/backend/llsupport/descr.py
@@ -305,12 +305,16 @@
     _clsname = ''
     loop_token = None
     arg_classes = ''     # <-- annotation hack
-    ffi_flags = 0
+    ffi_flags = 1
 
-    def __init__(self, arg_classes, extrainfo=None, ffi_flags=0):
+    def __init__(self, arg_classes, extrainfo=None, ffi_flags=1):
         self.arg_classes = arg_classes    # string of "r" and "i" (ref/int)
         self.extrainfo = extrainfo
         self.ffi_flags = ffi_flags
+        # NB. the default ffi_flags is 1, meaning FUNCFLAG_CDECL, which
+        # makes sense on Windows as it's the one for all the C functions
+        # we are compiling together with the JIT.  On non-Windows platforms
+        # it is just ignored anyway.
 
     def __repr__(self):
         res = '%s(%s)' % (self.__class__.__name__, self.arg_classes)
@@ -445,7 +449,7 @@
     """
     _clsname = 'DynamicIntCallDescr'
 
-    def __init__(self, arg_classes, result_size, result_sign, extrainfo=None, ffi_flags=0):
+    def __init__(self, arg_classes, result_size, result_sign, extrainfo, ffi_flags):
         BaseIntCallDescr.__init__(self, arg_classes, extrainfo, ffi_flags)
         assert isinstance(result_sign, bool)
         self._result_size = chr(result_size)
diff --git a/pypy/jit/backend/llsupport/ffisupport.py b/pypy/jit/backend/llsupport/ffisupport.py
--- a/pypy/jit/backend/llsupport/ffisupport.py
+++ b/pypy/jit/backend/llsupport/ffisupport.py
@@ -8,7 +8,7 @@
 class UnsupportedKind(Exception):
     pass
 
-def get_call_descr_dynamic(cpu, ffi_args, ffi_result, extrainfo=None, ffi_flags=0):
+def get_call_descr_dynamic(cpu, ffi_args, ffi_result, extrainfo, ffi_flags):
     """Get a call descr: the types of result and args are represented by
     rlib.libffi.types.*"""
     try:
diff --git a/pypy/jit/backend/llsupport/test/test_ffisupport.py b/pypy/jit/backend/llsupport/test/test_ffisupport.py
--- a/pypy/jit/backend/llsupport/test/test_ffisupport.py
+++ b/pypy/jit/backend/llsupport/test/test_ffisupport.py
@@ -13,44 +13,46 @@
 
 def test_call_descr_dynamic():
     args = [types.sint, types.pointer]
-    descr = get_call_descr_dynamic(FakeCPU(), args, types.sint, ffi_flags=42)
+    descr = get_call_descr_dynamic(FakeCPU(), args, types.sint, None,
+                                   ffi_flags=42)
     assert isinstance(descr, DynamicIntCallDescr)
     assert descr.arg_classes == 'ii'
     assert descr.get_ffi_flags() == 42
 
     args = [types.sint, types.double, types.pointer]
-    descr = get_call_descr_dynamic(FakeCPU(), args, types.void)
+    descr = get_call_descr_dynamic(FakeCPU(), args, types.void, None, 42)
     assert descr is None    # missing floats
     descr = get_call_descr_dynamic(FakeCPU(supports_floats=True),
-                                   args, types.void, ffi_flags=43)
+                                   args, types.void, None, ffi_flags=43)
     assert isinstance(descr, VoidCallDescr)
     assert descr.arg_classes == 'ifi'
     assert descr.get_ffi_flags() == 43
 
-    descr = get_call_descr_dynamic(FakeCPU(), [], types.sint8)
+    descr = get_call_descr_dynamic(FakeCPU(), [], types.sint8, None, 42)
     assert isinstance(descr, DynamicIntCallDescr)
     assert descr.get_result_size(False) == 1
     assert descr.is_result_signed() == True
 
-    descr = get_call_descr_dynamic(FakeCPU(), [], types.uint8)
+    descr = get_call_descr_dynamic(FakeCPU(), [], types.uint8, None, 42)
     assert isinstance(descr, DynamicIntCallDescr)
     assert descr.get_result_size(False) == 1
     assert descr.is_result_signed() == False
 
     if not is_64_bit:
-        descr = get_call_descr_dynamic(FakeCPU(), [], types.slonglong)
+        descr = get_call_descr_dynamic(FakeCPU(), [], types.slonglong,
+                                       None, 42)
         assert descr is None   # missing longlongs
         descr = get_call_descr_dynamic(FakeCPU(supports_longlong=True),
-                                       [], types.slonglong, ffi_flags=43)
+                                       [], types.slonglong, None, ffi_flags=43)
         assert isinstance(descr, LongLongCallDescr)
         assert descr.get_ffi_flags() == 43
     else:
         assert types.slonglong is types.slong
 
-    descr = get_call_descr_dynamic(FakeCPU(), [], types.float)
+    descr = get_call_descr_dynamic(FakeCPU(), [], types.float, None, 42)
     assert descr is None   # missing singlefloats
     descr = get_call_descr_dynamic(FakeCPU(supports_singlefloats=True),
-                                   [], types.float, ffi_flags=44)
+                                   [], types.float, None, ffi_flags=44)
     SingleFloatCallDescr = getCallDescrClass(rffi.FLOAT)
     assert isinstance(descr, SingleFloatCallDescr)
     assert descr.get_ffi_flags() == 44
diff --git a/pypy/jit/backend/x86/test/test_runner.py b/pypy/jit/backend/x86/test/test_runner.py
--- a/pypy/jit/backend/x86/test/test_runner.py
+++ b/pypy/jit/backend/x86/test/test_runner.py
@@ -455,6 +455,9 @@
                                                 EffectInfo.MOST_GENERAL,
                                                 ffi_flags=-1)
             calldescr.get_call_conv = lambda: ffi      # <==== hack
+            # ^^^ we patch get_call_conv() so that the test also makes sense
+            #     on Linux, because clibffi.get_call_conv() would always
+            #     return FFI_DEFAULT_ABI on non-Windows platforms.
             funcbox = ConstInt(rawstart)
             i1 = BoxInt()
             i2 = BoxInt()
diff --git a/pypy/jit/metainterp/optimizeopt/intutils.py b/pypy/jit/metainterp/optimizeopt/intutils.py
--- a/pypy/jit/metainterp/optimizeopt/intutils.py
+++ b/pypy/jit/metainterp/optimizeopt/intutils.py
@@ -1,4 +1,4 @@
-from pypy.rlib.rarithmetic import ovfcheck, ovfcheck_lshift, LONG_BIT
+from pypy.rlib.rarithmetic import ovfcheck, LONG_BIT
 from pypy.rlib.objectmodel import we_are_translated
 from pypy.jit.metainterp.resoperation import rop, ResOperation
 from pypy.jit.metainterp.history import BoxInt, ConstInt
@@ -174,10 +174,10 @@
            other.known_ge(IntBound(0, 0)) and \
            other.known_lt(IntBound(LONG_BIT, LONG_BIT)):
             try:
-                vals = (ovfcheck_lshift(self.upper, other.upper),
-                        ovfcheck_lshift(self.upper, other.lower),
-                        ovfcheck_lshift(self.lower, other.upper),
-                        ovfcheck_lshift(self.lower, other.lower))
+                vals = (ovfcheck(self.upper << other.upper),
+                        ovfcheck(self.upper << other.lower),
+                        ovfcheck(self.lower << other.upper),
+                        ovfcheck(self.lower << other.lower))
                 return IntBound(min4(vals), max4(vals))
             except (OverflowError, ValueError):
                 return IntUnbounded()
diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
--- a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
+++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
@@ -5000,6 +5000,7 @@
         self.optimize_loop(ops, expected)
 
     def test_known_equal_ints(self):
+        py.test.skip("in-progress")
         ops = """
         [i0, i1, i2, p0]
         i3 = int_eq(i0, i1)
diff --git a/pypy/module/cpyext/pyobject.py b/pypy/module/cpyext/pyobject.py
--- a/pypy/module/cpyext/pyobject.py
+++ b/pypy/module/cpyext/pyobject.py
@@ -116,8 +116,8 @@
     try:
         return typedescr_cache[typedef]
     except KeyError:
-        if typedef.base is not None:
-            return _get_typedescr_1(typedef.base)
+        if typedef.bases:
+            return _get_typedescr_1(typedef.bases[0])
         return typedescr_cache[None]
 
 def get_typedescr(typedef):
diff --git a/pypy/objspace/flow/operation.py b/pypy/objspace/flow/operation.py
--- a/pypy/objspace/flow/operation.py
+++ b/pypy/objspace/flow/operation.py
@@ -11,7 +11,7 @@
 from pypy.interpreter.baseobjspace import ObjSpace
 from pypy.interpreter.error import OperationError
 from pypy.tool.sourcetools import compile2
-from pypy.rlib.rarithmetic import ovfcheck, ovfcheck_lshift
+from pypy.rlib.rarithmetic import ovfcheck
 from pypy.objspace.flow import model
 
 
@@ -144,7 +144,7 @@
     return ovfcheck(x % y)
 
 def lshift_ovf(x, y):
-    return ovfcheck_lshift(x, y)
+    return ovfcheck(x << y)
 
 # slicing: operator.{get,set,del}slice() don't support b=None or c=None
 def do_getslice(a, b, c):
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
@@ -6,7 +6,7 @@
 from pypy.objspace.std.noneobject import W_NoneObject
 from pypy.objspace.std.register_all import register_all
 from pypy.rlib import jit
-from pypy.rlib.rarithmetic import ovfcheck, ovfcheck_lshift, LONG_BIT, r_uint
+from pypy.rlib.rarithmetic import ovfcheck, LONG_BIT, r_uint
 from pypy.rlib.rbigint import rbigint
 
 """
@@ -245,7 +245,7 @@
     b = w_int2.intval
     if r_uint(b) < LONG_BIT: # 0 <= b < LONG_BIT
         try:
-            c = ovfcheck_lshift(a, b)
+            c = ovfcheck(a << b)
         except OverflowError:
             raise FailedToImplementArgs(space.w_OverflowError,
                                     space.wrap("integer left shift"))
diff --git a/pypy/objspace/std/stdtypedef.py b/pypy/objspace/std/stdtypedef.py
--- a/pypy/objspace/std/stdtypedef.py
+++ b/pypy/objspace/std/stdtypedef.py
@@ -32,11 +32,14 @@
     from pypy.objspace.std.objecttype import object_typedef
     if b is object_typedef:
         return True
-    while a is not b:
-        if a is None:
-            return False
-        a = a.base
-    return True
+    if a is None:
+        return False
+    if a is b:
+        return True
+    for a1 in a.bases:
+        if issubtypedef(a1, b):
+            return True
+    return False
 
 std_dict_descr = GetSetProperty(descr_get_dict, descr_set_dict, descr_del_dict,
                     doc="dictionary for instance variables (if defined)")
@@ -75,8 +78,8 @@
         if typedef is object_typedef:
             bases_w = []
         else:
-            base = typedef.base or object_typedef
-            bases_w = [space.gettypeobject(base)]
+            bases = typedef.bases or [object_typedef]
+            bases_w = [space.gettypeobject(base) for base in bases]
 
         # wrap everything
         dict_w = {}
diff --git a/pypy/rlib/listsort.py b/pypy/rlib/listsort.py
--- a/pypy/rlib/listsort.py
+++ b/pypy/rlib/listsort.py
@@ -1,4 +1,4 @@
-from pypy.rlib.rarithmetic import ovfcheck, ovfcheck_lshift
+from pypy.rlib.rarithmetic import ovfcheck
 
 
 ## ------------------------------------------------------------------------
@@ -136,7 +136,7 @@
                     if lower(a.list[p + ofs], key):
                         lastofs = ofs
                         try:
-                            ofs = ovfcheck_lshift(ofs, 1)
+                            ofs = ovfcheck(ofs << 1)
                         except OverflowError:
                             ofs = maxofs
                         else:
@@ -161,7 +161,7 @@
                         # key <= a[hint - ofs]
                         lastofs = ofs
                         try:
-                            ofs = ovfcheck_lshift(ofs, 1)
+                            ofs = ovfcheck(ofs << 1)
                         except OverflowError:
                             ofs = maxofs
                         else:
diff --git a/pypy/rlib/rarithmetic.py b/pypy/rlib/rarithmetic.py
--- a/pypy/rlib/rarithmetic.py
+++ b/pypy/rlib/rarithmetic.py
@@ -12,9 +12,6 @@
          back to a signed int value
 ovfcheck check on CPython whether the result of a signed
          integer operation did overflow
-ovfcheck_lshift
-         << with oveflow checking
-         catering to 2.3/2.4 differences about <<
 ovfcheck_float_to_int
          convert to an integer or raise OverflowError
 r_longlong
@@ -111,18 +108,6 @@
         raise OverflowError, "signed integer expression did overflow"
     return r
 
-def _local_ovfcheck(r):
-    # a copy of the above, because we cannot call ovfcheck
-    # in a context where no primitiveoperator is involved.
-    assert not isinstance(r, r_uint), "unexpected ovf check on unsigned"
-    if isinstance(r, long):
-        raise OverflowError, "signed integer expression did overflow"
-    return r
-
-def ovfcheck_lshift(a, b):
-    "NOT_RPYTHON"
-    return _local_ovfcheck(int(long(a) << b))
-
 # Strange things happening for float to int on 64 bit:
 # int(float(i)) != i  because of rounding issues.
 # These are the minimum and maximum float value that can
diff --git a/pypy/rlib/rgc.py b/pypy/rlib/rgc.py
--- a/pypy/rlib/rgc.py
+++ b/pypy/rlib/rgc.py
@@ -216,8 +216,8 @@
     func._gc_no_collect_ = True
     return func
 
-def is_light_finalizer(func):
-    func._is_light_finalizer_ = True
+def must_be_light_finalizer(func):
+    func._must_be_light_finalizer_ = True
     return func
 
 # ____________________________________________________________
diff --git a/pypy/rpython/llinterp.py b/pypy/rpython/llinterp.py
--- a/pypy/rpython/llinterp.py
+++ b/pypy/rpython/llinterp.py
@@ -1,6 +1,6 @@
 from pypy.objspace.flow.model import FunctionGraph, Constant, Variable, c_last_exception
 from pypy.rlib.rarithmetic import intmask, r_uint, ovfcheck, r_longlong
-from pypy.rlib.rarithmetic import r_ulonglong, ovfcheck_lshift
+from pypy.rlib.rarithmetic import r_ulonglong
 from pypy.rpython.lltypesystem import lltype, llmemory, lloperation, llheap
 from pypy.rpython.lltypesystem import rclass
 from pypy.rpython.ootypesystem import ootype
@@ -1035,7 +1035,7 @@
         assert isinstance(x, int)
         assert isinstance(y, int)
         try:
-            return ovfcheck_lshift(x, y)
+            return ovfcheck(x << y)
         except OverflowError:
             self.make_llexception()
 
diff --git a/pypy/rpython/lltypesystem/module/ll_math.py b/pypy/rpython/lltypesystem/module/ll_math.py
--- a/pypy/rpython/lltypesystem/module/ll_math.py
+++ b/pypy/rpython/lltypesystem/module/ll_math.py
@@ -11,15 +11,17 @@
 from pypy.translator.platform import platform
 from pypy.rlib.rfloat import isfinite, isinf, isnan, INFINITY, NAN
 
+use_library_isinf_isnan = False
 if sys.platform == "win32":
     if platform.name == "msvc":
         # When compiled with /O2 or /Oi (enable intrinsic functions)
         # It's no more possible to take the address of some math functions.
         # Ensure that the compiler chooses real functions instead.
         eci = ExternalCompilationInfo(
-            includes = ['math.h'],
+            includes = ['math.h', 'float.h'],
             post_include_bits = ['#pragma function(floor)'],
             )
+        use_library_isinf_isnan = True
     else:
         eci = ExternalCompilationInfo()
     # Some math functions are C99 and not defined by the Microsoft compiler
@@ -108,18 +110,32 @@
 #
 # Custom implementations
 
+VERY_LARGE_FLOAT = 1.0
+while VERY_LARGE_FLOAT * 100.0 != INFINITY:
+    VERY_LARGE_FLOAT *= 64.0
+
+_lib_isnan = rffi.llexternal("_isnan", [lltype.Float], lltype.Signed,
+                             compilation_info=eci)
+_lib_finite = rffi.llexternal("_finite", [lltype.Float], lltype.Signed,
+                             compilation_info=eci)
+
 def ll_math_isnan(y):
     # By not calling into the external function the JIT can inline this.
     # Floats are awesome.
+    if use_library_isinf_isnan and not jit.we_are_jitted():
+        return bool(_lib_isnan(y))
     return y != y
 
 def ll_math_isinf(y):
-    # Use a bitwise OR so the JIT doesn't produce 2 different guards.
-    return (y == INFINITY) | (y == -INFINITY)
+    if use_library_isinf_isnan and not jit.we_are_jitted():
+        return not _lib_finite(y) and not _lib_isnan(y)
+    return (y + VERY_LARGE_FLOAT) == y
 
 def ll_math_isfinite(y):
     # Use a custom hack that is reasonably well-suited to the JIT.
     # Floats are awesome (bis).
+    if use_library_isinf_isnan and not jit.we_are_jitted():
+        return bool(_lib_finite(y))
     z = 0.0 * y
     return z == z       # i.e.: z is not a NaN
 
@@ -136,10 +152,12 @@
     Windows, FreeBSD and alpha Tru64 are amongst platforms that don't
     always follow C99.
     """
-    if isnan(x) or isnan(y):
+    if isnan(x):
         return NAN
 
-    if isinf(y):
+    if not isfinite(y):
+        if isnan(y):
+            return NAN
         if isinf(x):
             if math_copysign(1.0, x) == 1.0:
                 # atan2(+-inf, +inf) == +-pi/4
@@ -168,7 +186,7 @@
 
 def ll_math_frexp(x):
     # deal with special cases directly, to sidestep platform differences
-    if isnan(x) or isinf(x) or not x:
+    if not isfinite(x) or not x:
         mantissa = x
         exponent = 0
     else:
@@ -185,7 +203,7 @@
 INT_MIN = int(-2**31)
 
 def ll_math_ldexp(x, exp):
-    if x == 0.0 or isinf(x) or isnan(x):
+    if x == 0.0 or not isfinite(x):
         return x    # NaNs, zeros and infinities are returned unchanged
     if exp > INT_MAX:
         # overflow (64-bit platforms only)
@@ -209,10 +227,11 @@
 def ll_math_modf(x):
     # some platforms don't do the right thing for NaNs and
     # infinities, so we take care of special cases directly.
-    if isinf(x):
-        return (math_copysign(0.0, x), x)
-    elif isnan(x):
-        return (x, x)
+    if not isfinite(x):
+        if isnan(x):
+            return (x, x)
+        else:   # isinf(x)
+            return (math_copysign(0.0, x), x)
     intpart_p = lltype.malloc(rffi.DOUBLEP.TO, 1, flavor='raw')
     try:
         fracpart = math_modf(x, intpart_p)
@@ -223,13 +242,21 @@
 
 
 def ll_math_fmod(x, y):
-    if isinf(x) and not isnan(y):
-        raise ValueError("math domain error")
+    # fmod(x, +/-Inf) returns x for finite x.
+    if isinf(y) and isfinite(x):
+        return x
 
-    if y == 0:
-        raise ValueError("math domain error")
-
-    return math_fmod(x, y)
+    _error_reset()
+    r = math_fmod(x, y)
+    errno = rposix.get_errno()
+    if isnan(r):
+        if isnan(x) or isnan(y):
+            errno = 0
+        else:
+            errno = EDOM
+    if errno:
+        _likely_raise(errno, r)
+    return r
 
 
 def ll_math_hypot(x, y):
@@ -242,16 +269,17 @@
     _error_reset()
     r = math_hypot(x, y)
     errno = rposix.get_errno()
-    if isnan(r):
-        if isnan(x) or isnan(y):
-            errno = 0
-        else:
-            errno = EDOM
-    elif isinf(r):
-        if isinf(x) or isnan(x) or isinf(y) or isnan(y):
-            errno = 0
-        else:
-            errno = ERANGE
+    if not isfinite(r):
+        if isnan(r):
+            if isnan(x) or isnan(y):
+                errno = 0
+            else:
+                errno = EDOM
+        else:  # isinf(r)
+            if isfinite(x) and isfinite(y):
+                errno = ERANGE
+            else:
+                errno = 0
     if errno:
         _likely_raise(errno, r)
     return r
@@ -261,30 +289,30 @@
     # deal directly with IEEE specials, to cope with problems on various
     # platforms whose semantics don't exactly match C99
 
-    if isnan(x):
-        if y == 0.0:
-            return 1.0   # NaN**0 = 1
-        return x
-
-    elif isnan(y):
+    if isnan(y):
         if x == 1.0:
             return 1.0   # 1**Nan = 1
         return y
 
-    elif isinf(x):
-        odd_y = not isinf(y) and math_fmod(math_fabs(y), 2.0) == 1.0
-        if y > 0.0:
-            if odd_y:
-                return x
-            return math_fabs(x)
-        elif y == 0.0:
-            return 1.0
-        else:   # y < 0.0
-            if odd_y:
-                return math_copysign(0.0, x)
-            return 0.0
+    if not isfinite(x):
+        if isnan(x):
+            if y == 0.0:
+                return 1.0   # NaN**0 = 1
+            return x
+        else:   # isinf(x)
+            odd_y = not isinf(y) and math_fmod(math_fabs(y), 2.0) == 1.0
+            if y > 0.0:
+                if odd_y:
+                    return x
+                return math_fabs(x)
+            elif y == 0.0:
+                return 1.0
+            else:   # y < 0.0
+                if odd_y:
+                    return math_copysign(0.0, x)
+                return 0.0
 
-    elif isinf(y):
+    if isinf(y):
         if math_fabs(x) == 1.0:
             return 1.0
         elif y > 0.0 and math_fabs(x) > 1.0:
@@ -299,17 +327,18 @@
     _error_reset()
     r = math_pow(x, y)
     errno = rposix.get_errno()
-    if isnan(r):
-        # a NaN result should arise only from (-ve)**(finite non-integer)
-        errno = EDOM
-    elif isinf(r):
-        # an infinite result here arises either from:
-        # (A) (+/-0.)**negative (-> divide-by-zero)
-        # (B) overflow of x**y with x and y finite
-        if x == 0.0:
+    if not isfinite(r):
+        if isnan(r):
+            # a NaN result should arise only from (-ve)**(finite non-integer)
             errno = EDOM
-        else:
-            errno = ERANGE
+        else:   # isinf(r)
+            # an infinite result here arises either from:
+            # (A) (+/-0.)**negative (-> divide-by-zero)
+            # (B) overflow of x**y with x and y finite
+            if x == 0.0:
+                errno = EDOM
+            else:
+                errno = ERANGE
     if errno:
         _likely_raise(errno, r)
     return r
@@ -358,18 +387,19 @@
         r = c_func(x)
         # Error checking fun.  Copied from CPython 2.6
         errno = rposix.get_errno()
-        if isnan(r):
-            if isnan(x):
-                errno = 0
-            else:
-                errno = EDOM
-        elif isinf(r):
-            if isinf(x) or isnan(x):
-                errno = 0
-            elif can_overflow:
-                errno = ERANGE
-            else:
-                errno = EDOM
+        if not isfinite(r):
+            if isnan(r):
+                if isnan(x):
+                    errno = 0
+                else:
+                    errno = EDOM
+            else:  # isinf(r)
+                if not isfinite(x):
+                    errno = 0
+                elif can_overflow:
+                    errno = ERANGE
+                else:
+                    errno = EDOM
         if errno:
             _likely_raise(errno, r)
         return r
diff --git a/pypy/translator/backendopt/finalizer.py b/pypy/translator/backendopt/finalizer.py
--- a/pypy/translator/backendopt/finalizer.py
+++ b/pypy/translator/backendopt/finalizer.py
@@ -4,7 +4,7 @@
 
 class FinalizerError(Exception):
     """ __del__ marked as lightweight finalizer, but the analyzer did
-    not agreed
+    not agree
     """
 
 class FinalizerAnalyzer(graphanalyze.BoolGraphAnalyzer):
@@ -23,7 +23,7 @@
     def analyze_light_finalizer(self, graph):
         result = self.analyze_direct_call(graph)
         if (result is self.top_result() and
-            getattr(graph.func, '_is_light_finalizer_', False)):
+            getattr(graph.func, '_must_be_light_finalizer_', False)):
             raise FinalizerError(FinalizerError.__doc__, graph)
         return result
     
diff --git a/pypy/translator/backendopt/test/test_finalizer.py b/pypy/translator/backendopt/test/test_finalizer.py
--- a/pypy/translator/backendopt/test/test_finalizer.py
+++ b/pypy/translator/backendopt/test/test_finalizer.py
@@ -126,13 +126,13 @@
         r = self.analyze(f, [], A.__del__.im_func)
         assert r
 
-    def test_is_light_finalizer_decorator(self):
+    def test_must_be_light_finalizer_decorator(self):
         S = lltype.GcStruct('S')
 
-        @rgc.is_light_finalizer
+        @rgc.must_be_light_finalizer
         def f():
             lltype.malloc(S)
-        @rgc.is_light_finalizer
+        @rgc.must_be_light_finalizer
         def g():
             pass
         self.analyze(g, []) # did not explode
diff --git a/pypy/translator/c/genc.py b/pypy/translator/c/genc.py
--- a/pypy/translator/c/genc.py
+++ b/pypy/translator/c/genc.py
@@ -622,9 +622,9 @@
             else:
                 mk.definition('DEBUGFLAGS', '-O1 -g')
         if sys.platform == 'win32':
-            mk.rule('debug_target', 'debugmode_$(DEFAULT_TARGET)')
+            mk.rule('debug_target', 'debugmode_$(DEFAULT_TARGET)', 'rem')
         else:
-            mk.rule('debug_target', '$(TARGET)')
+            mk.rule('debug_target', '$(TARGET)', '#')
         mk.write()
         #self.translator.platform,
         #                           ,
diff --git a/pypy/translator/cli/test/test_snippet.py b/pypy/translator/cli/test/test_snippet.py
--- a/pypy/translator/cli/test/test_snippet.py
+++ b/pypy/translator/cli/test/test_snippet.py
@@ -28,14 +28,14 @@
         res = self.interpret(fn, [], backendopt=False)
         
     def test_link_vars_overlapping(self):
-        from pypy.rlib.rarithmetic import ovfcheck, ovfcheck_lshift
+        from pypy.rlib.rarithmetic import ovfcheck
         def fn(maxofs):
             lastofs = 0
             ofs = 1
             while ofs < maxofs:
                 lastofs = ofs
                 try:
-                    ofs = ovfcheck_lshift(ofs, 1)
+                    ofs = ovfcheck(ofs << 1)
                 except OverflowError:
                     ofs = maxofs
                 else:
diff --git a/pypy/translator/simplify.py b/pypy/translator/simplify.py
--- a/pypy/translator/simplify.py
+++ b/pypy/translator/simplify.py
@@ -111,16 +111,13 @@
                 # the while loop above will simplify recursively the new link
 
 def transform_ovfcheck(graph):
-    """The special function calls ovfcheck and ovfcheck_lshift need to
+    """The special function calls ovfcheck needs to
     be translated into primitive operations. ovfcheck is called directly
     after an operation that should be turned into an overflow-checked
     version. It is considered a syntax error if the resulting <op>_ovf
     is not defined in objspace/flow/objspace.py.
-    ovfcheck_lshift is special because there is no preceding operation.
-    Instead, it will be replaced by an OP_LSHIFT_OVF operation.
     """
     covf = Constant(rarithmetic.ovfcheck)
-    covfls = Constant(rarithmetic.ovfcheck_lshift)
 
     def check_syntax(opname):
         exlis = operation.implicit_exceptions.get("%s_ovf" % (opname,), [])
@@ -154,9 +151,6 @@
                 op1.opname += '_ovf'
                 del block.operations[i]
                 block.renamevariables({op.result: op1.result})
-            elif op.args[0] == covfls:
-                op.opname = 'lshift_ovf'
-                del op.args[0]
 
 def simplify_exceptions(graph):
     """The exception handling caused by non-implicit exceptions
diff --git a/pypy/translator/test/snippet.py b/pypy/translator/test/snippet.py
--- a/pypy/translator/test/snippet.py
+++ b/pypy/translator/test/snippet.py
@@ -1210,7 +1210,7 @@
     return istk.top(), sstk.top()
 
 
-from pypy.rlib.rarithmetic import ovfcheck, ovfcheck_lshift
+from pypy.rlib.rarithmetic import ovfcheck
 
 def add_func(i=numtype):
     try:
@@ -1253,7 +1253,7 @@
 def lshift_func(i=numtype):
     try:
         hugo(2, 3, 5)
-        return ovfcheck_lshift((-maxint-1), i)
+        return ovfcheck((-maxint-1) << i)
     except (hugelmugel, OverflowError, StandardError, ValueError):
         raise
 


More information about the pypy-commit mailing list