Author: Armin Rigo <[email protected]>
Branch: stm-gc
Changeset: r54554:bc86c14c03bd
Date: 2012-04-19 19:47 +0200
http://bitbucket.org/pypy/pypy/changeset/bc86c14c03bd/
Log: hg merge default
diff --git a/pypy/annotation/description.py b/pypy/annotation/description.py
--- a/pypy/annotation/description.py
+++ b/pypy/annotation/description.py
@@ -229,8 +229,8 @@
return thing
elif hasattr(thing, '__name__'): # mostly types and functions
return thing.__name__
- elif hasattr(thing, 'name'): # mostly ClassDescs
- return thing.name
+ elif hasattr(thing, 'name') and isinstance(thing.name, str):
+ return thing.name # mostly ClassDescs
elif isinstance(thing, tuple):
return '_'.join(map(nameof, thing))
else:
diff --git a/pypy/jit/backend/x86/assembler.py
b/pypy/jit/backend/x86/assembler.py
--- a/pypy/jit/backend/x86/assembler.py
+++ b/pypy/jit/backend/x86/assembler.py
@@ -1656,15 +1656,21 @@
else:
# XXX hard-coded assumption: to go from an object to its class
# we use the following algorithm:
- # - read the typeid from mem(locs[0]), i.e. at offset 0
- # - keep the lower 16 bits read there
- # - multiply by 4 and use it as an offset in type_info_group
- # - add 16 bytes, to go past the TYPE_INFO structure
+ # - read the typeid from mem(locs[0]), i.e. at offset 0;
+ # this is a complete word (N=4 bytes on 32-bit, N=8 on
+ # 64-bits)
+ # - keep the lower half of what is read there (i.e.
+ # truncate to an unsigned 'N / 2' bytes value)
+ # - multiply by 4 (on 32-bits only) and use it as an
+ # offset in type_info_group
+ # - add 16/32 bytes, to go past the TYPE_INFO structure
loc = locs[1]
assert isinstance(loc, ImmedLoc)
classptr = loc.value
# here, we have to go back from 'classptr' to the value expected
- # from reading the 16 bits in the object header
+ # from reading the half-word in the object header. Note that
+ # this half-word is at offset 0 on a little-endian machine;
+ # it would be at offset 2 or 4 on a big-endian machine.
from pypy.rpython.memory.gctypelayout import GCData
sizeof_ti = rffi.sizeof(GCData.TYPE_INFO)
type_info_group = llop.gc_get_type_info_group(llmemory.Address)
diff --git a/pypy/module/cpyext/iterator.py b/pypy/module/cpyext/iterator.py
--- a/pypy/module/cpyext/iterator.py
+++ b/pypy/module/cpyext/iterator.py
@@ -22,7 +22,7 @@
cannot be iterated."""
return space.iter(w_obj)
-@cpython_api([PyObject], PyObject, error=CANNOT_FAIL)
+@cpython_api([PyObject], PyObject)
def PyIter_Next(space, w_obj):
"""Return the next value from the iteration o. If the object is an
iterator, this retrieves the next value from the iteration, and returns
diff --git a/pypy/module/cpyext/test/test_iterator.py
b/pypy/module/cpyext/test/test_iterator.py
--- a/pypy/module/cpyext/test/test_iterator.py
+++ b/pypy/module/cpyext/test/test_iterator.py
@@ -15,3 +15,8 @@
assert space.unwrap(api.PyIter_Next(w_iter)) == 3
assert api.PyIter_Next(w_iter) is None
assert not api.PyErr_Occurred()
+
+ def test_iternext_error(self,space, api):
+ assert api.PyIter_Next(space.w_None) is None
+ assert api.PyErr_Occurred() is space.w_TypeError
+ api.PyErr_Clear()
diff --git a/pypy/module/cpyext/test/test_unicodeobject.py
b/pypy/module/cpyext/test/test_unicodeobject.py
--- a/pypy/module/cpyext/test/test_unicodeobject.py
+++ b/pypy/module/cpyext/test/test_unicodeobject.py
@@ -453,10 +453,22 @@
def test_tailmatch(self, space, api):
w_str = space.wrap(u"abcdef")
- assert api.PyUnicode_Tailmatch(w_str, space.wrap("cde"), 2, 10, 1) == 1
- assert api.PyUnicode_Tailmatch(w_str, space.wrap("cde"), 1, 5, -1) == 1
+ # prefix match
+ assert api.PyUnicode_Tailmatch(w_str, space.wrap("cde"), 2, 9, -1) == 1
+ assert api.PyUnicode_Tailmatch(w_str, space.wrap("cde"), 2, 4, -1) ==
0 # ends at 'd'
+ assert api.PyUnicode_Tailmatch(w_str, space.wrap("cde"), 1, 6, -1) ==
0 # starts at 'b'
+ assert api.PyUnicode_Tailmatch(w_str, space.wrap("cdf"), 2, 6, -1) == 0
+ # suffix match
+ assert api.PyUnicode_Tailmatch(w_str, space.wrap("cde"), 1, 5, 1) == 1
+ assert api.PyUnicode_Tailmatch(w_str, space.wrap("cde"), 3, 5, 1) ==
0 # starts at 'd'
+ assert api.PyUnicode_Tailmatch(w_str, space.wrap("cde"), 1, 6, 1) ==
0 # ends at 'f'
+ assert api.PyUnicode_Tailmatch(w_str, space.wrap("bde"), 1, 5, 1) == 0
+ # type checks
self.raises(space, api, TypeError,
api.PyUnicode_Tailmatch, w_str, space.wrap(3), 2, 10, 1)
+ self.raises(space, api, TypeError,
+ api.PyUnicode_Tailmatch, space.wrap(3), space.wrap("abc"),
+ 2, 10, 1)
def test_count(self, space, api):
w_str = space.wrap(u"abcabdab")
diff --git a/pypy/module/cpyext/unicodeobject.py
b/pypy/module/cpyext/unicodeobject.py
--- a/pypy/module/cpyext/unicodeobject.py
+++ b/pypy/module/cpyext/unicodeobject.py
@@ -593,7 +593,7 @@
suffix match), 0 otherwise. Return -1 if an error occurred."""
str = space.unicode_w(w_str)
substr = space.unicode_w(w_substr)
- if rffi.cast(lltype.Signed, direction) >= 0:
+ if rffi.cast(lltype.Signed, direction) <= 0:
return stringtype.stringstartswith(str, substr, start, end)
else:
return stringtype.stringendswith(str, substr, start, end)
diff --git a/pypy/module/pypyjit/test_pypy_c/test_exception.py
b/pypy/module/pypyjit/test_pypy_c/test_exception.py
--- a/pypy/module/pypyjit/test_pypy_c/test_exception.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_exception.py
@@ -91,3 +91,29 @@
--TICK--
jump(..., descr=...)
""")
+
+ def test_continue_in_finally(self):
+ # check that 'continue' inside a try:finally: block is correctly
+ # detected as closing a loop
+ py.test.skip("is this case important?")
+ def f(n):
+ i = 0
+ while 1:
+ try:
+ if i < n:
+ continue
+ finally:
+ i += 1
+ return i
+
+ log = self.run(f, [2000])
+ assert log.result == 2001
+ loop, = log.loops_by_filename(self.filepath)
+ assert loop.match("""
+ i40 = int_add_ovf(i31, 1)
+ guard_no_overflow(descr=...)
+ i41 = int_lt(i40, i33)
+ guard_true(i41, descr=...)
+ --TICK--
+ jump(..., descr=...)
+ """)
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -414,7 +414,8 @@
def contains(space, w_container, w_item):
w_descr = space.lookup(w_container, '__contains__')
if w_descr is not None:
- return space.get_and_call_function(w_descr, w_container, w_item)
+ w_result = space.get_and_call_function(w_descr, w_container,
w_item)
+ return space.nonzero(w_result)
return space._contains(w_container, w_item)
def _contains(space, w_container, w_item):
diff --git a/pypy/objspace/std/test/test_methodcache.py
b/pypy/objspace/std/test/test_methodcache.py
--- a/pypy/objspace/std/test/test_methodcache.py
+++ b/pypy/objspace/std/test/test_methodcache.py
@@ -63,8 +63,31 @@
assert a.f() == 42 + i
A.f = eval("lambda self: %s" % (42 + i + 1, ))
cache_counter = __pypy__.method_cache_counter("f")
- # the cache hits come from A.f = ..., which first does a lookup on A as
- # well
+ #
+ # a bit of explanation about what's going on. (1) is the line "a.f()"
+ # and (2) is "A.f = ...".
+ #
+ # at line (1) we do the lookup on type(a).f
+ #
+ # at line (2) we do a setattr on A. However, descr_setattr does also a
+ # lookup of type(A).f i.e. type.f, to check if by chance 'f' is a data
+ # descriptor.
+ #
+ # At the first iteration:
+ # (1) is a miss because it's the first lookup of A.f. The result is
cached
+ #
+ # (2) is a miss because it is the first lookup of type.f. The
+ # (non-existant) result is cached. The version of A changes, and 'f'
+ # is changed to be a cell object, so that subsequest assignments won't
+ # change the version of A
+ #
+ # At the second iteration:
+ # (1) is a miss because the version of A changed just before
+ # (2) is a hit, because type.f is cached. The version of A no longer
changes
+ #
+ # At the third and subsequent iterations:
+ # (1) is a hit, because the version of A did not change
+ # (2) is a hit, see above
assert cache_counter == (17, 3)
def test_subclasses(self):
diff --git a/pypy/objspace/std/test/test_stringformat.py
b/pypy/objspace/std/test/test_stringformat.py
--- a/pypy/objspace/std/test/test_stringformat.py
+++ b/pypy/objspace/std/test/test_stringformat.py
@@ -295,12 +295,11 @@
assert u'%x' % ten == 'a'
def test_long_no_overflow(self):
- big = 100000000000L
- assert "%x" % big == "174876e800"
+ big = 0x1234567890987654321
+ assert "%x" % big == "1234567890987654321"
def test_missing_cases(self):
- big = -123456789012345678901234567890L
- print '%032d' % big
+ big = -123456789012345678901234567890
assert '%032d' % big == '-0123456789012345678901234567890'
def test_invalid_char(self):
diff --git a/pypy/objspace/test/test_descroperation.py
b/pypy/objspace/test/test_descroperation.py
--- a/pypy/objspace/test/test_descroperation.py
+++ b/pypy/objspace/test/test_descroperation.py
@@ -694,5 +694,31 @@
l = len(X(X(2)))
assert l == 2 and type(l) is int
+ def test_bool___contains__(self):
+ class X(object):
+ def __contains__(self, item):
+ if item == 'foo':
+ return 42
+ else:
+ return 'hello world'
+ x = X()
+ res = 'foo' in x
+ assert res is True
+ res = 'bar' in x
+ assert res is True
+ #
+ class MyError(Exception):
+ pass
+ class CannotConvertToBool(object):
+ def __nonzero__(self):
+ raise MyError
+ class X(object):
+ def __contains__(self, item):
+ return CannotConvertToBool()
+ x = X()
+ raises(MyError, "'foo' in x")
+
+
+
class AppTestWithBuiltinShortcut(AppTest_Descroperation):
OPTIONS = {'objspace.std.builtinshortcut': True}
diff --git a/pypy/rpython/module/ll_os.py b/pypy/rpython/module/ll_os.py
--- a/pypy/rpython/module/ll_os.py
+++ b/pypy/rpython/module/ll_os.py
@@ -1168,8 +1168,11 @@
DIRENTP = lltype.Ptr(DIRENT)
os_opendir = self.llexternal('opendir', [rffi.CCHARP], DIRP,
compilation_info=compilation_info)
+ # XXX macro=True is hack to make sure we get the correct kind of
+ # dirent struct (which depends on defines)
os_readdir = self.llexternal('readdir', [DIRP], DIRENTP,
- compilation_info=compilation_info)
+ compilation_info=compilation_info,
+ macro=True)
os_closedir = self.llexternal('closedir', [DIRP], rffi.INT,
compilation_info=compilation_info)
diff --git a/pypy/translator/c/extfunc.py b/pypy/translator/c/extfunc.py
--- a/pypy/translator/c/extfunc.py
+++ b/pypy/translator/c/extfunc.py
@@ -5,7 +5,6 @@
from pypy.rpython.lltypesystem.rstr import STR, mallocstr
from pypy.rpython.lltypesystem import rstr
from pypy.rpython.lltypesystem import rlist
-from pypy.rpython.module import ll_time, ll_os
# table of functions hand-written in src/ll_*.h
# Note about *.im_func: The annotator and the rtyper expect direct
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit