Author: Christian Tismer <tis...@stackless.com>
Branch: win64-stage1
Changeset: r49800:d46af2518d03
Date: 2011-11-26 01:03 +0100
http://bitbucket.org/pypy/pypy/changeset/d46af2518d03/

Log:    Merge

diff --git a/pypy/jit/backend/test/runner_test.py 
b/pypy/jit/backend/test/runner_test.py
--- a/pypy/jit/backend/test/runner_test.py
+++ b/pypy/jit/backend/test/runner_test.py
@@ -16,7 +16,7 @@
 from pypy.rpython.annlowlevel import llhelper
 from pypy.rpython.llinterp import LLException
 from pypy.jit.codewriter import heaptracker, longlong
-from pypy.rlib.rarithmetic import intmask
+from pypy.rlib.rarithmetic import intmask, is_valid_int
 
 def boxfloat(x):
     return BoxFloat(longlong.getfloatstorage(x))
@@ -454,7 +454,7 @@
         if cpu.supports_floats:
             def func(f, i):
                 assert isinstance(f, float)
-                assert isinstance(i, (int, long))
+                assert is_valid_int(i)
                 return f - float(i)
             FPTR = self.Ptr(self.FuncType([lltype.Float, lltype.Signed],
                                           lltype.Float))
diff --git a/pypy/jit/backend/test/support.py b/pypy/jit/backend/test/support.py
--- a/pypy/jit/backend/test/support.py
+++ b/pypy/jit/backend/test/support.py
@@ -3,6 +3,7 @@
 from pypy.rlib.debug import debug_print
 from pypy.translator.translator import TranslationContext, graphof
 from pypy.jit.metainterp.optimizeopt import ALL_OPTS_NAMES
+from pypy.rlib.rarithmetic import is_valid_int
 
 class BaseCompiledMixin(object):
 
@@ -24,7 +25,7 @@
         from pypy.annotation import model as annmodel
 
         for arg in args:
-            assert isinstance(arg, (int, long))
+            assert is_valid_int(arg)
 
         self.pre_translation_hook()
         t = self._get_TranslationContext()
diff --git a/pypy/jit/codewriter/test/test_longlong.py 
b/pypy/jit/codewriter/test/test_longlong.py
--- a/pypy/jit/codewriter/test/test_longlong.py
+++ b/pypy/jit/codewriter/test/test_longlong.py
@@ -1,6 +1,6 @@
 import py, sys
 
-from pypy.rlib.rarithmetic import r_longlong, intmask
+from pypy.rlib.rarithmetic import r_longlong, intmask, is_valid_int
 from pypy.objspace.flow.model import SpaceOperation, Variable, Constant
 from pypy.objspace.flow.model import Block, Link
 from pypy.translator.unsimplify import varoftype
@@ -32,7 +32,7 @@
 def test_functions():
     xll = longlong.getfloatstorage(3.5)
     assert longlong.getrealfloat(xll) == 3.5
-    assert isinstance(longlong.gethash(xll), (int, long))
+    assert is_valid_int(longlong.gethash(xll))
 
 
 class TestLongLong:
diff --git a/pypy/jit/metainterp/executor.py b/pypy/jit/metainterp/executor.py
--- a/pypy/jit/metainterp/executor.py
+++ b/pypy/jit/metainterp/executor.py
@@ -2,7 +2,7 @@
 """
 
 from pypy.rpython.lltypesystem import lltype, rstr
-from pypy.rlib.rarithmetic import ovfcheck, r_longlong
+from pypy.rlib.rarithmetic import ovfcheck, r_longlong, is_valid_int
 from pypy.rlib.rtimer import read_timestamp
 from pypy.rlib.unroll import unrolling_iterable
 from pypy.jit.metainterp.history import BoxInt, BoxPtr, BoxFloat, check_descr
@@ -248,7 +248,7 @@
 def do_read_timestamp(cpu, _):
     x = read_timestamp()
     if longlong.is_64_bit:
-        assert isinstance(x, (int, long))         # 64-bit
+        assert is_valid_int(x)            # 64-bit
         return BoxInt(x)
     else:
         assert isinstance(x, r_longlong)  # 32-bit
diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py
--- a/pypy/jit/metainterp/history.py
+++ b/pypy/jit/metainterp/history.py
@@ -4,7 +4,8 @@
 from pypy.rpython.ootypesystem import ootype
 from pypy.rlib.objectmodel import we_are_translated, r_dict, Symbolic
 from pypy.rlib.objectmodel import compute_unique_id
-from pypy.rlib.rarithmetic import r_int64
+from pypy.rlib.rarithmetic import r_int64, is_valid_int
+
 from pypy.conftest import option
 
 from pypy.jit.metainterp.resoperation import ResOperation, rop
@@ -268,7 +269,7 @@
 
     def __init__(self, value):
         if not we_are_translated():
-            if isinstance(value, (int, long)):
+            if is_valid_int(value, force_type=False):
                 value = int(value)    # bool -> int
             else:
                 assert isinstance(value, Symbolic)
diff --git a/pypy/jit/metainterp/optimizeopt/vstring.py 
b/pypy/jit/metainterp/optimizeopt/vstring.py
--- a/pypy/jit/metainterp/optimizeopt/vstring.py
+++ b/pypy/jit/metainterp/optimizeopt/vstring.py
@@ -10,6 +10,8 @@
 from pypy.rlib.unroll import unrolling_iterable
 from pypy.rpython import annlowlevel
 from pypy.rpython.lltypesystem import lltype, rstr
+from pypy.rlib.rarithmetic import is_valid_int
+
 
 
 class StrOrUnicode(object):
@@ -713,7 +715,7 @@
     for name in dir(OptString):
         if name.startswith(prefix):
             value = getattr(EffectInfo, 'OS_' + name[len(prefix):])
-            assert isinstance(value, (int, long)) and value != 0
+            assert is_valid_int(value) and value != 0
             result.append((value, getattr(OptString, name)))
     return unrolling_iterable(result)
 opt_call_oopspec_ops = _findall_call_oopspec()
diff --git a/pypy/jit/tl/tlc.py b/pypy/jit/tl/tlc.py
--- a/pypy/jit/tl/tlc.py
+++ b/pypy/jit/tl/tlc.py
@@ -6,6 +6,8 @@
 from pypy.jit.tl.tlopcode import *
 from pypy.jit.tl import tlopcode
 from pypy.rlib.jit import JitDriver, elidable
+from pypy.rlib.rarithmetic import is_valid_int
+
 
 class Obj(object):
 
@@ -219,7 +221,7 @@
 class Frame(object):
 
     def __init__(self, args, pc):
-        assert isinstance(pc, (int, long))
+        assert is_valid_int(pc)
         self.args  = args
         self.pc    = pc
         self.stack = []
diff --git a/pypy/module/_ffi/test/test__ffi.py 
b/pypy/module/_ffi/test/test__ffi.py
--- a/pypy/module/_ffi/test/test__ffi.py
+++ b/pypy/module/_ffi/test/test__ffi.py
@@ -4,6 +4,8 @@
 from pypy.module._rawffi.interp_rawffi import TYPEMAP
 from pypy.module._rawffi.tracker import Tracker
 from pypy.translator.platform import platform
+from pypy.rlib.rarithmetic import is_valid_int
+
 
 import os, sys, py
 
@@ -182,7 +184,7 @@
                                         types.void)
         assert get_dummy() == 0
         ptr = get_dummy_ptr()
-        assert type(ptr) in (int, long)
+        assert is_valid_int(ptr)
         ptr2 = MyPointerWrapper(ptr)
         set_val_to_ptr(ptr2, 123)
         assert get_dummy() == 123
diff --git a/pypy/module/_multiprocessing/test/test_semaphore.py 
b/pypy/module/_multiprocessing/test/test_semaphore.py
--- a/pypy/module/_multiprocessing/test/test_semaphore.py
+++ b/pypy/module/_multiprocessing/test/test_semaphore.py
@@ -1,6 +1,8 @@
 from pypy.conftest import gettestobjspace
 from pypy.module._multiprocessing.interp_semaphore import (
     RECURSIVE_MUTEX, SEMAPHORE)
+from pypy.rlib.rarithmetic import is_valid_int
+
 
 class AppTestSemaphore:
     def setup_class(cls):
@@ -20,7 +22,7 @@
         sem = SemLock(kind, value, maxvalue)
         assert sem.kind == kind
         assert sem.maxvalue == maxvalue
-        assert isinstance(sem.handle, (int, long))
+        assert is_valid_int(sem.handle)
 
         assert sem._count() == 0
         if sys.platform == 'darwin':
diff --git a/pypy/module/_ssl/test/test_ssl.py 
b/pypy/module/_ssl/test/test_ssl.py
--- a/pypy/module/_ssl/test/test_ssl.py
+++ b/pypy/module/_ssl/test/test_ssl.py
@@ -1,6 +1,8 @@
 from pypy.conftest import gettestobjspace
 import os
 import py
+from pypy.rlib.rarithmetic import is_valid_int
+
 
 class AppTestSSL:
     def setup_class(cls):
@@ -29,7 +31,7 @@
         assert isinstance(_ssl.SSL_ERROR_EOF, int)
         assert isinstance(_ssl.SSL_ERROR_INVALID_ERROR_CODE, int)
 
-        assert isinstance(_ssl.OPENSSL_VERSION_NUMBER, (int, long))
+        assert is_valid_int(_ssl.OPENSSL_VERSION_NUMBER)
         assert isinstance(_ssl.OPENSSL_VERSION_INFO, tuple)
         assert len(_ssl.OPENSSL_VERSION_INFO) == 5
         assert isinstance(_ssl.OPENSSL_VERSION, str)
diff --git a/pypy/module/micronumpy/test/test_dtypes.py 
b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -1,4 +1,5 @@
 from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest
+from pypy.rlib.rarithmetic import is_valid_int
 
 
 class AppTestDtypes(BaseNumpyAppTest):
@@ -48,9 +49,9 @@
 
         a = array([0, 1, 2, 3], dtype=long)
         # int on 64-bit, long in 32-bit
-        assert isinstance(a[0], (int, long))
+        assert is_valid_int(a[0])
         b = a.copy()
-        assert isinstance(b[0], (int, long))
+        assert is_valid_int(b[0])
 
         a = array([0, 1, 2, 3], dtype=bool)
         assert a[0] is False_
@@ -75,14 +76,14 @@
         from numpypy import zeros
         a = zeros(10, dtype=long)
         for i in range(10):
-            assert isinstance(a[i], (int, long))
+            assert is_valid_int(a[i])
             assert a[1] == 0
 
     def test_ones_long(self):
         from numpypy import ones
         a = ones(10, dtype=long)
         for i in range(10):
-            assert isinstance(a[i], (int, long))
+            assert is_valid_int(a[i])
             assert a[1] == 1
 
     def test_overflow(self):
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
@@ -1,4 +1,4 @@
-
+from pypy.rlib.rarithmetic import is_valid_int
 from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest
 
 
@@ -140,7 +140,7 @@
 
         x = maximum(2, 3)
         assert x == 3
-        assert isinstance(x, (int, long))
+        assert is_valid_int(x)
 
     def test_multiply(self):
         from numpypy import array, multiply
diff --git a/pypy/module/operator/app_operator.py 
b/pypy/module/operator/app_operator.py
--- a/pypy/module/operator/app_operator.py
+++ b/pypy/module/operator/app_operator.py
@@ -5,6 +5,8 @@
 equivalent to x+y.
 '''
 from __pypy__ import builtinify
+from pypy.rlib.rarithmetic import is_valid_int
+
 
 def countOf(a,b): 
     'countOf(a, b) -- Return the number of times b occurs in a.'
@@ -53,7 +55,7 @@
 
 def repeat(obj, num):
     'repeat(a, b) -- Return a * b, where a is a sequence, and b is an integer.'
-    if not isinstance(num, (int, long)):
+    if not is_valid_int(num):
         raise TypeError, 'an integer is required'
     if not isSequenceType(obj):
         raise TypeError, "non-sequence object can't be repeated"
diff --git a/pypy/module/posix/test/test_posix2.py 
b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -7,6 +7,8 @@
 from pypy.conftest import gettestobjspace
 from pypy.tool.autopath import pypydir
 from pypy.rpython.module.ll_os import RegisterOs
+from pypy.rlib.rarithmetic import is_valid_int
+
 import os
 import py
 import sys
@@ -147,7 +149,7 @@
 
             posix.stat_float_times(False)
             st = posix.stat(path)
-            assert isinstance(st.st_mtime, (int, long))
+            assert is_valid_int(st.st_mtime)
             assert st[7] == st.st_atime
         finally:
             posix.stat_float_times(current)
diff --git a/pypy/module/signal/interp_signal.py 
b/pypy/module/signal/interp_signal.py
--- a/pypy/module/signal/interp_signal.py
+++ b/pypy/module/signal/interp_signal.py
@@ -11,11 +11,11 @@
 import sys
 from pypy.tool import autopath
 from pypy.rlib import jit, rposix
-from pypy.rlib.rarithmetic import intmask
+from pypy.rlib.rarithmetic import intmask, is_valid_int
 
 def setup():
     for key, value in cpy_signal.__dict__.items():
-        if key.startswith('SIG') and isinstance(value, (int, long)):
+        if key.startswith('SIG') and is_valid_int(value):
             globals()[key] = value
             yield key
 
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_as_parameter.py 
b/pypy/module/test_lib_pypy/ctypes_tests/test_as_parameter.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_as_parameter.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_as_parameter.py
@@ -1,6 +1,8 @@
 from ctypes import *
 import py
 from support import BaseCTypesTestChecker
+from pypy.rlib.rarithmetic import is_valid_int
+
 
 def setup_module(mod):
     import conftest
@@ -136,7 +138,7 @@
         f.argtypes = [c_longlong, MyCallback]
 
         def callback(value):
-            assert isinstance(value, (int, long))
+            assert is_valid_int(value)
             return value & 0x7FFFFFFF
 
         cb = MyCallback(callback)
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py 
b/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py
@@ -9,6 +9,8 @@
 import sys
 import py
 from support import BaseCTypesTestChecker
+from pypy.rlib.rarithmetic import is_valid_int
+
 
 try:
     WINFUNCTYPE
@@ -327,7 +329,7 @@
         f.argtypes = [c_longlong, MyCallback]
 
         def callback(value):
-            assert isinstance(value, (int, long))
+            assert is_valid_int(value)
             return value & 0x7FFFFFFF
 
         cb = MyCallback(callback)
diff --git a/pypy/objspace/flow/model.py b/pypy/objspace/flow/model.py
--- a/pypy/objspace/flow/model.py
+++ b/pypy/objspace/flow/model.py
@@ -8,6 +8,8 @@
 from pypy.tool.descriptor import roproperty
 from pypy.tool.sourcetools import PY_IDENTIFIER, nice_repr_for_func
 from pypy.tool.identity_dict import identity_dict
+from pypy.rlib.rarithmetic import is_valid_int
+
 
 """
     memory size before and after introduction of __slots__
