[pypy-commit] pypy py3.5: merge heads
arigo
pypy.commits at gmail.com
Sun Feb 12 04:40:44 EST 2017
Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r90069:ffcc62f39db7
Date: 2017-02-12 10:40 +0100
http://bitbucket.org/pypy/pypy/changeset/ffcc62f39db7/
Log: merge heads
diff --git a/pypy/module/cpyext/longobject.py b/pypy/module/cpyext/longobject.py
--- a/pypy/module/cpyext/longobject.py
+++ b/pypy/module/cpyext/longobject.py
@@ -70,9 +70,9 @@
@cpython_api([PyObject], lltype.Signed, error=-1)
def PyLong_AsLong(space, w_long):
"""
- Return a C long representation of the contents of pylong. If
- pylong is greater than LONG_MAX, an OverflowError is raised
- and -1 will be returned."""
+ Get a C long int from an int object or any object that has an __int__
+ method. Return -1 and set an error if overflow occurs.
+ """
return space.int_w(space.int(w_long))
@cpython_api([PyObject], Py_ssize_t, error=-1)
diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py
--- a/pypy/module/cpyext/slotdefs.py
+++ b/pypy/module/cpyext/slotdefs.py
@@ -323,11 +323,11 @@
self.w_obj = w_obj # kept alive
self.pyobj = make_ref(space, w_obj)
self.format = format
- if not shape:
+ if shape is None:
self.shape = [size]
else:
self.shape = shape
- if not strides:
+ if strides is None:
self.strides = [1]
else:
self.strides = strides
diff --git a/pypy/module/cpyext/test/test_arraymodule.py b/pypy/module/cpyext/test/test_arraymodule.py
--- a/pypy/module/cpyext/test/test_arraymodule.py
+++ b/pypy/module/cpyext/test/test_arraymodule.py
@@ -69,6 +69,14 @@
b'\x03\0\0\0'
b'\x04\0\0\0')
+ def test_0d_view(self):
+ module = self.import_module(name='array')
+ arr = module.array('B', b'\0\0\0\x01')
+ buf = memoryview(arr).cast('i', shape=())
+ assert bytes(buf) == b'\0\0\0\x01'
+ assert buf.shape == ()
+ assert buf.strides == ()
+
def test_binop_mul_impl(self):
# check that rmul is called
module = self.import_module(name='array')
diff --git a/pypy/objspace/std/memoryobject.py b/pypy/objspace/std/memoryobject.py
--- a/pypy/objspace/std/memoryobject.py
+++ b/pypy/objspace/std/memoryobject.py
@@ -117,6 +117,9 @@
return ''.join(self.copy_buffer())
def copy_buffer(self):
+ if self.getndim() == 0:
+ itemsize = self.getitemsize()
+ return [self.buf.getslice(0, itemsize, 1, itemsize)]
data = []
self._copy_rec(0, data, 0)
return data
@@ -126,12 +129,12 @@
shape = shapes[idim]
strides = self.getstrides()
- if self.getndim()-1 == idim:
- self._copy_base(data,off)
+ if self.getndim() - 1 == idim:
+ self._copy_base(data, off)
return
for i in range(shape):
- self._copy_rec(idim+1,data,off)
+ self._copy_rec(idim + 1, data, off)
off += strides[idim]
def _copy_base(self, data, off):
@@ -428,14 +431,10 @@
def w_get_shape(self, space):
self._check_released(space)
- if self.getndim() == 0:
- return space.w_None
return space.newtuple([space.wrap(x) for x in self.getshape()])
def w_get_strides(self, space):
self._check_released(space)
- if self.getndim() == 0:
- return space.w_None
return space.newtuple([space.wrap(x) for x in self.getstrides()])
def w_get_suboffsets(self, space):
@@ -569,7 +568,7 @@
def _init_flags(self):
buf = self.buf
- ndim = buf.getndim()
+ ndim = self.getndim()
flags = 0
if ndim == 0:
flags |= MEMORYVIEW_SCALAR | MEMORYVIEW_C | MEMORYVIEW_FORTRAN
diff --git a/pypy/objspace/std/test/test_memoryobject.py b/pypy/objspace/std/test/test_memoryobject.py
--- a/pypy/objspace/std/test/test_memoryobject.py
+++ b/pypy/objspace/std/test/test_memoryobject.py
@@ -27,6 +27,14 @@
assert len(w) == 2
exc = raises(TypeError, "memoryview('foobar')")
+ def test_0d(self):
+ v = memoryview(b'x').cast('B', ())
+ assert len(v) == 1
+ assert v.shape == ()
+ assert v.strides == ()
+ assert v.tobytes() == b'x'
+ #assert v[()] == b'x'[0]
+
def test_rw(self):
data = bytearray(b'abcefg')
v = memoryview(data)
More information about the pypy-commit
mailing list