[pypy-commit] pypy zlib-mem-pressure: merge in default
justinpeel
noreply at buildbot.pypy.org
Thu Mar 15 04:24:06 CET 2012
Author: Justin Peel <notmuchtotell at gmail.com>
Branch: zlib-mem-pressure
Changeset: r53655:51221f3fd04c
Date: 2012-03-14 21:19 -0600
http://bitbucket.org/pypy/pypy/changeset/51221f3fd04c/
Log: merge in default
diff --git a/pypy/rlib/rarithmetic.py b/pypy/rlib/rarithmetic.py
--- a/pypy/rlib/rarithmetic.py
+++ b/pypy/rlib/rarithmetic.py
@@ -92,7 +92,10 @@
We therefore can no longer use the int type as it is, but need
to use long everywhere.
"""
-
+
+# XXX returning int(n) should not be necessary and should be simply n.
+# XXX TODO: replace all int(n) by long(n) and fix everything that breaks.
+# XXX Then relax it and replace int(n) by n.
def intmask(n):
if isinstance(n, objectmodel.Symbolic):
return n # assume Symbolics don't overflow
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
@@ -1021,22 +1021,22 @@
# Overflow-detecting variants
def op_int_neg_ovf(self, x):
- assert type(x) is int
+ assert is_valid_int(x)
try:
return ovfcheck(-x)
except OverflowError:
self.make_llexception()
def op_int_abs_ovf(self, x):
- assert type(x) is int
+ 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)
- assert isinstance(y, int)
+ assert is_valid_int(x)
+ assert is_valid_int(y)
try:
return ovfcheck(x << y)
except OverflowError:
@@ -1060,7 +1060,9 @@
return r
'''%locals()
elif operator == '%':
- code = '''r = %(checkfn)s(x %% y)
+ ## overflow check on % does not work with emulated int
+ code = '''%(checkfn)s(x // y)
+ r = x %% y
if x^y < 0 and x%%y != 0:
r -= y
return r
@@ -1077,15 +1079,15 @@
self.make_llexception()
""" % locals()).compile() in globals(), d
- _makefunc2('op_int_add_ovf', '+', '(int, llmemory.AddressOffset)')
- _makefunc2('op_int_mul_ovf', '*', '(int, llmemory.AddressOffset)', 'int')
- _makefunc2('op_int_sub_ovf', '-', 'int')
- _makefunc2('op_int_floordiv_ovf', '//', 'int') # XXX negative args
- _makefunc2('op_int_floordiv_zer', '//', 'int') # can get off-by-one
- _makefunc2('op_int_floordiv_ovf_zer', '//', 'int') # (see op_int_floordiv)
- _makefunc2('op_int_mod_ovf', '%', 'int')
- _makefunc2('op_int_mod_zer', '%', 'int')
- _makefunc2('op_int_mod_ovf_zer', '%', 'int')
+ _makefunc2('op_int_add_ovf', '+', '(int, long, llmemory.AddressOffset)')
+ _makefunc2('op_int_mul_ovf', '*', '(int, long, llmemory.AddressOffset)', '(int, long)')
+ _makefunc2('op_int_sub_ovf', '-', '(int, long)')
+ _makefunc2('op_int_floordiv_ovf', '//', '(int, long)') # XXX negative args
+ _makefunc2('op_int_floordiv_zer', '//', '(int, long)') # can get off-by-one
+ _makefunc2('op_int_floordiv_ovf_zer', '//', '(int, long)') # (see op_int_floordiv)
+ _makefunc2('op_int_mod_ovf', '%', '(int, long)')
+ _makefunc2('op_int_mod_zer', '%', '(int, long)')
+ _makefunc2('op_int_mod_ovf_zer', '%', '(int, long)')
_makefunc2('op_uint_floordiv_zer', '//', 'r_uint')
_makefunc2('op_uint_mod_zer', '%', 'r_uint')
@@ -1107,7 +1109,7 @@
x = x.default
# if type(x) is a subclass of Symbolic, bool(x) will usually raise
# a TypeError -- unless __nonzero__ has been explicitly overridden.
- assert isinstance(x, (int, Symbolic))
+ assert is_valid_int(x) or isinstance(x, Symbolic)
return bool(x)
# hack for jit.codegen.llgraph
@@ -1129,7 +1131,7 @@
def op_oonewarray(self, ARRAY, length):
assert isinstance(ARRAY, ootype.Array)
- assert isinstance(length, int)
+ assert is_valid_int(length)
return ootype.oonewarray(ARRAY, length)
def op_runtimenew(self, class_):
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) and other == 0 and
self.known_nonneg()):
return True
else:
@@ -58,7 +60,7 @@
return "<ItemOffset %r %r>" % (self.TYPE, self.repeat)
def __mul__(self, other):
- if not isinstance(other, int):
+ if not is_valid_int(other):
return NotImplemented
return ItemOffset(self.TYPE, self.repeat * other)
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/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
@@ -567,7 +567,7 @@
if r_longlong is not r_int:
assert isinstance(res, r_longlong)
else:
- assert isinstance(res, int)
+ assert is_valid_int(res)
#
def llfn(v):
return rffi.cast(rffi.ULONGLONG, v)
diff --git a/pypy/translator/c/test/test_newgc.py b/pypy/translator/c/test/test_newgc.py
--- a/pypy/translator/c/test/test_newgc.py
+++ b/pypy/translator/c/test/test_newgc.py
@@ -675,8 +675,8 @@
gc.collect()
p_a1 = rffi.cast(rffi.VOIDPP, ll_args[0])[0]
p_a2 = rffi.cast(rffi.VOIDPP, ll_args[1])[0]
- a1 = rffi.cast(rffi.LONGP, p_a1)[0]
- a2 = rffi.cast(rffi.LONGP, p_a2)[0]
+ a1 = rffi.cast(rffi.SIGNEDP, p_a1)[0]
+ a2 = rffi.cast(rffi.SIGNEDP, p_a2)[0]
res = rffi.cast(rffi.INTP, ll_res)
if a1 > a2:
res[0] = rffi.cast(rffi.INT, 1)
@@ -692,7 +692,7 @@
ptr = CallbackFuncPtr([ffi_type_pointer, ffi_type_pointer],
ffi_type_sint, callback)
- TP = rffi.CArray(rffi.LONG)
+ TP = rffi.CArray(lltype.Signed)
to_sort = lltype.malloc(TP, 4, flavor='raw')
to_sort[0] = 4
to_sort[1] = 3
@@ -700,7 +700,7 @@
to_sort[3] = 2
qsort.push_arg(rffi.cast(rffi.VOIDP, to_sort))
qsort.push_arg(rffi.cast(rffi.SIZE_T, 4))
- qsort.push_arg(rffi.cast(rffi.SIZE_T, rffi.sizeof(rffi.LONG)))
+ qsort.push_arg(rffi.cast(rffi.SIZE_T, rffi.sizeof(lltype.Signed)))
qsort.push_arg(rffi.cast(rffi.VOIDP, ptr.ll_closure))
qsort.call(lltype.Void)
result = [to_sort[i] for i in range(4)] == [1,2,3,4]
@@ -1202,7 +1202,7 @@
def f():
from pypy.rpython.lltypesystem import lltype, rffi
alist = [A() for i in range(50000)]
- idarray = lltype.malloc(rffi.LONGP.TO, len(alist), flavor='raw')
+ idarray = lltype.malloc(rffi.SIGNEDP.TO, len(alist), flavor='raw')
# Compute the id of all elements of the list. The goal is
# to not allocate memory, so that if the GC needs memory to
# remember the ids, it will trigger some collections itself
More information about the pypy-commit
mailing list