@@ -546,7 +548,7 @@
                     cases = [link.exitcase for link in block.exits]
                     has_default = cases[-1] == 'default'
                     for n in cases[:len(cases)-has_default]:
-                        if isinstance(n, (int, long)):
+                        if is_valid_int(n, force_type=False):
                             continue
                         if isinstance(n, (str, unicode)) and len(n) == 1:
                             continue
diff --git a/pypy/objspace/flow/objspace.py b/pypy/objspace/flow/objspace.py
--- a/pypy/objspace/flow/objspace.py
+++ b/pypy/objspace/flow/objspace.py
@@ -13,6 +13,7 @@
 from pypy.objspace.flow import flowcontext, operation, specialcase
 from pypy.rlib.unroll import unrolling_iterable, _unroller
 from pypy.rlib import rstackovf, rarithmetic
+from pypy.rlib.rarithmetic import is_valid_int
 
 
 # method-wrappers have not enough introspection in CPython
@@ -134,7 +135,7 @@
     def int_w(self, w_obj):
         if isinstance(w_obj, Constant):
             val = w_obj.value
-            if type(val) not in (int,long):
+            if not is_valid_int(val):
                 raise TypeError("expected integer: " + repr(w_obj))
             return val
         return self.unwrap(w_obj)
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -160,7 +160,7 @@
         if isinstance(x, OperationError):
             raise TypeError, ("attempt to wrap already wrapped exception: %s"%
                               (x,))
-        if isinstance(x, (int, long)) and is_valid_int(x):
+        if is_valid_int(x, force_type=False):
             if isinstance(x, bool):
                 return self.newbool(x)
             else:
diff --git a/pypy/objspace/std/test/test_listobject.py 
b/pypy/objspace/std/test/test_listobject.py
--- a/pypy/objspace/std/test/test_listobject.py
+++ b/pypy/objspace/std/test/test_listobject.py
@@ -2,6 +2,7 @@
 import random
 from pypy.objspace.std.listobject import W_ListObject
 from pypy.interpreter.error import OperationError
+from pypy.rlib.rarithmetic import is_valid_int
 
 from pypy.conftest import gettestobjspace, option
 
@@ -201,7 +202,7 @@
                 self.space.raises_w(self.space.w_IndexError,
                                     self.space.setitem, w_list, w(key), w(42))
             else:
-                if isinstance(value, (int, long)):   # non-slicing
+                if is_valid_int(value, force_type=False):   # non-slicing
                     if random.random() < 0.25:   # deleting
                         self.space.delitem(w_list, w(key))
                         del expected[key]
diff --git a/pypy/rlib/debug.py b/pypy/rlib/debug.py
--- a/pypy/rlib/debug.py
+++ b/pypy/rlib/debug.py
@@ -1,5 +1,7 @@
 import sys, time
 from pypy.rpython.extregistry import ExtRegistryEntry
+from pypy.rlib.rarithmetic import is_valid_int
+
 
 def ll_assert(x, msg):
     """After translation to C, this becomes an RPyAssert."""
@@ -325,7 +327,7 @@
     """Give a translation-time error if 'x' is not a plain int
     (e.g. if it's a r_longlong or an r_uint).
     """
-    assert isinstance(x, (int, long))
+    assert is_valid_int(x)
     return x
 
 class Entry(ExtRegistryEntry):
diff --git a/pypy/rlib/rarithmetic.py b/pypy/rlib/rarithmetic.py
--- a/pypy/rlib/rarithmetic.py
+++ b/pypy/rlib/rarithmetic.py
@@ -136,7 +136,12 @@
 # the replacement for sys.maxint
 maxint = int(LONG_TEST - 1)
 
-def is_valid_int(r):
+def is_valid_int(r, force_type=True):
+    if force_type:
+        assert isinstance(r, (int, long))
+    else:
+        if not isinstance(r, (int, long)):
+            return False
     return -maxint - 1 <= r <= maxint
 
 def ovfcheck(r):
