Author: Philip Jenvey <[email protected]>
Branch: py3k-stdlib-2.7.6-merge
Changeset: r69911:0913e409b4e2
Date: 2014-03-12 15:20 -0700
http://bitbucket.org/pypy/pypy/changeset/0913e409b4e2/
Log: merge default
diff --git a/pypy/module/_codecs/test/test_codecs.py
b/pypy/module/_codecs/test/test_codecs.py
--- a/pypy/module/_codecs/test/test_codecs.py
+++ b/pypy/module/_codecs/test/test_codecs.py
@@ -337,12 +337,12 @@
raises(UnicodeDecodeError, decode, r"\U00110000")
assert decode(r"\U00110000", "ignore") == (u"", 10)
assert decode(r"\U00110000", "replace") == (u"\ufffd", 10)
- exc = raises(UnicodeDecodeError, unicode_escape_decode, "\u1z32z3",
'strict')
- assert str(exc.value) == "'unicodeescape' codec can't decode bytes in
position 0-2: truncated \uXXXX escape"
- exc = raises(UnicodeDecodeError, raw_unicode_escape_decode,
"\u1z32z3", 'strict')
- assert str(exc.value) == "'rawunicodeescape' codec can't decode bytes
in position 0-2: truncated \uXXXX"
- exc = raises(UnicodeDecodeError, raw_unicode_escape_decode,
"\U1z32z3", 'strict')
- assert str(exc.value) == "'rawunicodeescape' codec can't decode bytes
in position 0-2: truncated \uXXXX"
+ exc = raises(UnicodeDecodeError, unicode_escape_decode, b"\u1z32z3",
'strict')
+ assert str(exc.value) == r"'unicodeescape' codec can't decode bytes in
position 0-2: truncated \uXXXX escape"
+ exc = raises(UnicodeDecodeError, raw_unicode_escape_decode,
b"\u1z32z3", 'strict')
+ assert str(exc.value) == r"'rawunicodeescape' codec can't decode bytes
in position 0-2: truncated \uXXXX"
+ exc = raises(UnicodeDecodeError, raw_unicode_escape_decode,
b"\U1z32z3", 'strict')
+ assert str(exc.value) == r"'rawunicodeescape' codec can't decode bytes
in position 0-2: truncated \uXXXX"
def test_escape_encode(self):
import _codecs
@@ -653,7 +653,7 @@
l = [u"<%d>" % ord(exc.object[pos]) for pos in xrange(exc.start,
exc.end)]
return (u"[%s]" % u"".join(l), exc.end)
codecs.register_error("test.handler1", handler1)
- assert "\\u3042\u3xxx".decode("unicode-escape", "test.handler1") == \
+ assert b"\\u3042\u3xxx".decode("unicode-escape", "test.handler1") == \
u"\u3042[<92><117><51>]xxx"
def test_encode_error_bad_handler(self):
@@ -706,22 +706,22 @@
def test_utf7_errors(self):
import codecs
tests = [
- ('a\xffb', u'a\ufffdb'),
- ('a+IK', u'a\ufffd'),
- ('a+IK-b', u'a\ufffdb'),
- ('a+IK,b', u'a\ufffdb'),
- ('a+IKx', u'a\u20ac\ufffd'),
- ('a+IKx-b', u'a\u20ac\ufffdb'),
- ('a+IKwgr', u'a\u20ac\ufffd'),
- ('a+IKwgr-b', u'a\u20ac\ufffdb'),
- ('a+IKwgr,', u'a\u20ac\ufffd'),
- ('a+IKwgr,-b', u'a\u20ac\ufffd-b'),
- ('a+IKwgrB', u'a\u20ac\u20ac\ufffd'),
- ('a+IKwgrB-b', u'a\u20ac\u20ac\ufffdb'),
- ('a+/,+IKw-b', u'a\ufffd\u20acb'),
- ('a+//,+IKw-b', u'a\ufffd\u20acb'),
- ('a+///,+IKw-b', u'a\uffff\ufffd\u20acb'),
- ('a+////,+IKw-b', u'a\uffff\ufffd\u20acb'),
+ (b'a\xffb', u'a\ufffdb'),
+ (b'a+IK', u'a\ufffd'),
+ (b'a+IK-b', u'a\ufffdb'),
+ (b'a+IK,b', u'a\ufffdb'),
+ (b'a+IKx', u'a\u20ac\ufffd'),
+ (b'a+IKx-b', u'a\u20ac\ufffdb'),
+ (b'a+IKwgr', u'a\u20ac\ufffd'),
+ (b'a+IKwgr-b', u'a\u20ac\ufffdb'),
+ (b'a+IKwgr,', u'a\u20ac\ufffd'),
+ (b'a+IKwgr,-b', u'a\u20ac\ufffd-b'),
+ (b'a+IKwgrB', u'a\u20ac\u20ac\ufffd'),
+ (b'a+IKwgrB-b', u'a\u20ac\u20ac\ufffdb'),
+ (b'a+/,+IKw-b', u'a\ufffd\u20acb'),
+ (b'a+//,+IKw-b', u'a\ufffd\u20acb'),
+ (b'a+///,+IKw-b', u'a\uffff\ufffd\u20acb'),
+ (b'a+////,+IKw-b', u'a\uffff\ufffd\u20acb'),
]
for raw, expected in tests:
raises(UnicodeDecodeError, codecs.utf_7_decode, raw, 'strict',
True)
diff --git a/pypy/module/cpyext/test/test_typeobject.py
b/pypy/module/cpyext/test/test_typeobject.py
--- a/pypy/module/cpyext/test/test_typeobject.py
+++ b/pypy/module/cpyext/test/test_typeobject.py
@@ -584,5 +584,5 @@
def test_tp_new_in_subclass_of_type(self):
skip("BROKEN")
module = self.import_module(name='foo3')
- print 'calling module.Type()...'
+ print('calling module.Type()...')
module.Type("X", (object,), {})
diff --git a/pypy/module/micronumpy/__init__.py
b/pypy/module/micronumpy/__init__.py
--- a/pypy/module/micronumpy/__init__.py
+++ b/pypy/module/micronumpy/__init__.py
@@ -6,23 +6,26 @@
interpleveldefs = {
'ndarray': 'ndarray.W_NDimArray',
'dtype': 'descriptor.W_Dtype',
+ 'flatiter': 'flatiter.W_FlatIterator',
+ '_reconstruct' : 'ndarray._reconstruct',
+ 'scalar' : 'ctors.build_scalar',
'array': 'ctors.array',
'zeros': 'ctors.zeros',
'empty': 'ctors.zeros',
'empty_like': 'ctors.empty_like',
- '_reconstruct' : 'ndarray._reconstruct',
- 'scalar' : 'ctors.build_scalar',
+ 'fromstring': 'ctors.fromstring',
+
+ 'concatenate': 'arrayops.concatenate',
+ 'count_nonzero': 'arrayops.count_nonzero',
'dot': 'arrayops.dot',
- 'fromstring': 'ctors.fromstring',
- 'flatiter': 'flatiter.W_FlatIterator',
- 'concatenate': 'arrayops.concatenate',
'where': 'arrayops.where',
- 'count_nonzero': 'arrayops.count_nonzero',
'set_string_function': 'appbridge.set_string_function',
'typeinfo': 'descriptor.get_dtype_cache(space).w_typeinfo',
}
+ for c in ['CLIP', 'WRAP', 'RAISE']:
+ interpleveldefs[c] = 'space.wrap(constants.%s)' % c
class UMathModule(MixedModule):
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
@@ -1035,6 +1035,26 @@
value = self.get_scalar_value()
return space.float(value)
+ def descr_hex(self, space):
+ if self.get_size() != 1:
+ raise oefmt(space.w_TypeError,
+ "only length-1 arrays can be converted to Python
scalars")
+ if not self.get_dtype().is_int():
+ raise oefmt(space.w_TypeError,
+ "don't know how to convert scalar number to hex")
+ value = self.get_scalar_value()
+ return space.hex(value)
+
+ def descr_oct(self, space):
+ if self.get_size() != 1:
+ raise oefmt(space.w_TypeError,
+ "only length-1 arrays can be converted to Python
scalars")
+ if not self.get_dtype().is_int():
+ raise oefmt(space.w_TypeError,
+ "don't know how to convert scalar number to oct")
+ value = self.get_scalar_value()
+ return space.oct(value)
+
def descr_index(self, space):
if self.get_size() != 1 or \
not self.get_dtype().is_int() or self.get_dtype().is_bool():
@@ -1226,6 +1246,8 @@
__str__ = interp2app(W_NDimArray.descr_str),
__int__ = interp2app(W_NDimArray.descr_int),
__float__ = interp2app(W_NDimArray.descr_float),
+ __hex__ = interp2app(W_NDimArray.descr_hex),
+ __oct__ = interp2app(W_NDimArray.descr_oct),
__buffer__ = interp2app(W_NDimArray.descr_get_data),
__index__ = interp2app(W_NDimArray.descr_index),
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
@@ -246,6 +246,12 @@
return CustomIntObject(value)
+ def test_constants(self):
+ import numpy as np
+ assert np.CLIP is 0
+ assert np.WRAP is 1
+ assert np.RAISE is 2
+
def test_ndarray(self):
from numpy import ndarray, array, dtype, flatiter
@@ -2267,6 +2273,30 @@
exc = raises(TypeError, "float(np.array([1.5, 2.5]))")
assert exc.value[0] == 'only length-1 arrays can be converted to
Python scalars'
+ def test__hex__(self):
+ import numpy as np
+ assert hex(np.array(True)) == '0x1'
+ assert hex(np.array(15)) == '0xf'
+ assert hex(np.array([15])) == '0xf'
+ exc = raises(TypeError, "hex(np.array(1.5))")
+ assert str(exc.value) == "don't know how to convert scalar number to
hex"
+ exc = raises(TypeError, "hex(np.array('15'))")
+ assert str(exc.value) == "don't know how to convert scalar number to
hex"
+ exc = raises(TypeError, "hex(np.array([1, 2]))")
+ assert str(exc.value) == "only length-1 arrays can be converted to
Python scalars"
+
+ def test__oct__(self):
+ import numpy as np
+ assert oct(np.array(True)) == '01'
+ assert oct(np.array(15)) == '017'
+ assert oct(np.array([15])) == '017'
+ exc = raises(TypeError, "oct(np.array(1.5))")
+ assert str(exc.value) == "don't know how to convert scalar number to
oct"
+ exc = raises(TypeError, "oct(np.array('15'))")
+ assert str(exc.value) == "don't know how to convert scalar number to
oct"
+ exc = raises(TypeError, "oct(np.array([1, 2]))")
+ assert str(exc.value) == "only length-1 arrays can be converted to
Python scalars"
+
def test__reduce__(self):
from numpypy import array, dtype
from cPickle import loads, dumps
diff --git a/pypy/module/pypyjit/test/test_ztranslation.py
b/pypy/module/pypyjit/test/test_ztranslation.py
--- a/pypy/module/pypyjit/test/test_ztranslation.py
+++ b/pypy/module/pypyjit/test/test_ztranslation.py
@@ -1,5 +1,5 @@
+from pypy.objspace.fake.checkmodule import checkmodule
-from pypy.objspace.fake.checkmodule import checkmodule
def test_pypyjit_translates():
checkmodule('pypyjit')
diff --git a/pypy/module/pypyjit/test_pypy_c/test_00_model.py
b/pypy/module/pypyjit/test_pypy_c/test_00_model.py
--- a/pypy/module/pypyjit/test_pypy_c/test_00_model.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_00_model.py
@@ -7,13 +7,13 @@
from rpython.tool.udir import udir
from rpython.tool import logparser
from rpython.jit.tool.jitoutput import parse_prof
-from pypy.module.pypyjit.test_pypy_c.model import (Log, find_ids_range,
- find_ids,
- OpMatcher, InvalidMatch)
+from pypy.module.pypyjit.test_pypy_c.model import \
+ Log, find_ids_range, find_ids, OpMatcher, InvalidMatch
+
class BaseTestPyPyC(object):
log_string = 'jit-log-opt,jit-log-noopt,jit-log-virtualstate,jit-summary'
-
+
def setup_class(cls):
if '__pypy__' not in sys.builtin_module_names:
py.test.skip("must run this test with pypy")
@@ -98,7 +98,6 @@
class TestLog(object):
-
def test_find_ids_range(self):
def f():
a = 0 # ID: myline
@@ -127,7 +126,6 @@
class TestOpMatcher_(object):
-
def match(self, src1, src2, **kwds):
from rpython.tool.jitlogparser.parser import SimpleParser
loop = SimpleParser.parse_from_input(src1)
@@ -347,7 +345,6 @@
class TestRunPyPyC(BaseTestPyPyC):
-
def test_run_function(self):
def f(a, b):
return a+b
@@ -385,7 +382,7 @@
assert len(loops) == 1
assert loops[0].filename == self.filepath
assert len([op for op in loops[0].allops() if op.name == 'label']) == 0
- assert len([op for op in loops[0].allops() if op.name ==
'guard_nonnull_class']) == 0
+ assert len([op for op in loops[0].allops() if op.name ==
'guard_nonnull_class']) == 0
#
loops = log.loops_by_filename(self.filepath, is_entry_bridge=True)
assert len(loops) == 1
@@ -454,7 +451,6 @@
#
ops = loop.ops_by_id('foo', opcode='INPLACE_SUBTRACT')
assert log.opnames(ops) == ['int_sub_ovf', 'guard_no_overflow']
-
def test_inlined_function(self):
def f():
diff --git a/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py
b/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py
@@ -0,0 +1,60 @@
+from pypy.module.pypyjit.test_pypy_c.test_00_model import BaseTestPyPyC
+
+
+class TestMicroNumPy(BaseTestPyPyC):
+ def test_array_getitem_basic(self):
+ def main():
+ import _numpypy.multiarray as np
+ arr = np.zeros((300, 300))
+ x = 150
+ y = 0
+ while y < 300:
+ a = arr[x, y]
+ y += 1
+ return a
+ log = self.run(main, [])
+ assert log.result == 0
+ loop, = log.loops_by_filename(self.filepath)
+ assert loop.match("""
+ i76 = int_lt(i71, 300)
+ guard_true(i76, descr=...)
+ i77 = int_ge(i71, i59)
+ guard_false(i77, descr=...)
+ i78 = int_mul(i71, i61)
+ i79 = int_add(i55, i78)
+ f80 = raw_load(i67, i79, descr=<ArrayF 8>)
+ i81 = int_add(i71, 1)
+ guard_not_invalidated(descr=...)
+ --TICK--
+ jump(p0, p1, p3, p6, p7, p12, p14, p16, i81, f80, i59, p38, i55,
p40, i37, i61, i67, descr=...)
+ """)
+
+ def test_array_getitem_accumulate(self):
+ def main():
+ import _numpypy.multiarray as np
+ arr = np.zeros((300, 300))
+ a = 0.0
+ x = 150
+ y = 0
+ while y < 300:
+ a += arr[x, y]
+ y += 1
+ return a
+ log = self.run(main, [])
+ assert log.result == 0
+ loop, = log.loops_by_filename(self.filepath)
+ skip('used to pass on 69421-f3e717c94913')
+ assert loop.match("""
+ i81 = int_lt(i76, 300)
+ guard_true(i81, descr=...)
+ i82 = int_ge(i76, i62)
+ guard_false(i82, descr=...)
+ i83 = int_mul(i76, i64)
+ i84 = int_add(i58, i83)
+ f85 = raw_load(i70, i84, descr=<ArrayF 8>)
+ guard_not_invalidated(descr=...)
+ f86 = float_add(f74, f85)
+ i87 = int_add(i76, 1)
+ --TICK--
+ jump(p0, p1, p3, p6, p7, p12, p14, f86, p18, i87, i62, p41, i58,
p47, i40, i64, i70, descr=...)
+ """)
diff --git a/rpython/rlib/rfile.py b/rpython/rlib/rfile.py
--- a/rpython/rlib/rfile.py
+++ b/rpython/rlib/rfile.py
@@ -132,8 +132,8 @@
The actual return value may be determined with os.WEXITSTATUS.
"""
+ res = 0
ll_f = self.ll_file
- res = 0
if ll_f:
# double close is allowed
self.ll_file = lltype.nullptr(FILE)
diff --git a/rpython/rlib/test/test_rfile.py b/rpython/rlib/test/test_rfile.py
--- a/rpython/rlib/test/test_rfile.py
+++ b/rpython/rlib/test/test_rfile.py
@@ -1,9 +1,9 @@
-
import os, sys, py
from rpython.rtyper.test.tool import BaseRtypingTest
from rpython.tool.udir import udir
from rpython.rlib import rfile
+
class TestFile(BaseRtypingTest):
def setup_class(cls):
cls.tmpdir = udir.join('test_rfile')
@@ -208,6 +208,7 @@
assert s == "%s\n" % printval
assert os.WEXITSTATUS(r) == retval
+
class TestPopenR(BaseRtypingTest):
def setup_class(cls):
if sys.platform == 'win32':
diff --git a/rpython/rtyper/llannotation.py b/rpython/rtyper/llannotation.py
--- a/rpython/rtyper/llannotation.py
+++ b/rpython/rtyper/llannotation.py
@@ -6,7 +6,7 @@
from rpython.annotator.model import (
SomeObject, SomeSingleFloat, SomeFloat, SomeLongFloat, SomeChar,
SomeUnicodeCodePoint, SomeInteger, SomeString, SomeImpossibleValue,
- s_None, s_Bool, UnionError, AnnotatorError)
+ s_None, s_Bool, UnionError, AnnotatorError, SomeBool)
from rpython.rtyper.lltypesystem import lltype, llmemory
class SomeAddress(SomeObject):
@@ -155,7 +155,10 @@
return ll_to_annotation(v)
def bool(self):
- return s_Bool
+ result = SomeBool()
+ if self.is_constant():
+ result.const = bool(self.const)
+ return result
class SomeInteriorPtr(SomePtr):
diff --git a/rpython/rtyper/lltypesystem/rffi.py
b/rpython/rtyper/lltypesystem/rffi.py
--- a/rpython/rtyper/lltypesystem/rffi.py
+++ b/rpython/rtyper/lltypesystem/rffi.py
@@ -4,7 +4,7 @@
from rpython.rtyper.lltypesystem import lltype, rstr
from rpython.rtyper.lltypesystem import ll2ctypes
from rpython.rtyper.lltypesystem.llmemory import cast_ptr_to_adr
-from rpython.rtyper.lltypesystem.llmemory import itemoffsetof, raw_memcopy
+from rpython.rtyper.lltypesystem.llmemory import itemoffsetof
from rpython.rtyper.llannotation import lltype_to_annotation
from rpython.tool.sourcetools import func_with_new_name
from rpython.rlib.objectmodel import Symbolic
@@ -679,7 +679,9 @@
if strtype is str:
from rpython.rtyper.lltypesystem.rstr import (STR as STRTYPE,
- copy_string_to_raw)
+ copy_string_to_raw,
+ copy_raw_to_string,
+ copy_string_contents)
from rpython.rtyper.annlowlevel import llstr as llstrtype
from rpython.rtyper.annlowlevel import hlstr as hlstrtype
TYPEP = CCHARP
@@ -689,7 +691,9 @@
else:
from rpython.rtyper.lltypesystem.rstr import (
UNICODE as STRTYPE,
- copy_unicode_to_raw as copy_string_to_raw)
+ copy_unicode_to_raw as copy_string_to_raw,
+ copy_raw_to_unicode as copy_raw_to_string,
+ copy_unicode_contents as copy_string_contents)
from rpython.rtyper.annlowlevel import llunicode as llstrtype
from rpython.rtyper.annlowlevel import hlunicode as hlstrtype
TYPEP = CWCHARP
@@ -803,17 +807,10 @@
return hlstrtype(gc_buf)
new_buf = lltype.malloc(STRTYPE, needed_size)
- str_chars_offset = (offsetof(STRTYPE, 'chars') + \
- itemoffsetof(STRTYPE.chars, 0))
if gc_buf:
- src = cast_ptr_to_adr(gc_buf) + str_chars_offset
+ copy_string_contents(gc_buf, new_buf, 0, 0, needed_size)
else:
- src = cast_ptr_to_adr(raw_buf) + itemoffsetof(TYPEP.TO, 0)
- dest = cast_ptr_to_adr(new_buf) + str_chars_offset
- raw_memcopy(src, dest,
- llmemory.sizeof(ll_char_type) * needed_size)
- keepalive_until_here(gc_buf)
- keepalive_until_here(new_buf)
+ copy_raw_to_string(raw_buf, new_buf, 0, needed_size)
return hlstrtype(new_buf)
# (char*, str) -> None
diff --git a/rpython/rtyper/rtuple.py b/rpython/rtyper/rtuple.py
--- a/rpython/rtyper/rtuple.py
+++ b/rpython/rtyper/rtuple.py
@@ -290,14 +290,15 @@
if not s_tup.is_constant():
raise TyperError("contains() on non-const tuple")
t = s_tup.const
- if len(t) == 0:
- hop.exception_cannot_occur()
- return hop.inputconst(Bool, False)
+ s_item = hop.args_s[1]
r_item = hop.args_r[1]
v_arg = hop.inputarg(r_item, arg=1)
ll_eq = r_item.get_ll_eq_function() or _ll_equal
v_result = None
for x in t:
+ s_const_item = hop.rtyper.annotator.bookkeeper.immutablevalue(x)
+ if not s_item.contains(s_const_item):
+ continue # corner case, see test_constant_tuple_contains_bug
c_tuple_item = hop.inputconst(r_item, x)
v_equal = hop.gendirectcall(ll_eq, v_arg, c_tuple_item)
if v_result is None:
diff --git a/rpython/rtyper/test/test_rtuple.py
b/rpython/rtyper/test/test_rtuple.py
--- a/rpython/rtyper/test/test_rtuple.py
+++ b/rpython/rtyper/test/test_rtuple.py
@@ -95,6 +95,14 @@
res = self.interpret(f, [50])
assert res is False
+ def test_constant_tuple_contains_bug(self):
+ def f(i):
+ return chr(i) in ('1', '2', '34') # the '34' can never match
+ res = self.interpret(f, [ord('1')])
+ assert res is True
+ res = self.interpret(f, [ord('3')])
+ assert res is False
+
def test_conv(self):
def t0():
return (3, 2, None)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit