Commits

Armin Rigo  committed cda44e9 Merge

merge heads

  • Participants
  • Parent commits 1ae31b6, 3f632ce

Comments (0)

Files changed (16)

File pypy/doc/_ref.txt

 .. _`rpython/translator/c/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/c/
 .. _`rpython/translator/c/src/stacklet/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/c/src/stacklet/
 .. _`rpython/translator/c/src/stacklet/stacklet.h`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/c/src/stacklet/stacklet.h
-.. _`rpython/translator/cli/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/cli/
-.. _`rpython/translator/jvm/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/jvm/
 .. _`rpython/translator/tool/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/tool/

File pypy/interpreter/pyframe.py

     def run(self):
         """Start this frame's execution."""
         if self.getcode().co_flags & pycode.CO_GENERATOR:
-            if self.getcode().co_flags & pycode.CO_YIELD_INSIDE_TRY:
+            if 1:# self.getcode().co_flags & pycode.CO_YIELD_INSIDE_TRY:
                 from pypy.interpreter.generator import GeneratorIteratorWithDel
                 return self.space.wrap(GeneratorIteratorWithDel(self))
             else:

File pypy/module/_cffi_backend/ctypestruct.py

         if self.fields_dict is None:
             space = self.space
             raise operationerrfmt(w_errorcls or space.w_TypeError,
-                                  "'%s' is not completed yet", self.name)
+                              "'%s' is opaque or not completed yet", self.name)
 
     def _alignof(self):
         self.check_complete(w_errorcls=self.space.w_ValueError)

File pypy/module/_rawffi/test/test__rawffi.py

 from rpython.translator.platform import platform
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
-from pypy.conftest import option
 from pypy.module._rawffi.interp_rawffi import TYPEMAP, TYPEMAP_FLOAT_LETTERS
 from pypy.module._rawffi.tracker import Tracker
 
     def setup_class(cls):
         cls.w_sizes_and_alignments = cls.space.wrap(dict(
             [(k, (v.c_size, v.c_alignment)) for k,v in TYPEMAP.iteritems()]))
-        #
-        # detect if we're running on PyPy with DO_TRACING not compiled in
-        if option.runappdirect:
-            try:
-                import _rawffi
-                _rawffi._num_of_allocated_objects()
-            except (ImportError, RuntimeError), e:
-                py.test.skip(str(e))
-        #
         Tracker.DO_TRACING = True
 
     def test_structure_autofree(self):

File pypy/module/struct/__init__.py

         'calcsize': 'interp_struct.calcsize',
         'pack': 'interp_struct.pack',
         'unpack': 'interp_struct.unpack',
-        }
+
+        'Struct': 'interp_struct.W_Struct',
+    }
 
     appleveldefs = {
         'error': 'app_struct.error',
         'pack_into': 'app_struct.pack_into',
         'unpack_from': 'app_struct.unpack_from',
-        'Struct': 'app_struct.Struct',
-        }
+    }

File pypy/module/struct/app_struct.py

 """
 import struct
 
+
 class error(Exception):
     """Exception raised on various occasions; argument is a string
     describing what is wrong."""
         raise error("unpack_from requires a buffer of at least %d bytes"
                     % (size,))
     return struct.unpack(fmt, data)
-
-# XXX inefficient
-class Struct(object):
-    def __init__(self, format):
-        self.format = format
-        self.size = struct.calcsize(format)
-
-    def pack(self, *args):
-        return struct.pack(self.format, *args)
-
-    def unpack(self, s):
-        return struct.unpack(self.format, s)
-
-    def pack_into(self, buffer, offset, *args):
-        return pack_into(self.format, buffer, offset, *args)
-
-    def unpack_from(self, buffer, offset=0):
-        return unpack_from(self.format, buffer, offset)

File pypy/module/struct/interp_struct.py

-from pypy.interpreter.gateway import unwrap_spec
-from pypy.interpreter.error import OperationError
-from pypy.module.struct.formatiterator import PackFormatIterator, UnpackFormatIterator
 from rpython.rlib import jit
 from rpython.rlib.rstruct.error import StructError, StructOverflowError
 from rpython.rlib.rstruct.formatiterator import CalcSizeFormatIterator
+from rpython.tool.sourcetools import func_with_new_name
+
+from pypy.interpreter.baseobjspace import W_Root
+from pypy.interpreter.gateway import interp2app, unwrap_spec
+from pypy.interpreter.error import OperationError
+from pypy.interpreter.typedef import TypeDef, interp_attrproperty
+from pypy.module.struct.formatiterator import (
+    PackFormatIterator, UnpackFormatIterator
+)
 
 
 @unwrap_spec(format=str)
 def calcsize(space, format):
     return space.wrap(_calcsize(space, format))
 
+
 def _calcsize(space, format):
     fmtiter = CalcSizeFormatIterator()
     try:
         w_error = space.getattr(w_module, space.wrap('error'))
         raise OperationError(w_error, space.wrap(e.msg))
     return space.newtuple(fmtiter.result_w[:])
+
+
+class W_Struct(W_Root):
+    _immutable_fields_ = ["format", "size"]
+
+    def __init__(self, space, format):
+        self.format = format
+        self.size = _calcsize(space, format)
+
+    @unwrap_spec(format=str)
+    def descr__new__(space, w_subtype, format):
+        self = space.allocate_instance(W_Struct, w_subtype)
+        W_Struct.__init__(self, space, format)
+        return self
+
+    def wrap_struct_method(name):
+        def impl(self, space, __args__):
+            w_module = space.getbuiltinmodule('struct')
+            w_method = space.getattr(w_module, space.wrap(name))
+            return space.call_obj_args(
+                w_method, space.wrap(self.format), __args__
+            )
+
+        return func_with_new_name(impl, 'descr_' + name)
+
+    descr_pack = wrap_struct_method("pack")
+    descr_unpack = wrap_struct_method("unpack")
+    descr_pack_into = wrap_struct_method("pack_into")
+    descr_unpack_from = wrap_struct_method("unpack_from")
+
+
+W_Struct.typedef = TypeDef("Struct",
+    __new__=interp2app(W_Struct.descr__new__.im_func),
+    format=interp_attrproperty("format", cls=W_Struct),
+    size=interp_attrproperty("size", cls=W_Struct),
+
+    pack=interp2app(W_Struct.descr_pack),
+    unpack=interp2app(W_Struct.descr_unpack),
+    pack_into=interp2app(W_Struct.descr_pack_into),
+    unpack_from=interp2app(W_Struct.descr_unpack_from),
+)

File pypy/objspace/std/stringmethods.py

         if (isinstance(self, W_BytearrayObject) and
             space.isinstance_w(w_sub, space.w_int)):
             char = space.int_w(w_sub)
-            if not 0 <= char < 256:
-                raise OperationError(space.w_ValueError,
-                                     space.wrap("byte must be in range(0, 256)"))
-            for c in self.data:
-                if ord(c) == char:
-                    return space.w_True
-            return space.w_False
+            return _descr_contains_bytearray(self.data, space, char)
         return space.newbool(self._val(space).find(self._op_val(space, w_sub)) >= 0)
 
     def descr_add(self, space, w_other):
                 assert start >= 0 and stop >= 0
                 return self._sliced(space, selfvalue, start, stop, self)
             else:
-                ret = [selfvalue[start + i*step] for i in range(sl)]
+                ret = _descr_getslice_slowpath(selfvalue, start, step, sl)
                 return self._new_from_list(ret)
 
         index = space.getindex_w(w_index, space.w_IndexError, "string index")
         return self._is_generic(space, '_isdigit')
 
     # this is only for bytes and bytesarray: unicodeobject overrides it
+    def _descr_islower_slowpath(self, space, v):
+        cased = False
+        for idx in range(len(v)):
+            if self._isupper(v[idx]):
+                return False
+            elif not cased and self._islower(v[idx]):
+                cased = True
+        return cased
+
     def descr_islower(self, space):
         v = self._val(space)
         if len(v) == 1:
             c = v[0]
             return space.newbool(self._islower(c))
-        cased = False
-        for idx in range(len(v)):
-            if self._isupper(v[idx]):
-                return space.w_False
-            elif not cased and self._islower(v[idx]):
-                cased = True
+        cased = self._descr_islower_slowpath(space, v)
         return space.newbool(cased)
 
     def descr_isspace(self, space):
         return space.newbool(cased)
 
     # this is only for bytes and bytesarray: unicodeobject overrides it
+    def _descr_isupper_slowpath(self, space, v):
+        cased = False
+        for idx in range(len(v)):
+            if self._islower(v[idx]):
+                return False
+            elif not cased and self._isupper(v[idx]):
+                cased = True
+        return cased
+
     def descr_isupper(self, space):
         v = self._val(space)
         if len(v) == 1:
             c = v[0]
             return space.newbool(self._isupper(c))
-        cased = False
-        for idx in range(len(v)):
-            if self._islower(v[idx]):
-                return space.w_False
-            elif not cased and self._isupper(v[idx]):
-                cased = True
+        cased = self._descr_isupper_slowpath(space, v)
         return space.newbool(cased)
 
     def descr_join(self, space, w_list):
 
     def descr_getnewargs(self, space):
         return space.newtuple([self._new(self._val(space))])
+
+# ____________________________________________________________
+# helpers for slow paths, moved out because they contain loops
+
+def _descr_contains_bytearray(data, space, char):
+    if not 0 <= char < 256:
+        raise OperationError(space.w_ValueError,
+                             space.wrap("byte must be in range(0, 256)"))
+    for c in data:
+        if ord(c) == char:
+            return space.w_True
+    return space.w_False
+
+@specialize.argtype(0)
+def _descr_getslice_slowpath(selfvalue, start, step, sl):
+    return [selfvalue[start + i*step] for i in range(sl)]

File rpython/jit/backend/llsupport/gc.py

         unicode_ofs_length = self.unicode_descr.lendescr.offset
 
         def malloc_str(length):
+            type_id = llop.extract_ushort(llgroup.HALFWORD, str_type_id)
             return llop1.do_malloc_varsize_clear(
                 llmemory.GCREF,
-                str_type_id, length, str_basesize, str_itemsize,
+                type_id, length, str_basesize, str_itemsize,
                 str_ofs_length)
         self.generate_function('malloc_str', malloc_str,
                                [lltype.Signed])
 
         def malloc_unicode(length):
+            type_id = llop.extract_ushort(llgroup.HALFWORD, unicode_type_id)
             return llop1.do_malloc_varsize_clear(
                 llmemory.GCREF,
-                unicode_type_id, length, unicode_basesize, unicode_itemsize,
+                type_id, length, unicode_basesize, unicode_itemsize,
                 unicode_ofs_length)
         self.generate_function('malloc_unicode', malloc_unicode,
                                [lltype.Signed])

File rpython/rlib/ropenssl.py

 
 ASN1_STRING = lltype.Ptr(lltype.ForwardReference())
 ASN1_ITEM = rffi.COpaquePtr('ASN1_ITEM')
-ASN1_ITEM_EXP = lltype.Ptr(lltype.FuncType([], ASN1_ITEM))
 X509_NAME = rffi.COpaquePtr('X509_NAME')
 
+class CConfigBootstrap:
+    _compilation_info_ = eci
+    OPENSSL_EXPORT_VAR_AS_FUNCTION = rffi_platform.Defined(
+            "OPENSSL_EXPORT_VAR_AS_FUNCTION")
+if rffi_platform.configure(CConfigBootstrap)["OPENSSL_EXPORT_VAR_AS_FUNCTION"]:
+    ASN1_ITEM_EXP = lltype.Ptr(lltype.FuncType([], ASN1_ITEM))
+else:
+    ASN1_ITEM_EXP = ASN1_ITEM
+
 class CConfig:
     _compilation_info_ = eci
 
          ('block_size', rffi.INT)])
     EVP_MD_SIZE = rffi_platform.SizeOf('EVP_MD')
     EVP_MD_CTX_SIZE = rffi_platform.SizeOf('EVP_MD_CTX')
-    OPENSSL_EXPORT_VAR_AS_FUNCTION = rffi_platform.Defined(
-                                             "OPENSSL_EXPORT_VAR_AS_FUNCTION")
 
     OBJ_NAME_st = rffi_platform.Struct(
         'OBJ_NAME',
 ssl_external('i2a_ASN1_INTEGER', [BIO, ASN1_INTEGER], rffi.INT)
 ssl_external('ASN1_item_d2i',
              [rffi.VOIDP, rffi.CCHARPP, rffi.LONG, ASN1_ITEM], rffi.VOIDP)
-if OPENSSL_EXPORT_VAR_AS_FUNCTION:
-    ssl_external('ASN1_ITEM_ptr', [ASN1_ITEM_EXP], ASN1_ITEM, macro=True)
-else:
-    ssl_external('ASN1_ITEM_ptr', [rffi.VOIDP], ASN1_ITEM, macro=True)
+ssl_external('ASN1_ITEM_ptr', [ASN1_ITEM_EXP], ASN1_ITEM, macro=True)
 
 ssl_external('sk_GENERAL_NAME_num', [GENERAL_NAMES], rffi.INT,
              macro=True)

File rpython/rtyper/lltypesystem/lloperation.py

 #
 # This list corresponds to the operations implemented by the LLInterpreter.
 # Note that many exception-raising operations can be replaced by calls
-# to helper functions in rpython.rtyper.raisingops.raisingops.
+# to helper functions in rpython.rtyper.raisingops.
 # ***** Run test_lloperation after changes. *****
 
 LL_OPERATIONS = {

File rpython/rtyper/raisingops.py

+import sys
+from rpython.rlib.rarithmetic import r_longlong, r_uint, intmask
+from rpython.rtyper.lltypesystem.lloperation import llop
+from rpython.rtyper.lltypesystem.lltype import Signed, SignedLongLong, \
+                                        UnsignedLongLong
+
+#XXX original SIGNED_RIGHT_SHIFT_ZERO_FILLS not taken into account
+#XXX assuming HAVE_LONG_LONG (int_mul_ovf)
+#XXX should int_mod and int_floordiv return an intmask(...) instead?
+
+LONG_MAX = sys.maxint
+LONG_MIN = -sys.maxint-1
+
+LLONG_MAX = r_longlong(2 ** (r_longlong.BITS-1) - 1)
+LLONG_MIN = -LLONG_MAX-1
+
+def int_floordiv_zer(x, y):
+    '''#define OP_INT_FLOORDIV_ZER(x,y,r,err) \
+        if ((y)) { OP_INT_FLOORDIV(x,y,r,err); } \
+        else FAIL_ZER(err, "integer division")
+    '''
+    if y:
+        return llop.int_floordiv(Signed, x, y)
+    else:
+        raise ZeroDivisionError("integer division")
+
+def uint_floordiv_zer(x, y):
+    '''#define OP_UINT_FLOORDIV_ZER(x,y,r,err) \
+        if ((y)) { OP_UINT_FLOORDIV(x,y,r,err); } \
+        else FAIL_ZER(err, "unsigned integer division")
+    '''
+    if y:
+        return x / y
+    else:
+        raise ZeroDivisionError("unsigned integer division")
+
+def llong_floordiv_zer(x, y):
+    '''#define OP_LLONG_FLOORDIV_ZER(x,y,r) \
+      if ((y)) { OP_LLONG_FLOORDIV(x,y,r); } \
+      else FAIL_ZER("integer division")
+    '''
+    if y:
+        return llop.llong_floordiv(SignedLongLong, x, y)
+    else:
+        raise ZeroDivisionError("integer division")
+
+def ullong_floordiv_zer(x, y):
+    '''#define OP_ULLONG_FLOORDIV_ZER(x,y,r) \
+      if ((y)) { OP_ULLONG_FLOORDIV(x,y,r); } \
+      else FAIL_ZER("unsigned integer division")
+    '''
+    if y:
+        return llop.llong_floordiv(UnsignedLongLong, x, y)
+    else:
+        raise ZeroDivisionError("unsigned integer division")
+
+
+def int_neg_ovf(x):
+    if x == LONG_MIN:
+        raise OverflowError("integer negate")
+    return -x
+
+def llong_neg_ovf(x):
+    if x == LLONG_MIN:
+        raise OverflowError("integer negate")
+    return -x
+
+def int_abs_ovf(x):
+    if x == LONG_MIN:
+        raise OverflowError("integer absolute")
+    if x < 0:
+        return -x
+    else:
+        return x
+
+def llong_abs_ovf(x):
+    if x == LLONG_MIN:
+        raise OverflowError("integer absolute")
+    if x < 0:
+        return -x
+    else:
+        return x
+
+def int_add_ovf(x, y):
+    '''#define OP_INT_ADD_OVF(x,y,r,err) \
+        OP_INT_ADD(x,y,r,err); \
+        if ((r^(x)) >= 0 || (r^(y)) >= 0); \
+        else FAIL_OVF(err, "integer addition")
+    '''
+    r = x + y
+    if r^x >= 0 or r^y >= 0:
+        return r
+    else:
+        raise OverflowError("integer addition")
+
+def int_add_nonneg_ovf(x, y):
+    '''
+    OP_INT_ADD(x,y,r); \
+    if (r >= (x)); \
+    else FAIL_OVF("integer addition")
+    '''
+    r = x + y
+    if r >= x:
+        return r
+    else:
+        raise OverflowError("integer addition")
+
+def int_sub_ovf(x, y):
+    '''#define OP_INT_SUB_OVF(x,y,r,err) \
+        OP_INT_SUB(x,y,r,err); \
+        if ((r^(x)) >= 0 || (r^~(y)) >= 0); \
+        else FAIL_OVF(err, "integer subtraction")
+    '''
+    r = x - y
+    if r^x >= 0 or r^~y >= 0:
+        return r
+    else:
+        raise OverflowError("integer subtraction")
+
+def int_lshift_ovf(x, y):
+    '''#define OP_INT_LSHIFT_OVF(x,y,r,err) \
+        OP_INT_LSHIFT(x,y,r,err); \
+        if ((x) != Py_ARITHMETIC_RIGHT_SHIFT(long, r, (y))) \
+                FAIL_OVF(err, "x<<y losing bits or changing sign")
+    '''
+    r = x << y
+    if x != _Py_ARITHMETIC_RIGHT_SHIFT(r, y):
+        raise OverflowError("x<<y losing bits or changing sign")
+    else:
+        return r
+
+def int_rshift_val(x, y):
+    '''#define OP_INT_RSHIFT_VAL(x,y,r,err) \
+        if ((y) >= 0) { OP_INT_RSHIFT(x,y,r,err); } \
+        else FAIL_VAL(err, "negative shift count")
+    '''
+    if y >= 0:
+        return _Py_ARITHMETIC_RIGHT_SHIFT(x, y)
+    else:
+        raise ValueError("negative shift count")
+
+def int_lshift_val(x, y):
+    '''#define OP_INT_LSHIFT_VAL(x,y,r,err) \
+        if ((y) >= 0) { OP_INT_LSHIFT(x,y,r,err); } \
+        else FAIL_VAL(err, "negative shift count")
+    '''
+    if y >= 0:
+        return x << y
+    else:
+        raise ValueError("negative shift count")
+
+def int_lshift_ovf_val(x, y):
+    '''#define OP_INT_LSHIFT_OVF_VAL(x,y,r,err) \
+        if ((y) >= 0) { OP_INT_LSHIFT_OVF(x,y,r,err); } \
+        else FAIL_VAL(err, "negative shift count")
+    '''
+    if y >= 0:
+        return int_lshift_ovf(x, y)
+    else:
+        raise ValueError("negative shift count")
+
+def int_floordiv_ovf(x, y):
+    '''#define OP_INT_FLOORDIV_OVF(x,y,r,err) \
+        if ((y) == -1 && (x) < 0 && ((unsigned long)(x) << 1) == 0) \
+                FAIL_OVF(err, "integer division"); \
+        OP_INT_FLOORDIV(x,y,r,err)
+    '''
+    if y == -1 and x < 0 and (r_uint(x) << 1) == 0:
+        raise OverflowError("integer division")
+    else:
+        return llop.int_floordiv(Signed, x, y)
+
+def int_floordiv_ovf_zer(x, y):
+    '''#define OP_INT_FLOORDIV_OVF_ZER(x,y,r,err) \
+        if ((y)) { OP_INT_FLOORDIV_OVF(x,y,r,err); } \
+        else FAIL_ZER(err, "integer division")
+    '''
+    if y:
+        return int_floordiv_ovf(x, y)
+    else:
+        raise ZeroDivisionError("integer division")
+
+def int_mod_ovf(x, y):
+    '''#define OP_INT_MOD_OVF(x,y,r,err) \
+        if ((y) == -1 && (x) < 0 && ((unsigned long)(x) << 1) == 0) \
+                FAIL_OVF(err, "integer modulo"); \
+        OP_INT_MOD(x,y,r,err)
+    '''
+    if y == -1 and x < 0 and (r_uint(x) << 1) == 0:
+        raise OverflowError("integer modulo")
+    else:
+        return llop.int_mod(Signed, x, y)
+
+def int_mod_zer(x, y):
+    '''#define OP_INT_MOD_ZER(x,y,r,err) \
+        if ((y)) { OP_INT_MOD(x,y,r,err); } \
+        else FAIL_ZER(err, "integer modulo")
+    '''
+    if y:
+        return llop.int_mod(Signed, x, y)
+    else:
+        raise ZeroDivisionError("integer modulo")
+
+def uint_mod_zer(x, y):
+    '''#define OP_UINT_MOD_ZER(x,y,r,err) \
+        if ((y)) { OP_UINT_MOD(x,y,r,err); } \
+        else FAIL_ZER(err, "unsigned integer modulo")
+    '''
+    if y:
+        return x % y
+    else:
+        raise ZeroDivisionError("unsigned integer modulo")
+
+def int_mod_ovf_zer(x, y):
+    '''#define OP_INT_MOD_OVF_ZER(x,y,r,err) \
+        if ((y)) { OP_INT_MOD_OVF(x,y,r,err); } \
+        else FAIL_ZER(err, "integer modulo")
+    '''
+    if y:
+        return int_mod_ovf(x, y)
+    else:
+        raise ZeroDivisionError("integer modulo")
+
+def llong_mod_zer(x, y):
+    '''#define OP_LLONG_MOD_ZER(x,y,r) \
+      if ((y)) { OP_LLONG_MOD(x,y,r); } \
+      else FAIL_ZER("integer modulo")
+    '''
+    if y:
+        return llop.int_mod(SignedLongLong, x, y)
+    else:
+        raise ZeroDivisionError("integer modulo")
+
+# Helpers...
+
+def _Py_ARITHMETIC_RIGHT_SHIFT(i, j):
+    '''
+// Py_ARITHMETIC_RIGHT_SHIFT
+// C doesn't define whether a right-shift of a signed integer sign-extends
+// or zero-fills.  Here a macro to force sign extension:
+// Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J)
+//    Return I >> J, forcing sign extension.
+// Requirements:
+//    I is of basic signed type TYPE (char, short, int, long, or long long).
+//    TYPE is one of char, short, int, long, or long long, although long long
+//    must not be used except on platforms that support it.
+//    J is an integer >= 0 and strictly less than the number of bits in TYPE
+//    (because C doesn't define what happens for J outside that range either).
+// Caution:
+//    I may be evaluated more than once.
+
+#ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS
+    #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \
+            ((I) < 0 ? ~((~(unsigned TYPE)(I)) >> (J)) : (I) >> (J))
+#else
+    #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
+#endif
+    '''
+    return i >> j
+
+#XXX some code from src/int.h seems missing
+#def int_mul_ovf(x, y): #HAVE_LONG_LONG version
+#    '''{ \
+#        PY_LONG_LONG lr = (PY_LONG_LONG)(x) * (PY_LONG_LONG)(y); \
+#        r = (long)lr; \
+#        if ((PY_LONG_LONG)r == lr); \
+#        else FAIL_OVF(err, "integer multiplication"); \
+#    }
+#    '''
+#    lr = r_longlong(x) * r_longlong(y);
+#    r  = intmask(lr)
+#    if r_longlong(r) == lr:
+#        return r
+#    else:
+#        raise OverflowError("integer multiplication")
+
+#not HAVE_LONG_LONG version
+def int_mul_ovf(a, b):          #long a, long b, long *longprod):
+    longprod = a * b
+    doubleprod = float(a) * float(b)
+    doubled_longprod = float(longprod)
+
+    # Fast path for normal case:  small multiplicands, and no info is lost in either method.
+    if doubled_longprod == doubleprod:
+        return longprod
+
+    # Somebody somewhere lost info.  Close enough, or way off?  Note
+    # that a != 0 and b != 0 (else doubled_longprod == doubleprod == 0).
+    # The difference either is or isn't significant compared to the
+    # true value (of which doubleprod is a good approximation).
+    # absdiff/absprod <= 1/32 iff 32 * absdiff <= absprod -- 5 good bits is "close enough"
+    if 32.0 * abs(doubled_longprod - doubleprod) <= abs(doubleprod):
+        return longprod
+
+    raise OverflowError("integer multiplication")

File rpython/rtyper/raisingops/__init__.py

Empty file removed.

File rpython/rtyper/raisingops/raisingops.py

-import sys
-from rpython.rlib.rarithmetic import r_longlong, r_uint, intmask
-from rpython.rtyper.lltypesystem.lloperation import llop
-from rpython.rtyper.lltypesystem.lltype import Signed, SignedLongLong, \
-                                        UnsignedLongLong
-
-#XXX original SIGNED_RIGHT_SHIFT_ZERO_FILLS not taken into account
-#XXX assuming HAVE_LONG_LONG (int_mul_ovf)
-#XXX should int_mod and int_floordiv return an intmask(...) instead?
-
-LONG_MAX = sys.maxint
-LONG_MIN = -sys.maxint-1
-
-LLONG_MAX = r_longlong(2 ** (r_longlong.BITS-1) - 1)
-LLONG_MIN = -LLONG_MAX-1
-
-def int_floordiv_zer(x, y):
-    '''#define OP_INT_FLOORDIV_ZER(x,y,r,err) \
-        if ((y)) { OP_INT_FLOORDIV(x,y,r,err); } \
-        else FAIL_ZER(err, "integer division")
-    '''
-    if y:
-        return llop.int_floordiv(Signed, x, y)
-    else:
-        raise ZeroDivisionError("integer division")
-
-def uint_floordiv_zer(x, y):
-    '''#define OP_UINT_FLOORDIV_ZER(x,y,r,err) \
-        if ((y)) { OP_UINT_FLOORDIV(x,y,r,err); } \
-        else FAIL_ZER(err, "unsigned integer division")
-    '''
-    if y:
-        return x / y
-    else:
-        raise ZeroDivisionError("unsigned integer division")
-
-def llong_floordiv_zer(x, y):
-    '''#define OP_LLONG_FLOORDIV_ZER(x,y,r) \
-      if ((y)) { OP_LLONG_FLOORDIV(x,y,r); } \
-      else FAIL_ZER("integer division")
-    '''
-    if y:
-        return llop.llong_floordiv(SignedLongLong, x, y)
-    else:
-        raise ZeroDivisionError("integer division")
-
-def ullong_floordiv_zer(x, y):
-    '''#define OP_ULLONG_FLOORDIV_ZER(x,y,r) \
-      if ((y)) { OP_ULLONG_FLOORDIV(x,y,r); } \
-      else FAIL_ZER("unsigned integer division")
-    '''
-    if y:
-        return llop.llong_floordiv(UnsignedLongLong, x, y)
-    else:
-        raise ZeroDivisionError("unsigned integer division")
-
-
-def int_neg_ovf(x):
-    if x == LONG_MIN:
-        raise OverflowError("integer negate")
-    return -x
-
-def llong_neg_ovf(x):
-    if x == LLONG_MIN:
-        raise OverflowError("integer negate")
-    return -x
-
-def int_abs_ovf(x):
-    if x == LONG_MIN:
-        raise OverflowError("integer absolute")
-    if x < 0:
-        return -x
-    else:
-        return x
-
-def llong_abs_ovf(x):
-    if x == LLONG_MIN:
-        raise OverflowError("integer absolute")
-    if x < 0:
-        return -x
-    else:
-        return x
-
-def int_add_ovf(x, y):
-    '''#define OP_INT_ADD_OVF(x,y,r,err) \
-        OP_INT_ADD(x,y,r,err); \
-        if ((r^(x)) >= 0 || (r^(y)) >= 0); \
-        else FAIL_OVF(err, "integer addition")
-    '''
-    r = x + y
-    if r^x >= 0 or r^y >= 0:
-        return r
-    else:
-        raise OverflowError("integer addition")
-
-def int_add_nonneg_ovf(x, y):
-    '''
-    OP_INT_ADD(x,y,r); \
-    if (r >= (x)); \
-    else FAIL_OVF("integer addition")
-    '''
-    r = x + y
-    if r >= x:
-        return r
-    else:
-        raise OverflowError("integer addition")
-
-def int_sub_ovf(x, y):
-    '''#define OP_INT_SUB_OVF(x,y,r,err) \
-        OP_INT_SUB(x,y,r,err); \
-        if ((r^(x)) >= 0 || (r^~(y)) >= 0); \
-        else FAIL_OVF(err, "integer subtraction")
-    '''
-    r = x - y
-    if r^x >= 0 or r^~y >= 0:
-        return r
-    else:
-        raise OverflowError("integer subtraction")
-
-def int_lshift_ovf(x, y):
-    '''#define OP_INT_LSHIFT_OVF(x,y,r,err) \
-        OP_INT_LSHIFT(x,y,r,err); \
-        if ((x) != Py_ARITHMETIC_RIGHT_SHIFT(long, r, (y))) \
-                FAIL_OVF(err, "x<<y losing bits or changing sign")
-    '''
-    r = x << y
-    if x != _Py_ARITHMETIC_RIGHT_SHIFT(r, y):
-        raise OverflowError("x<<y losing bits or changing sign")
-    else:
-        return r
-
-def int_rshift_val(x, y):
-    '''#define OP_INT_RSHIFT_VAL(x,y,r,err) \
-        if ((y) >= 0) { OP_INT_RSHIFT(x,y,r,err); } \
-        else FAIL_VAL(err, "negative shift count")
-    '''
-    if y >= 0:
-        return _Py_ARITHMETIC_RIGHT_SHIFT(x, y)
-    else:
-        raise ValueError("negative shift count")
-
-def int_lshift_val(x, y):
-    '''#define OP_INT_LSHIFT_VAL(x,y,r,err) \
-        if ((y) >= 0) { OP_INT_LSHIFT(x,y,r,err); } \
-        else FAIL_VAL(err, "negative shift count")
-    '''
-    if y >= 0:
-        return x << y
-    else:
-        raise ValueError("negative shift count")
-
-def int_lshift_ovf_val(x, y):
-    '''#define OP_INT_LSHIFT_OVF_VAL(x,y,r,err) \
-        if ((y) >= 0) { OP_INT_LSHIFT_OVF(x,y,r,err); } \
-        else FAIL_VAL(err, "negative shift count")
-    '''
-    if y >= 0:
-        return int_lshift_ovf(x, y)
-    else:
-        raise ValueError("negative shift count")
-
-def int_floordiv_ovf(x, y):
-    '''#define OP_INT_FLOORDIV_OVF(x,y,r,err) \
-        if ((y) == -1 && (x) < 0 && ((unsigned long)(x) << 1) == 0) \
-                FAIL_OVF(err, "integer division"); \
-        OP_INT_FLOORDIV(x,y,r,err)
-    '''
-    if y == -1 and x < 0 and (r_uint(x) << 1) == 0:
-        raise OverflowError("integer division")
-    else:
-        return llop.int_floordiv(Signed, x, y)
-
-def int_floordiv_ovf_zer(x, y):
-    '''#define OP_INT_FLOORDIV_OVF_ZER(x,y,r,err) \
-        if ((y)) { OP_INT_FLOORDIV_OVF(x,y,r,err); } \
-        else FAIL_ZER(err, "integer division")
-    '''
-    if y:
-        return int_floordiv_ovf(x, y)
-    else:
-        raise ZeroDivisionError("integer division")
-
-def int_mod_ovf(x, y):
-    '''#define OP_INT_MOD_OVF(x,y,r,err) \
-        if ((y) == -1 && (x) < 0 && ((unsigned long)(x) << 1) == 0) \
-                FAIL_OVF(err, "integer modulo"); \
-        OP_INT_MOD(x,y,r,err)
-    '''
-    if y == -1 and x < 0 and (r_uint(x) << 1) == 0:
-        raise OverflowError("integer modulo")
-    else:
-        return llop.int_mod(Signed, x, y)
-
-def int_mod_zer(x, y):
-    '''#define OP_INT_MOD_ZER(x,y,r,err) \
-        if ((y)) { OP_INT_MOD(x,y,r,err); } \
-        else FAIL_ZER(err, "integer modulo")
-    '''
-    if y:
-        return llop.int_mod(Signed, x, y)
-    else:
-        raise ZeroDivisionError("integer modulo")
-
-def uint_mod_zer(x, y):
-    '''#define OP_UINT_MOD_ZER(x,y,r,err) \
-        if ((y)) { OP_UINT_MOD(x,y,r,err); } \
-        else FAIL_ZER(err, "unsigned integer modulo")
-    '''
-    if y:
-        return x % y
-    else:
-        raise ZeroDivisionError("unsigned integer modulo")
-
-def int_mod_ovf_zer(x, y):
-    '''#define OP_INT_MOD_OVF_ZER(x,y,r,err) \
-        if ((y)) { OP_INT_MOD_OVF(x,y,r,err); } \
-        else FAIL_ZER(err, "integer modulo")
-    '''
-    if y:
-        return int_mod_ovf(x, y)
-    else:
-        raise ZeroDivisionError("integer modulo")
-
-def llong_mod_zer(x, y):
-    '''#define OP_LLONG_MOD_ZER(x,y,r) \
-      if ((y)) { OP_LLONG_MOD(x,y,r); } \
-      else FAIL_ZER("integer modulo")
-    '''
-    if y:
-        return llop.int_mod(SignedLongLong, x, y)
-    else:
-        raise ZeroDivisionError("integer modulo")
-
-# Helpers...
-
-def _Py_ARITHMETIC_RIGHT_SHIFT(i, j):
-    '''
-// Py_ARITHMETIC_RIGHT_SHIFT
-// C doesn't define whether a right-shift of a signed integer sign-extends
-// or zero-fills.  Here a macro to force sign extension:
-// Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J)
-//    Return I >> J, forcing sign extension.
-// Requirements:
-//    I is of basic signed type TYPE (char, short, int, long, or long long).
-//    TYPE is one of char, short, int, long, or long long, although long long
-//    must not be used except on platforms that support it.
-//    J is an integer >= 0 and strictly less than the number of bits in TYPE
-//    (because C doesn't define what happens for J outside that range either).
-// Caution:
-//    I may be evaluated more than once.
-
-#ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS
-    #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \
-            ((I) < 0 ? ~((~(unsigned TYPE)(I)) >> (J)) : (I) >> (J))
-#else
-    #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
-#endif
-    '''
-    return i >> j
-
-#XXX some code from src/int.h seems missing
-#def int_mul_ovf(x, y): #HAVE_LONG_LONG version
-#    '''{ \
-#        PY_LONG_LONG lr = (PY_LONG_LONG)(x) * (PY_LONG_LONG)(y); \
-#        r = (long)lr; \
-#        if ((PY_LONG_LONG)r == lr); \
-#        else FAIL_OVF(err, "integer multiplication"); \
-#    }
-#    '''
-#    lr = r_longlong(x) * r_longlong(y);
-#    r  = intmask(lr)
-#    if r_longlong(r) == lr:
-#        return r
-#    else:
-#        raise OverflowError("integer multiplication")
-
-#not HAVE_LONG_LONG version
-def int_mul_ovf(a, b):          #long a, long b, long *longprod):
-    longprod = a * b
-    doubleprod = float(a) * float(b)
-    doubled_longprod = float(longprod)
-
-    # Fast path for normal case:  small multiplicands, and no info is lost in either method.
-    if doubled_longprod == doubleprod:
-        return longprod
-
-    # Somebody somewhere lost info.  Close enough, or way off?  Note
-    # that a != 0 and b != 0 (else doubled_longprod == doubleprod == 0).
-    # The difference either is or isn't significant compared to the
-    # true value (of which doubleprod is a good approximation).
-    # absdiff/absprod <= 1/32 iff 32 * absdiff <= absprod -- 5 good bits is "close enough"
-    if 32.0 * abs(doubled_longprod - doubleprod) <= abs(doubleprod):
-        return longprod
-
-    raise OverflowError("integer multiplication")

File rpython/translator/backendopt/raisingop2direct_call.py

 from rpython.translator.backendopt.support import log, all_operations, annotate
-import rpython.rtyper.raisingops.raisingops
+import rpython.rtyper.raisingops
 
 
 log = log.raisingop2directcall
 
 def raisingop2direct_call(translator, graphs=None):
     """search for operations that could raise an exception and change that
-    operation into a direct_call to a function from the raisingops directory.
+    operation into a direct_call to a function from the raisingops module.
     This function also needs to be annotated and specialized.
 
     note: this could be extended to allow for any operation to be changed into
     for op in all_operations(graphs):
         if not is_raisingop(op):
             continue
-        func = getattr(rpython.rtyper.raisingops.raisingops, op.opname, None)
+        func = getattr(rpython.rtyper.raisingops, op.opname, None)
         if not func:
             log.warning("%s not found" % op.opname)
             continue

File rpython/translator/driver.py

 # TODO:
 # sanity-checks using states
 
-_BACKEND_TO_TYPESYSTEM = {
-    'c': 'lltype',
-}
-
-def backend_to_typesystem(backend):
-    return _BACKEND_TO_TYPESYSTEM[backend]
-
 # set of translation steps to profile
 PROFILE = set([])
 
                         if backend == postfix:
                             expose_task(task, explicit_task)
                     elif ts:
-                        if ts == backend_to_typesystem(postfix):
+                        if ts == 'lltype':
                             expose_task(explicit_task)
                     else:
                         expose_task(explicit_task)