@@ -146,8 +151,8 @@
     assert not isinstance(r, r_uint), "unexpected ovf check on unsigned"
     assert not isinstance(r, r_longlong), "ovfcheck not supported on 
r_longlong"
     assert not isinstance(r, r_ulonglong), "ovfcheck not supported on 
r_ulonglong"
-    if type(r) is long and not is_valid_int(r):
-        # the type check is needed to make ovfcheck skip symbolics.
+    if not is_valid_int(r, force_type=False):
+        # checks only if applicable to r's type.
         # this happens in the garbage collector.
         raise OverflowError, "signed integer expression did overflow"
     return r
diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py
--- a/pypy/rlib/rbigint.py
+++ b/pypy/rlib/rbigint.py
@@ -49,14 +49,14 @@
 
 def _widen_digit(x):
     if not we_are_translated():
-        assert isinstance(x, (int, long)) and is_valid_int(x), "widen_digit() 
takes an int, got a %r" % type(x)
+        assert is_valid_int(x), "widen_digit() takes an int, got a %r" % 
type(x)
     if SHIFT <= 15:
         return int(x)
     return r_longlong(x)
 
 def _store_digit(x):
     if not we_are_translated():
-        assert isinstance(x, (int, long)) and is_valid_int(x), "store_digit() 
takes an int, got a %r" % type(x)
+        assert is_valid_int(x), "store_digit() takes an int, got a %r" % 
type(x)
     if SHIFT <= 15:
         return rffi.cast(rffi.SHORT, x)
     elif SHIFT <= 31:
diff --git a/pypy/rlib/rerased.py b/pypy/rlib/rerased.py
--- a/pypy/rlib/rerased.py
+++ b/pypy/rlib/rerased.py
@@ -24,11 +24,11 @@
 from pypy.rpython.lltypesystem.rclass import OBJECTPTR
 from pypy.rpython.lltypesystem import lltype, llmemory
 from pypy.rpython.error import TyperError
-
+from pypy.rlib.rarithmetic import is_valid_int
 
 
 def erase_int(x):
-    assert isinstance(x, (int, long))
+    assert is_valid_int(x)
     res = 2 * x + 1
     if res > sys.maxint or res < -sys.maxint - 1:
         raise OverflowError
@@ -36,7 +36,7 @@
 
 def unerase_int(y):
     assert y._identity is _identity_for_ints
-    assert isinstance(y._x, (int, long))
+    assert is_valid_int(y._x)
     return y._x
 
 
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
+from pypy.rlib.rarithmetic import r_ulonglong, is_valid_int
 from pypy.rpython.lltypesystem import lltype, llmemory, lloperation, llheap
 from pypy.rpython.lltypesystem import rclass
 from pypy.rpython.ootypesystem import ootype
@@ -1018,22 +1018,22 @@
     # Overflow-detecting variants
 
     def op_int_neg_ovf(self, x):
-        assert isinstance(x, (int, long))
+        assert is_valid_int(x)
         try:
             return ovfcheck(-x)
         except OverflowError:
             self.make_llexception()
 
     def op_int_abs_ovf(self, x):
-        assert isinstance(x, (int, long))
+        assert is_valid_int(x)
         try:
             return ovfcheck(abs(x))
         except OverflowError:
             self.make_llexception()
 
     def op_int_lshift_ovf(self, x, y):
-        assert isinstance(x, (int, long))
-        assert isinstance(y, (int, long))
+        assert is_valid_int(x)
+        assert is_valid_int(y)
         try:
             return ovfcheck(x << y)
         except OverflowError:
diff --git a/pypy/rpython/lltypesystem/llarena.py 
b/pypy/rpython/lltypesystem/llarena.py
--- a/pypy/rpython/lltypesystem/llarena.py
+++ b/pypy/rpython/lltypesystem/llarena.py
@@ -1,5 +1,7 @@
 import array, weakref
 from pypy.rpython.lltypesystem import llmemory
+from pypy.rlib.rarithmetic import is_valid_int
+
 
 # An "arena" is a large area of memory which can hold a number of
 # objects, not necessarily all of the same type or size.  It's used by
@@ -164,7 +166,7 @@
         return '<arenaaddr %s + %d>' % (self.arena, self.offset)
 
     def __add__(self, other):
-        if isinstance(other, (int, long)):
+        if is_valid_int(other):
             position = self.offset + other
         elif isinstance(other, llmemory.AddressOffset):
             # this is really some Do What I Mean logic.  There are two
@@ -184,7 +186,7 @@
     def __sub__(self, other):
         if isinstance(other, llmemory.AddressOffset):
             other = llmemory.raw_malloc_usage(other)
