Author: Manuel Jacob <[email protected]>
Branch: kill-multimethod
Changeset: r74131:67da075acbca
Date: 2014-10-23 16:19 +0200
http://bitbucket.org/pypy/pypy/changeset/67da075acbca/
Log: hg merge default
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -22,3 +22,6 @@
.. branch: ClassRepr
Refactor ClassRepr and make normalizecalls independent of the rtyper.
+
+.. branch: remove-remaining-smm
+Remove all remaining multimethods.
diff --git a/pypy/module/micronumpy/boxes.py b/pypy/module/micronumpy/boxes.py
--- a/pypy/module/micronumpy/boxes.py
+++ b/pypy/module/micronumpy/boxes.py
@@ -16,6 +16,7 @@
from pypy.module.micronumpy.base import W_NDimArray, W_NumpyObject
from pypy.module.micronumpy.concrete import VoidBoxStorage
from pypy.module.micronumpy.flagsobj import W_FlagsObject
+from pypy.module.micronumpy import support
MIXIN_32 = (W_IntObject.typedef,) if LONG_BIT == 32 else ()
MIXIN_64 = (W_IntObject.typedef,) if LONG_BIT == 64 else ()
@@ -144,6 +145,34 @@
def item(self, space):
return self.get_dtype(space).itemtype.to_builtin_type(space, self)
+ def descr_item(self, space, args_w):
+ if len(args_w) == 1 and space.isinstance_w(args_w[0], space.w_tuple):
+ args_w = space.fixedview(args_w[0])
+ if len(args_w) > 1:
+ raise oefmt(space.w_ValueError,
+ "incorrect number of indices for array")
+ elif len(args_w) == 1:
+ try:
+ idx = support.index_w(space, args_w[0])
+ except OperationError:
+ raise oefmt(space.w_TypeError, "an integer is required")
+ if idx != 0:
+ raise oefmt(space.w_IndexError,
+ "index %d is out of bounds for size 1", idx)
+ return self.item(space)
+
+ def descr_transpose(self, space, args_w):
+ if len(args_w) == 1 and space.isinstance_w(args_w[0], space.w_tuple):
+ args_w = space.fixedview(args_w[0])
+ if len(args_w) >= 1:
+ for w_arg in args_w:
+ try:
+ idx = support.index_w(space, w_arg)
+ except OperationError:
+ raise oefmt(space.w_TypeError, "an integer is required")
+ raise oefmt(space.w_ValueError, "axes don't match array")
+ return self
+
def descr_getitem(self, space, w_item):
from pypy.module.micronumpy.base import convert_to_array
if space.is_w(w_item, space.w_Ellipsis) or \
@@ -372,6 +401,13 @@
def descr_reshape(self, space, __args__):
w_meth = space.getattr(self.descr_ravel(space), space.wrap('reshape'))
+ w_res = space.call_args(w_meth, __args__)
+ if isinstance(w_res, W_NDimArray) and len(w_res.get_shape()) == 0:
+ return w_res.get_scalar_value()
+ return w_res
+
+ def descr_nd_nonzero(self, space, __args__):
+ w_meth = space.getattr(self.descr_ravel(space), space.wrap('nonzero'))
return space.call_args(w_meth, __args__)
def descr_get_real(self, space):
@@ -387,6 +423,13 @@
self.w_flags = W_FlagsObject(self)
return self.w_flags
+ @unwrap_spec(axis1=int, axis2=int)
+ def descr_swapaxes(self, space, axis1, axis2):
+ return self
+
+ def descr_fill(self, space, w_value):
+ self.get_dtype(space).coerce(space, w_value)
+
class W_BoolBox(W_GenericBox, PrimitiveBox):
descr__new__, _get_dtype, descr_reduce = new_dtype_getter(NPY.BOOL)
@@ -619,6 +662,8 @@
__hash__ = interp2app(W_GenericBox.descr_hash),
tolist = interp2app(W_GenericBox.item),
+ item = interp2app(W_GenericBox.descr_item),
+ transpose = interp2app(W_GenericBox.descr_transpose),
min = interp2app(W_GenericBox.descr_self),
max = interp2app(W_GenericBox.descr_self),
argmin = interp2app(W_GenericBox.descr_zero),
@@ -630,13 +675,18 @@
ravel = interp2app(W_GenericBox.descr_ravel),
round = interp2app(W_GenericBox.descr_round),
conjugate = interp2app(W_GenericBox.descr_conjugate),
+ conj = interp2app(W_GenericBox.descr_conjugate),
astype = interp2app(W_GenericBox.descr_astype),
view = interp2app(W_GenericBox.descr_view),
squeeze = interp2app(W_GenericBox.descr_self),
copy = interp2app(W_GenericBox.descr_copy),
byteswap = interp2app(W_GenericBox.descr_byteswap),
tostring = interp2app(W_GenericBox.descr_tostring),
+ tobytes = interp2app(W_GenericBox.descr_tostring),
reshape = interp2app(W_GenericBox.descr_reshape),
+ swapaxes = interp2app(W_GenericBox.descr_swapaxes),
+ nonzero = interp2app(W_GenericBox.descr_nd_nonzero),
+ fill = interp2app(W_GenericBox.descr_fill),
dtype = GetSetProperty(W_GenericBox.descr_get_dtype),
size = GetSetProperty(W_GenericBox.descr_get_size),
diff --git a/pypy/module/micronumpy/ndarray.py
b/pypy/module/micronumpy/ndarray.py
--- a/pypy/module/micronumpy/ndarray.py
+++ b/pypy/module/micronumpy/ndarray.py
@@ -483,8 +483,7 @@
from .flatiter import W_FlatIterator
return space.wrap(W_FlatIterator(self))
- def descr_item(self, space, __args__):
- args_w, kw_w = __args__.unpack()
+ def descr_item(self, space, args_w):
if len(args_w) == 1 and space.isinstance_w(args_w[0], space.w_tuple):
args_w = space.fixedview(args_w[0])
shape = self.get_shape()
diff --git a/pypy/module/micronumpy/test/test_ndarray.py
b/pypy/module/micronumpy/test/test_ndarray.py
--- a/pypy/module/micronumpy/test/test_ndarray.py
+++ b/pypy/module/micronumpy/test/test_ndarray.py
@@ -3074,6 +3074,7 @@
assert a.item((1, 1, 1)) == 16
exc = raises(ValueError, a.item, 1, 1, 1, 1)
assert str(exc.value) == "incorrect number of indices for array"
+ raises(TypeError, "array([1]).item(a=1)")
def test_itemset(self):
import numpy as np
diff --git a/pypy/module/micronumpy/test/test_scalar.py
b/pypy/module/micronumpy/test/test_scalar.py
--- a/pypy/module/micronumpy/test/test_scalar.py
+++ b/pypy/module/micronumpy/test/test_scalar.py
@@ -254,6 +254,7 @@
assert np.int64(123).reshape((1,)).shape == (1,)
exc = raises(ValueError, "np.int64(123).reshape((2,))")
assert exc.value[0] == 'total size of new array must be unchanged'
+ assert type(np.int64(123).reshape(())) == np.int64
def test_complex_scalar_complex_cast(self):
import numpy as np
@@ -293,10 +294,123 @@
def test_scalar_iter(self):
from numpypy import int8, int16, int32, int64, float32, float64
- for t in int8, int16, int32, int64, float32, float64:
- try:
- iter(t(17))
- except TypeError:
- pass
- else:
- assert False, "%s object should not be iterable." % t
+ from numpypy import complex64, complex128
+ for t in (int8, int16, int32, int64, float32, float64,
+ complex64, complex128):
+ raises(TypeError, iter, t(17))
+
+ def test_item_tolist(self):
+ from numpypy import int8, int16, int32, int64, float32, float64
+ from numpypy import complex64, complex128, dtype
+
+ def _do_test(np_type, py_type, orig_val, exp_val):
+ val = np_type(orig_val)
+ assert val == orig_val
+ assert val.item() == exp_val
+ assert val.tolist() == exp_val
+ assert type(val.item()) is py_type
+ assert type(val.tolist()) is py_type
+ val.item(0)
+ val.item(())
+ val.item((0,))
+ raises(ValueError, val.item, 0, 1)
+ raises(ValueError, val.item, 0, '')
+ raises(TypeError, val.item, '')
+ raises(IndexError, val.item, 2)
+
+ for t in int8, int16, int32:
+ _do_test(t, int, 17, 17)
+
+ py_type = int if dtype('int').itemsize == 8 else long
+ _do_test(int64, py_type, 17, 17)
+
+ for t in float32, float64:
+ _do_test(t, float, 17, 17)
+
+ for t in complex64, complex128:
+ _do_test(t, complex, 17j, 17j)
+
+ def test_transpose(self):
+ from numpypy import int8, int16, int32, int64, float32, float64
+ from numpypy import complex64, complex128
+
+ def _do_test(np_type, orig_val, exp_val):
+ val = np_type(orig_val)
+ assert val == orig_val
+ assert val.transpose() == exp_val
+ assert type(val.transpose()) is np_type
+ val.transpose(())
+ raises(ValueError, val.transpose, 0, 1)
+ raises(TypeError, val.transpose, 0, '')
+ raises(ValueError, val.transpose, 0)
+
+ for t in int8, int16, int32, int64:
+ _do_test(t, 17, 17)
+
+ for t in float32, float64:
+ _do_test(t, 17, 17)
+
+ for t in complex64, complex128:
+ _do_test(t, 17j, 17j)
+
+ def test_swapaxes(self):
+ from numpypy import int8, int16, int32, int64, float32, float64
+ from numpypy import complex64, complex128
+
+ def _do_test(np_type, orig_val, exp_val):
+ val = np_type(orig_val)
+ assert val == orig_val
+ assert val.swapaxes(10, 20) == exp_val
+ assert type(val.swapaxes(0, 1)) is np_type
+ raises(TypeError, val.swapaxes, 0, ())
+
+ for t in int8, int16, int32, int64:
+ _do_test(t, 17, 17)
+
+ for t in float32, float64:
+ _do_test(t, 17, 17)
+
+ for t in complex64, complex128:
+ _do_test(t, 17j, 17j)
+
+ def test_nonzero(self):
+ from numpypy import int8, int16, int32, int64, float32, float64
+ from numpypy import complex64, complex128
+
+ for t in (int8, int16, int32, int64, float32, float64,
+ complex64, complex128):
+ res, = t(17).nonzero()
+ assert len(res) == 1
+ assert res[0] == 0
+ res, = t(0).nonzero()
+ assert len(res) == 0
+
+ def test_fill(self):
+ import sys
+ from numpypy import int8, int16, int32, int64, float32, float64
+ from numpypy import complex64, complex128
+
+ for t in (int8, int16, int32, int64, float32, float64,
+ complex64, complex128):
+ t(17).fill(2)
+ exc = (TypeError if t in (complex64, complex128)
+ and '__pypy__' not in sys.builtin_module_names
+ else ValueError)
+ raises(exc, t(17).fill, '')
+
+ def test_conj(self):
+ from numpypy import int8, int16, int32, int64, float32, float64
+ from numpypy import complex64, complex128
+
+ def _do_test(np_type, orig_val, exp_val):
+ val = np_type(orig_val)
+ assert val == orig_val
+ assert val.conj() == exp_val
+ assert val.conjugate() == exp_val
+
+ for t in (int8, int16, int32, int64, float32, float64,
+ complex64, complex128):
+ _do_test(t, 17, 17)
+
+ for t in complex64, complex128:
+ _do_test(t, 17j, -17j)
diff --git a/pypy/module/pypyjit/policy.py b/pypy/module/pypyjit/policy.py
--- a/pypy/module/pypyjit/policy.py
+++ b/pypy/module/pypyjit/policy.py
@@ -111,7 +111,7 @@
'__pypy__', 'cStringIO', '_collections', 'struct',
'mmap', 'marshal', '_codecs', 'rctime', 'cppyy',
'_cffi_backend', 'pyexpat', '_continuation', '_io',
- 'thread', 'select']:
+ 'thread', 'select', '_random']:
if modname == 'pypyjit' and 'interp_resop' in rest:
return False
return True
@@ -120,7 +120,7 @@
def look_inside_function(self, func):
mod = func.__module__ or '?'
- if mod == 'rpython.rlib.rbigint' or mod == 'rpython.rlib.rlocale' or
mod == 'rpython.rlib.rsocket':
+ if mod == 'rpython.rlib.rlocale' or mod == 'rpython.rlib.rsocket':
return False
if mod.startswith('pypy.interpreter.astcompiler.'):
return False
diff --git a/pypy/module/pypyjit/test/test_policy.py
b/pypy/module/pypyjit/test/test_policy.py
--- a/pypy/module/pypyjit/test/test_policy.py
+++ b/pypy/module/pypyjit/test/test_policy.py
@@ -6,15 +6,6 @@
from pypy.objspace.std.intobject import W_IntObject
assert pypypolicy.look_inside_function(W_IntObject.descr_add)
-def test_bigint():
- from rpython.rlib.rbigint import rbigint
- assert not pypypolicy.look_inside_function(rbigint.eq.im_func)
- assert not pypypolicy.look_inside_function(rbigint.ne.im_func)
- assert not pypypolicy.look_inside_function(rbigint.lt.im_func)
- assert not pypypolicy.look_inside_function(rbigint.le.im_func)
- assert not pypypolicy.look_inside_function(rbigint.gt.im_func)
- assert not pypypolicy.look_inside_function(rbigint.ge.im_func)
-
def test_rlocale():
from rpython.rlib.rlocale import setlocale
assert not pypypolicy.look_inside_function(setlocale)
@@ -56,7 +47,7 @@
def test_pypy_module():
from pypy.module._collections.interp_deque import W_Deque
from pypy.module._random.interp_random import W_Random
- assert not pypypolicy.look_inside_function(W_Random.random)
+ assert pypypolicy.look_inside_function(W_Random.random)
assert pypypolicy.look_inside_function(W_Deque.length)
assert pypypolicy.look_inside_pypy_module('__builtin__.operation')
assert pypypolicy.look_inside_pypy_module('__builtin__.abstractinst')
diff --git a/pypy/module/pypyjit/test_pypy_c/test_string.py
b/pypy/module/pypyjit/test_pypy_c/test_string.py
--- a/pypy/module/pypyjit/test_pypy_c/test_string.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_string.py
@@ -82,7 +82,10 @@
strsetitem(p25, 0, i23)
p93 = call(ConstClass(fromstr), p25, 16, descr=<Callr . ri EF=3>)
guard_no_exception(descr=...)
- i94 = call(ConstClass(rbigint.toint), p93, descr=<Calli . r EF=3>)
+ i95 = getfield_gc_pure(p93, descr=<FieldS
rpython.rlib.rbigint.rbigint.inst_size .*>)
+ i96 = int_gt(i95, .*)
+ guard_false(i96, descr=...)
+ i94 = call(ConstClass(rbigint._toint_helper), p93, descr=<Calli 8
r EF=3>)
guard_no_exception(descr=...)
i95 = int_add_ovf(i6, i94)
guard_no_overflow(descr=...)
diff --git a/pypy/module/pypyjit/test_pypy_c/test_thread.py
b/pypy/module/pypyjit/test_pypy_c/test_thread.py
--- a/pypy/module/pypyjit/test_pypy_c/test_thread.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_thread.py
@@ -70,7 +70,6 @@
i59 = int_is_true(i58)
guard_true(i59, descr=...)
i60 = int_sub(i44, 1)
- guard_not_invalidated(descr=...)
p62 = force_token()
setfield_gc(p0, p62, descr=<FieldP
pypy.interpreter.pyframe.PyFrame.vable_token 8>)
i63 = call_release_gil(..., i37, 0, descr=<Calli 4 ii EF=6>)
diff --git a/pypy/tool/pytest/appsupport.py b/pypy/tool/pytest/appsupport.py
--- a/pypy/tool/pytest/appsupport.py
+++ b/pypy/tool/pytest/appsupport.py
@@ -130,13 +130,9 @@
frame = None
def __init__(self, space, tb):
- self._frame = AppFrame(space, space.getattr(tb,
space.wrap('tb_frame')))
+ self.frame = AppFrame(space, space.getattr(tb, space.wrap('tb_frame')))
self.lineno = space.unwrap(space.getattr(tb, space.wrap('tb_lineno')))
- 1
- @property
- def frame(self):
- return self._frame
-
def reinterpret(self):
# XXX we need to solve a general problem: how to prevent
# reinterpretation from generating a different exception?
diff --git a/rpython/jit/codewriter/assembler.py
b/rpython/jit/codewriter/assembler.py
--- a/rpython/jit/codewriter/assembler.py
+++ b/rpython/jit/codewriter/assembler.py
@@ -249,6 +249,8 @@
if isinstance(TYPE, lltype.FuncType):
name = value._obj._name
elif TYPE == rclass.OBJECT_VTABLE:
+ if not value.name: # this is really the "dummy" class
+ return # pointer from some dict
name = ''.join(value.name.chars)
else:
return
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py
b/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py
@@ -1558,6 +1558,26 @@
"""
self.optimize_loop(ops, expected)
+ def test_varray_clear_unroll_bug(self):
+ ops = """
+ [p0]
+ i0 = getarrayitem_gc(p0, 0, descr=arraydescr)
+ i1 = getarrayitem_gc(p0, 1, descr=arraydescr)
+ i2 = getarrayitem_gc(p0, 2, descr=arraydescr)
+ i3 = int_add(i0, i1)
+ i4 = int_add(i3, i2)
+ p1 = new_array_clear(3, descr=arraydescr)
+ setarrayitem_gc(p1, 1, i4, descr=arraydescr)
+ setarrayitem_gc(p1, 0, 25, descr=arraydescr)
+ jump(p1)
+ """
+ expected = """
+ [i1]
+ i2 = int_add(i1, 25)
+ jump(i2)
+ """
+ self.optimize_loop(ops, expected)
+
def test_varray_alloc_and_set(self):
ops = """
[i1]
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py
b/rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py
@@ -761,6 +761,24 @@
assert not vstate1.generalization_of(vstate2)
+ def test_crash_varay_clear(self):
+ innervalue1 = OptValue(self.nodebox)
+ constclassbox = self.cpu.ts.cls_of_box(self.nodebox)
+ innervalue1.make_constant_class(constclassbox, -1)
+ innerinfo1 = NotVirtualStateInfo(innervalue1)
+ innerinfo1.position = 1
+ innerinfo1.position_in_notvirtuals = 0
+
+ descr = object()
+
+ info1 = VArrayStateInfo(descr)
+ info1.fieldstate = [innerinfo1]
+
+ constvalue = self.cpu.ts.CVAL_NULLREF
+ value1 = VArrayValue(descr, constvalue, 1, self.nodebox, clear=True)
+ value1._items[0] = constvalue
+ info1.enum_forced_boxes([None], value1, None)
+
class BaseTestBridges(BaseTest):
enable_opts = "intbounds:rewrite:virtualize:string:pure:heap:unroll"
diff --git a/rpython/jit/metainterp/optimizeopt/virtualstate.py
b/rpython/jit/metainterp/optimizeopt/virtualstate.py
--- a/rpython/jit/metainterp/optimizeopt/virtualstate.py
+++ b/rpython/jit/metainterp/optimizeopt/virtualstate.py
@@ -205,6 +205,8 @@
raise BadVirtualState
for i in range(len(self.fieldstate)):
v = value.get_item_value(i)
+ if v is None:
+ v = value.get_missing_null_value()
s = self.fieldstate[i]
if s.position > self.position:
s.enum_forced_boxes(boxes, v, optimizer)
diff --git a/rpython/jit/metainterp/test/test_dict.py
b/rpython/jit/metainterp/test/test_dict.py
--- a/rpython/jit/metainterp/test/test_dict.py
+++ b/rpython/jit/metainterp/test/test_dict.py
@@ -20,6 +20,21 @@
res = self.interp_operations(fn, [0])
assert not res
+ def test_dict_of_classes_as_values(self):
+ class A:
+ x = 5
+ class B(A):
+ x = 8
+ def fn(n):
+ A()
+ B()
+ d = self.newdict()
+ d[42] = A
+ d[43] = B
+ return d[n].x
+ res = self.interp_operations(fn, [43])
+ assert res == 8
+
def test_dict_keys_values_items(self):
for name, extract, expected in [('keys', None, 'k'),
('values', None, 'v'),
diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -427,7 +427,6 @@
def tolonglong(self):
return _AsLongLong(self)
- @jit.look_inside
def tobool(self):
return self.sign != 0
@@ -517,11 +516,9 @@
return (self.sign * self.digit(0)) == other
- @jit.look_inside
def ne(self, other):
return not self.eq(other)
- @jit.look_inside
def int_ne(self, other):
return not self.int_eq(other)
@@ -592,11 +589,9 @@
return True
return False
- @jit.look_inside
def le(self, other):
return not other.lt(self)
- @jit.look_inside
def int_le(self, other):
# Alternative that might be faster, reimplant this. as a check with
other + 1. But we got to check for overflow
# or reduce valid range.
@@ -605,19 +600,15 @@
return True
return self.int_lt(other)
- @jit.look_inside
def gt(self, other):
return other.lt(self)
- @jit.look_inside
def int_gt(self, other):
return not self.int_le(other)
- @jit.look_inside
def ge(self, other):
return not self.lt(other)
- @jit.look_inside
def int_ge(self, other):
return not self.int_lt(other)
@@ -784,7 +775,6 @@
return div
- @jit.look_inside
def div(self, other):
return self.floordiv(other)
diff --git a/rpython/rlib/rzlib.py b/rpython/rlib/rzlib.py
--- a/rpython/rlib/rzlib.py
+++ b/rpython/rlib/rzlib.py
@@ -37,7 +37,7 @@
Z_NO_FLUSH Z_FINISH Z_SYNC_FLUSH Z_FULL_FLUSH
MAX_WBITS MAX_MEM_LEVEL
Z_BEST_SPEED Z_BEST_COMPRESSION Z_DEFAULT_COMPRESSION
- Z_FILTERED Z_HUFFMAN_ONLY Z_DEFAULT_STRATEGY
+ Z_FILTERED Z_HUFFMAN_ONLY Z_DEFAULT_STRATEGY Z_NEED_DICT
'''.split()
class SimpleCConfig:
@@ -165,6 +165,9 @@
result = _inflateInit2_(stream, wbits, ZLIB_VERSION, size)
return result
+_deflateSetDictionary = zlib_external('deflateSetDictionary', [z_stream_p,
Bytefp, uInt], rffi.INT)
+_inflateSetDictionary = zlib_external('inflateSetDictionary', [z_stream_p,
Bytefp, uInt], rffi.INT)
+
# ____________________________________________________________
CRC32_DEFAULT_START = 0
@@ -184,6 +187,23 @@
ADLER32_DEFAULT_START = 1
+def deflateSetDictionary(stream, string):
+ bytes = rffi.get_nonmovingbuffer(string)
+ err = _deflateSetDictionary(stream, rffi.cast(Bytefp, bytes), len(string))
+ rffi.free_nonmovingbuffer(string, bytes)
+ if err == Z_STREAM_ERROR:
+ raise RZlibError("Parameter is invalid or the stream state is
inconsistent")
+
+def inflateSetDictionary(stream, string):
+ bytes = rffi.get_nonmovingbuffer(string)
+ err = _inflateSetDictionary(stream, rffi.cast(Bytefp, bytes), len(string))
+ rffi.free_nonmovingbuffer(string, bytes)
+ if err == Z_STREAM_ERROR:
+ raise RZlibError("Parameter is invalid or the stream state is
inconsistent")
+ elif err == Z_DATA_ERROR:
+ raise RZlibError("The given dictionary doesn't match the expected one")
+
+
def adler32(string, start=ADLER32_DEFAULT_START):
"""
Compute the Adler-32 checksum of the string, possibly with the given
diff --git a/rpython/rlib/test/test_rbigint.py
b/rpython/rlib/test/test_rbigint.py
--- a/rpython/rlib/test/test_rbigint.py
+++ b/rpython/rlib/test/test_rbigint.py
@@ -582,6 +582,8 @@
def test_int_bitwise(self):
for x in gen_signs([0, 1, 5, 11, 42, 43, 2 ** 30]):
for y in gen_signs([0, 1, 5, 11, 42, 43, 3 ** 30, 2 ** 31]):
+ if y != intmask(y):
+ continue # skip 'y' too large for 32-bit
lx = rbigint.fromlong(x)
for mod in "xor and_ or_".split():
res1 = getattr(lx, 'int_' + mod)(y).tolong()
@@ -666,9 +668,9 @@
for base in [0, 2, 4, 8, 16, 10, math.e]:
l = rbigint.fromlong(op).log(base)
if base:
- assert ulps_check(l, math.log(op, base), 1) is None
+ assert ulps_check(l, math.log(op, base)) is None
else:
- assert ulps_check(l, math.log(op), 1) is None
+ assert ulps_check(l, math.log(op)) is None
class TestInternalFunctions(object):
def test__inplace_divrem1(self):
diff --git a/rpython/rlib/test/test_rzlib.py b/rpython/rlib/test/test_rzlib.py
--- a/rpython/rlib/test/test_rzlib.py
+++ b/rpython/rlib/test/test_rzlib.py
@@ -82,6 +82,39 @@
rzlib.deflateEnd(stream)
+def test_deflate_set_dictionary():
+ text = 'abcabc'
+ zdict = 'abc'
+ stream = rzlib.deflateInit()
+ rzlib.deflateSetDictionary(stream, zdict)
+ bytes = rzlib.compress(stream, text, rzlib.Z_FINISH)
+ rzlib.deflateEnd(stream)
+
+ stream2 = rzlib.inflateInit()
+
+ from rpython.rtyper.lltypesystem import lltype, rffi, rstr
+ from rpython.rtyper.annlowlevel import llstr
+ from rpython.rlib.rstring import StringBuilder
+ with lltype.scoped_alloc(rffi.CCHARP.TO, len(bytes)) as inbuf:
+ rstr.copy_string_to_raw(llstr(bytes), inbuf, 0, len(bytes))
+ stream2.c_next_in = rffi.cast(rzlib.Bytefp, inbuf)
+ rffi.setintfield(stream2, 'c_avail_in', len(bytes))
+ with lltype.scoped_alloc(rffi.CCHARP.TO, 100) as outbuf:
+ stream2.c_next_out = rffi.cast(rzlib.Bytefp, outbuf)
+ bufsize = 100
+ rffi.setintfield(stream2, 'c_avail_out', bufsize)
+ err = rzlib._inflate(stream2, rzlib.Z_SYNC_FLUSH)
+ assert err == rzlib.Z_NEED_DICT
+ rzlib.inflateSetDictionary(stream2, zdict)
+ rzlib._inflate(stream2, rzlib.Z_SYNC_FLUSH)
+ avail_out = rffi.cast(lltype.Signed, stream2.c_avail_out)
+ result = StringBuilder()
+ result.append_charpsize(outbuf, bufsize - avail_out)
+
+ rzlib.inflateEnd(stream2)
+ assert result.build() == text
+
+
def test_compression():
"""
Once we have got a deflate stream, rzlib.compress()
diff --git a/rpython/rtyper/rbuiltin.py b/rpython/rtyper/rbuiltin.py
--- a/rpython/rtyper/rbuiltin.py
+++ b/rpython/rtyper/rbuiltin.py
@@ -688,10 +688,10 @@
if hop.s_result.is_constant():
return hop.inputconst(lltype.Bool, hop.s_result.const)
- if hop.args_s[1].is_constant() and hop.args_s[1].const in (str, list):
- if hop.args_s[0].knowntype not in (str, list):
- raise TyperError("isinstance(x, str/list) expects x to be known"
- " statically to be a str/list or None")
+ if hop.args_s[1].is_constant() and hop.args_s[1].const in (str, list,
unicode):
+ if hop.args_s[0].knowntype not in (str, list, unicode):
+ raise TyperError("isinstance(x, str/list/unicode) expects x to be
known"
+ " statically to be a str/list/unicode or None")
rstrlist = hop.args_r[0]
vstrlist = hop.inputarg(rstrlist, arg=0)
cnone = hop.inputconst(rstrlist, None)
diff --git a/rpython/rtyper/test/test_rbuiltin.py
b/rpython/rtyper/test/test_rbuiltin.py
--- a/rpython/rtyper/test/test_rbuiltin.py
+++ b/rpython/rtyper/test/test_rbuiltin.py
@@ -393,6 +393,21 @@
res = self.interpret(f, [1])
assert res is False
+ def test_isinstance_unicode(self):
+ def g():
+ pass
+ def f(i):
+ if i == 0:
+ l = u"foobar"
+ else:
+ l = None
+ g()
+ return isinstance(l, unicode)
+ res = self.interpret(f, [0])
+ assert res is True
+ res = self.interpret(f, [1])
+ assert res is False
+
def test_instantiate(self):
class A:
pass
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit