[pypy-commit] pypy default: merge
fijal
noreply at buildbot.pypy.org
Tue Jul 14 11:21:54 CEST 2015
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch:
Changeset: r78552:d4482678ba26
Date: 2015-07-14 11:21 +0200
http://bitbucket.org/pypy/pypy/changeset/d4482678ba26/
Log: merge
diff --git a/pypy/module/micronumpy/concrete.py b/pypy/module/micronumpy/concrete.py
--- a/pypy/module/micronumpy/concrete.py
+++ b/pypy/module/micronumpy/concrete.py
@@ -617,15 +617,17 @@
self.impl = impl
self.readonly = readonly
- def getitem(self, item):
- return raw_storage_getitem(lltype.Char, self.impl.storage, item)
+ def getitem(self, index):
+ return raw_storage_getitem(lltype.Char, self.impl.storage,
+ index + self.impl.start)
- def setitem(self, item, v):
- raw_storage_setitem(self.impl.storage, item,
+ def setitem(self, index, v):
+ raw_storage_setitem(self.impl.storage, index + self.impl.start,
rffi.cast(lltype.Char, v))
def getlength(self):
- return self.impl.size
+ return self.impl.size - self.impl.start
def get_raw_address(self):
- return self.impl.storage
+ from rpython.rtyper.lltypesystem import rffi
+ return rffi.ptradd(self.impl.storage, self.impl.start)
diff --git a/pypy/module/micronumpy/strides.py b/pypy/module/micronumpy/strides.py
--- a/pypy/module/micronumpy/strides.py
+++ b/pypy/module/micronumpy/strides.py
@@ -77,7 +77,7 @@
stop = 1
step = 1
lgt = 1
- axis_step = 0
+ axis_step = 0 # both skip this axis in calculate_slice_strides and set stride => 0
def __init__(self):
pass
@@ -127,7 +127,7 @@
except IndexError:
continue
if chunk.step != 0:
- rstrides[j] = s_i * chunk.step
+ rstrides[j] = s_i * chunk.step * chunk.axis_step
rbackstrides[j] = s_i * max(0, chunk.lgt - 1) * chunk.step
rshape[j] = chunk.lgt
j += 1
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
@@ -764,6 +764,8 @@
assert (a[1:] == b).all()
assert (a[1:,newaxis] == d).all()
assert (a[newaxis,1:] == c).all()
+ assert a.strides == (8,)
+ assert a[:, newaxis].strides == (8, 0)
def test_newaxis_assign(self):
from numpy import array, newaxis
@@ -2345,6 +2347,7 @@
assert a[1] == 0xff
assert len(a.data) == 16
assert type(a.data) is buffer
+ assert a[1:].data._pypy_raw_address() - a.data._pypy_raw_address() == a.strides[0]
def test_explicit_dtype_conversion(self):
from numpy import array
diff --git a/pypy/objspace/std/test/test_typeobject.py b/pypy/objspace/std/test/test_typeobject.py
--- a/pypy/objspace/std/test/test_typeobject.py
+++ b/pypy/objspace/std/test/test_typeobject.py
@@ -1031,6 +1031,48 @@
A.__dict__['x'] = 5
assert A.x == 5
+ def test_we_already_got_one_1(self):
+ # Issue #2079: highly obscure: CPython complains if we say
+ # ``__slots__="__dict__"`` and there is already a __dict__...
+ # but from the "best base" only. If the __dict__ comes from
+ # another base, it doesn't complain. Shrug and copy the logic.
+ class A(object):
+ __slots__ = ()
+ class B(object):
+ pass
+ class C(A, B): # "best base" is A
+ __slots__ = ("__dict__",)
+ class D(A, B): # "best base" is A
+ __slots__ = ("__weakref__",)
+ try:
+ class E(B, A): # "best base" is B
+ __slots__ = ("__dict__",)
+ except TypeError, e:
+ assert 'we already got one' in str(e)
+ else:
+ raise AssertionError("TypeError not raised")
+ try:
+ class F(B, A): # "best base" is B
+ __slots__ = ("__weakref__",)
+ except TypeError, e:
+ assert 'we already got one' in str(e)
+ else:
+ raise AssertionError("TypeError not raised")
+
+ def test_we_already_got_one_2(self):
+ class A(object):
+ __slots__ = ()
+ class B:
+ pass
+ class C(A, B): # "best base" is A
+ __slots__ = ("__dict__",)
+ class D(A, B): # "best base" is A
+ __slots__ = ("__weakref__",)
+ class C(B, A): # "best base" is A
+ __slots__ = ("__dict__",)
+ class D(B, A): # "best base" is A
+ __slots__ = ("__weakref__",)
+
class AppTestWithMethodCacheCounter:
spaceconfig = {"objspace.std.withmethodcachecounter": True}
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -1022,7 +1022,7 @@
w_self.nslots = w_bestbase.nslots
return hasoldstylebase
-def create_all_slots(w_self, hasoldstylebase):
+def create_all_slots(w_self, hasoldstylebase, w_bestbase):
space = w_self.space
dict_w = w_self.dict_w
if '__slots__' not in dict_w:
@@ -1040,12 +1040,12 @@
for w_slot_name in slot_names_w:
slot_name = space.str_w(w_slot_name)
if slot_name == '__dict__':
- if wantdict or w_self.hasdict:
+ if wantdict or w_bestbase.hasdict:
raise oefmt(space.w_TypeError,
"__dict__ slot disallowed: we already got one")
wantdict = True
elif slot_name == '__weakref__':
- if wantweakref or w_self.weakrefable:
+ if wantweakref or w_bestbase.weakrefable:
raise oefmt(space.w_TypeError,
"__weakref__ slot disallowed: we already got one")
wantweakref = True
@@ -1106,7 +1106,7 @@
w_self.flag_abstract |= w_base.flag_abstract
hasoldstylebase = copy_flags_from_bases(w_self, w_bestbase)
- create_all_slots(w_self, hasoldstylebase)
+ create_all_slots(w_self, hasoldstylebase, w_bestbase)
ensure_common_attributes(w_self)
More information about the pypy-commit
mailing list