-        if isinstance(other, (int, long)):
+        if is_valid_int(other, force_type=False):
             return self.arena.getaddr(self.offset - other)
         if isinstance(other, fakearenaaddress):
             if self.arena is not other.arena:
diff --git a/pypy/rpython/lltypesystem/llmemory.py 
b/pypy/rpython/lltypesystem/llmemory.py
--- a/pypy/rpython/lltypesystem/llmemory.py
+++ b/pypy/rpython/lltypesystem/llmemory.py
@@ -8,6 +8,8 @@
 from pypy.rlib.objectmodel import Symbolic
 from pypy.rpython.lltypesystem import lltype
 from pypy.tool.uid import uid
+from pypy.rlib.rarithmetic import is_valid_int
+
 
 class AddressOffset(Symbolic):
 
@@ -28,7 +30,7 @@
     def __ge__(self, other):
         if self is other:
             return True
-        elif (isinstance(other, (int, long)) and other == 0 and
+        elif (is_valid_int(other, force_type=False) and other == 0 and
             self.known_nonneg()):
             return True
         else:
diff --git a/pypy/rpython/lltypesystem/lltype.py 
b/pypy/rpython/lltypesystem/lltype.py
--- a/pypy/rpython/lltypesystem/lltype.py
+++ b/pypy/rpython/lltypesystem/lltype.py
@@ -7,7 +7,7 @@
 from pypy.tool.identity_dict import identity_dict
 from pypy.tool import leakfinder
 from types import NoneType
-from sys import maxint
+from pypy.rlib.rarithmetic import maxint, is_valid_int
 import weakref
 
 class State(object):
@@ -1654,7 +1654,7 @@
     __slots__ = ('items',)
 
     def __init__(self, TYPE, n, initialization=None, parent=None, 
parentindex=None):
-        if not isinstance(n, (int, long)):
+        if not is_valid_int(n):
             raise TypeError, "array length must be an int"
         if n < 0:
             raise ValueError, "negative array length"
diff --git a/pypy/rpython/lltypesystem/opimpl.py 
b/pypy/rpython/lltypesystem/opimpl.py
--- a/pypy/rpython/lltypesystem/opimpl.py
+++ b/pypy/rpython/lltypesystem/opimpl.py
@@ -4,6 +4,8 @@
 from pypy.rpython.lltypesystem import lltype, llmemory
 from pypy.rpython.lltypesystem.lloperation import opimpls
 from pypy.rlib import debug
+from pypy.rlib.rarithmetic import is_valid_int
+
 
 # ____________________________________________________________
 # Implementation of the 'canfold' operations
@@ -173,7 +175,7 @@
 
 def op_direct_ptradd(obj, index):
     checkptr(obj)
-    assert isinstance(index, (int, long))
+    assert is_valid_int(index)
     return lltype.direct_ptradd(obj, index)
 
 
@@ -189,23 +191,23 @@
     return intmask(x + y)
 
 def op_int_sub(x, y):
-    if not isinstance(x, (int, long)):
+    if not is_valid_int(x, force_type=False):
         from pypy.rpython.lltypesystem import llgroup
         assert isinstance(x, llgroup.CombinedSymbolic)
-    assert isinstance(y, (int, long))
+    assert is_valid_int(y)
     return intmask(x - y)
 
 def op_int_ge(x, y):
     # special case for 'AddressOffset >= 0'
     assert isinstance(x, (int, long, llmemory.AddressOffset))
-    assert isinstance(y, (int, long))
+    assert is_valid_int(y)
     return x >= y
 
 def op_int_lt(x, y):
     # special case for 'AddressOffset < 0'
     # hack for win64
     assert isinstance(x, (int, long, llmemory.AddressOffset))
-    assert isinstance(y, (int, long))
+    assert is_valid_int(y)
     return x < y
 
 def op_int_between(a, b, c):
@@ -215,25 +217,25 @@
     return a <= b < c
 
 def op_int_and(x, y):
-    if not isinstance(x, (int, long)):
+    if not is_valid_int(x, force_type=False):
         from pypy.rpython.lltypesystem import llgroup
         assert isinstance(x, llgroup.CombinedSymbolic)
-    assert isinstance(y, (int, long))
+    assert is_valid_int(y)
     return x & y
 
 def op_int_or(x, y):
-    if not isinstance(x, (int, long)):
+    if not is_valid_int(x, force_type=False):
         from pypy.rpython.lltypesystem import llgroup
         assert isinstance(x, llgroup.CombinedSymbolic)
-    assert isinstance(y, (int, long))
+    assert is_valid_int(y)
     return x | y
 
 def op_int_xor(x, y):
     # used in computing hashes
     if isinstance(x, AddressAsInt): x = llmemory.cast_adr_to_int(x.adr)
     if isinstance(y, AddressAsInt): y = llmemory.cast_adr_to_int(y.adr)
-    assert isinstance(x, (int, long))
-    assert isinstance(y, (int, long))
+    assert is_valid_int(x)
+    assert is_valid_int(y)
     return x ^ y
 
 def op_int_mul(x, y):
@@ -242,10 +244,10 @@
     return intmask(x * y)
 
 def op_int_rshift(x, y):
-    if not isinstance(x, (int, long)):
+    if not is_valid_int(x, force_type=False):
         from pypy.rpython.lltypesystem import llgroup
         assert isinstance(x, llgroup.CombinedSymbolic)
-    assert isinstance(y, (int, long))
+    assert is_valid_int(y)
     return x >> y
 
 def op_int_floordiv(x, y):
@@ -283,22 +285,22 @@
 
 def op_uint_lshift(x, y):
     assert isinstance(x, r_uint)
-    assert isinstance(y, (int, long))
+    assert is_valid_int(y)
     return r_uint(x << y)
 
 def op_uint_rshift(x, y):
     assert isinstance(x, r_uint)
-    assert isinstance(y, (int, long))
+    assert is_valid_int(y)
     return r_uint(x >> y)
 
 def op_llong_lshift(x, y):
     assert isinstance(x, r_longlong_arg)
-    assert isinstance(y, (int, long))
+    assert is_valid_int(y)
     return r_longlong_result(x << y)
 
 def op_llong_rshift(x, y):
     assert isinstance(x, r_longlong_arg)
-    assert isinstance(y, (int, long))
+    assert is_valid_int(y)
     return r_longlong_result(x >> y)
 
 def op_ullong_lshift(x, y):
@@ -308,7 +310,7 @@
 
 def op_ullong_rshift(x, y):
     assert isinstance(x, r_ulonglong)
-    assert isinstance(y, (int, long))
+    assert is_valid_int(y)
     return r_ulonglong(x >> y)
 
 def op_same_as(x):
@@ -321,7 +323,7 @@
 
 def op_cast_int_to_float(i):
     # assert type(i) is int
-    assert isinstance(i, (int, long))
+    assert is_valid_int(i)
     return float(i)
 
 def op_cast_uint_to_float(u):
@@ -344,7 +346,7 @@
 
 def op_cast_int_to_char(b):
     #assert type(b) is int
-    assert isinstance(b, (int, long))
+    assert is_valid_int(b)
     return chr(b)
 
 def op_cast_bool_to_int(b):
@@ -388,12 +390,12 @@
     return ord(b)
 
 def op_cast_int_to_unichar(b):
-    assert isinstance(b, (int, long))
+    assert is_valid_int(b)
     return unichr(b)
 
 def op_cast_int_to_uint(b):
     # assert type(b) is int
-    assert isinstance(b, (int, long))
+    assert is_valid_int(b)
     return r_uint(b)
 
 def op_cast_uint_to_int(b):
@@ -401,7 +403,7 @@
     return intmask(b)
 
 def op_cast_int_to_longlong(b):
-    assert isinstance(b, (int, long))
+    assert is_valid_int(b)
     return r_longlong_result(b)
 
 def op_truncate_longlong_to_int(b):
@@ -572,7 +574,7 @@
     if isinstance(memberoffset, llgroup.GroupMemberOffset):
         return memberoffset.index != 0
     else:
-        assert isinstance(memberoffset, (int, long))
+        assert is_valid_int(memberoffset)
         return memberoffset != 0
 
 def op_extract_ushort(combinedoffset):
diff --git a/pypy/rpython/lltypesystem/test/test_ll2ctypes.py 
b/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
--- a/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
+++ b/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
@@ -17,6 +17,7 @@
 from pypy.annotation.annrpython import RPythonAnnotator
 from pypy.rpython.rtyper import RPythonTyper
 from pypy.rlib.rarithmetic import r_uint, get_long_pattern, is_emulated_long
+from pypy.rlib.rarithmetic import is_valid_int
 
 if False:    # for now, please keep it False by default
     from pypy.rpython.lltypesystem import ll2ctypes
@@ -1074,7 +1075,7 @@
                 return sys.maxint/2 * 3
 
         res = cast_adr_to_int(someaddr())
-        assert isinstance(res, (int, long))
+        assert is_emulated_long(res)
         assert res == -sys.maxint/2 - 3
 
     def test_cast_gcref_back_and_forth(self):
@@ -1327,7 +1328,7 @@
         p = lltype.malloc(S, flavor='raw')
         a = llmemory.cast_ptr_to_adr(p)
         i = llmemory.cast_adr_to_int(a, "forced")
-        assert isinstance(i, (int, long))
+        assert is_valid_int(i)
         assert i == llmemory.cast_adr_to_int(a, "forced")
         lltype.free(p, flavor='raw')
 
diff --git a/pypy/rpython/memory/gc/markcompact.py 
b/pypy/rpython/memory/gc/markcompact.py
--- a/pypy/rpython/memory/gc/markcompact.py
+++ b/pypy/rpython/memory/gc/markcompact.py
@@ -11,6 +11,8 @@
 from pypy.rlib.objectmodel import we_are_translated, running_on_llinterp
 from pypy.rpython.lltypesystem import rffi
 from pypy.rpython.memory.gcheader import GCHeaderBuilder
+from pypy.rlib.rarithmetic import is_valid_int
+
 
 # Mark'n'compact garbage collector
 #
@@ -353,7 +355,7 @@
         # like header(), but asserts that we have a forwarding header
         hdr = MovingGCBase.header(self, addr)
         if not we_are_translated():
-            assert isinstance(hdr.tid, (int, long))
+            assert is_valid_int(hdr.tid)
         return hdr
 
     def combine(self, typeid16, flags):
diff --git a/pypy/rpython/memory/gc/test/test_direct.py 
b/pypy/rpython/memory/gc/test/test_direct.py
--- a/pypy/rpython/memory/gc/test/test_direct.py
+++ b/pypy/rpython/memory/gc/test/test_direct.py
@@ -9,7 +9,7 @@
 import py
 from pypy.rpython.lltypesystem import lltype, llmemory
 from pypy.rpython.memory.gctypelayout import TypeLayoutBuilder
-from pypy.rlib.rarithmetic import LONG_BIT
+from pypy.rlib.rarithmetic import LONG_BIT, is_valid_int
 
 WORD = LONG_BIT // 8
 
@@ -286,7 +286,7 @@
         p = self.malloc(S)
         hash = self.gc.identityhash(p)
         print hash
-        assert isinstance(hash, (int, long))
+        assert is_valid_int(hash)
         assert hash == self.gc.identityhash(p)
         self.stackroots.append(p)
         for i in range(6):
@@ -299,7 +299,7 @@
         self.gc.collect()
         hash = self.gc.identityhash(self.stackroots[-1])
         print hash
-        assert isinstance(hash, (int, long))
+        assert is_valid_int(hash)
         for i in range(6):
             self.gc.collect()
             assert hash == self.gc.identityhash(self.stackroots[-1])
@@ -311,7 +311,7 @@
             self.gc.collect()
         hash = self.gc.identityhash(self.stackroots[-1])
         print hash
-        assert isinstance(hash, (int, long))
+        assert is_valid_int(hash)
         for i in range(2):
             self.gc.collect()
             assert hash == self.gc.identityhash(self.stackroots[-1])
@@ -319,7 +319,7 @@
         # (4) p is a prebuilt object
         hash = self.gc.identityhash(p_const)
         print hash
-        assert isinstance(hash, (int, long))
+        assert is_valid_int(hash)
         assert hash == self.gc.identityhash(p_const)
         # (5) p is actually moving (for the markcompact gc)
         p0 = self.malloc(S)
diff --git a/pypy/rpython/module/test/test_posix.py 
b/pypy/rpython/module/test/test_posix.py
--- a/pypy/rpython/module/test/test_posix.py
+++ b/pypy/rpython/module/test/test_posix.py
@@ -1,6 +1,8 @@
 import py
 from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
 from pypy.tool.udir import udir
+from pypy.rlib.rarithmetic import is_valid_int
+
 import os
 exec 'import %s as posix' % os.name
 
@@ -21,7 +23,7 @@
             ff = posix.open(path, posix.O_RDONLY, 0777)
             return ff
         func = self.interpret(f, [])
-        assert isinstance(func, (int, long))
+        assert is_valid_int(func)
 
     def test_fstat(self):
         def fo(fi):
@@ -61,7 +63,7 @@
         assert isinstance(times, tuple)
         assert len(times) == 5
         for value in times:
-            assert isinstance(value, (int, long))
+            assert is_valid_int(value)
 
 
     def test_lseek(self):
diff --git a/pypy/rpython/test/test_rbuiltin.py 
b/pypy/rpython/test/test_rbuiltin.py
--- a/pypy/rpython/test/test_rbuiltin.py
+++ b/pypy/rpython/test/test_rbuiltin.py
@@ -5,7 +5,7 @@
 from pypy.rlib.debug import llinterpcall
 from pypy.rpython.lltypesystem import lltype
 from pypy.tool import udir
-from pypy.rlib.rarithmetic import intmask
+from pypy.rlib.rarithmetic import intmask, is_valid_int
 from pypy.rlib.rarithmetic import r_int, r_uint, r_longlong, r_ulonglong
 from pypy.annotation.builtin import *
 from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
@@ -542,7 +542,7 @@
         if r_longlong is not r_int:
             assert isinstance(res, r_longlong)
         else:
-            assert isinstance(res, (int, long))
+            assert is_valid_int(res)
         #
         def llfn(v):
             return rffi.cast(rffi.ULONGLONG, v)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to