Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
35613175
Commit
35613175
authored
Oct 03, 2013
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #19014: memoryview.cast() is now allowed on zero-length views.
parent
a3a6f356
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
4 deletions
+13
-4
Lib/test/test_buffer.py
Lib/test/test_buffer.py
+10
-3
Misc/NEWS
Misc/NEWS
+2
-0
Objects/memoryobject.c
Objects/memoryobject.c
+1
-1
No files found.
Lib/test/test_buffer.py
View file @
35613175
...
@@ -2432,15 +2432,22 @@ class TestBufferProtocol(unittest.TestCase):
...
@@ -2432,15 +2432,22 @@ class TestBufferProtocol(unittest.TestCase):
self
.
assertRaises
(
ValueError
,
get_contiguous
,
nd
[::
-
1
],
PyBUF_READ
,
'C'
)
self
.
assertRaises
(
ValueError
,
get_contiguous
,
nd
[::
-
1
],
PyBUF_READ
,
'C'
)
def
test_memoryview_cast_zero_shape
(
self
):
def
test_memoryview_cast_zero_shape
(
self
):
# Casts are undefined if shape contains zeros. These arrays are
# Casts are undefined if buffer is multidimensional and shape
# regarded as C-contiguous by Numpy and PyBuffer_GetContiguous(),
# contains zeros. These arrays are regarded as C-contiguous by
# so they are not caught by the test for C-contiguity in memory_cast().
# Numpy and PyBuffer_GetContiguous(), so they are not caught by
# the test for C-contiguity in memory_cast().
items
=
[
1
,
2
,
3
]
items
=
[
1
,
2
,
3
]
for
shape
in
([
0
,
3
,
3
],
[
3
,
0
,
3
],
[
0
,
3
,
3
]):
for
shape
in
([
0
,
3
,
3
],
[
3
,
0
,
3
],
[
0
,
3
,
3
]):
ex
=
ndarray
(
items
,
shape
=
shape
)
ex
=
ndarray
(
items
,
shape
=
shape
)
self
.
assertTrue
(
ex
.
c_contiguous
)
self
.
assertTrue
(
ex
.
c_contiguous
)
msrc
=
memoryview
(
ex
)
msrc
=
memoryview
(
ex
)
self
.
assertRaises
(
TypeError
,
msrc
.
cast
,
'c'
)
self
.
assertRaises
(
TypeError
,
msrc
.
cast
,
'c'
)
# Monodimensional empty view can be cast (issue #19014).
for
fmt
,
_
,
_
in
iter_format
(
1
,
'memoryview'
):
msrc
=
memoryview
(
b''
)
m
=
msrc
.
cast
(
fmt
)
self
.
assertEqual
(
m
.
tobytes
(),
b''
)
self
.
assertEqual
(
m
.
tolist
(),
[])
def
test_memoryview_struct_module
(
self
):
def
test_memoryview_struct_module
(
self
):
...
...
Misc/NEWS
View file @
35613175
...
@@ -12,6 +12,8 @@ What's New in Python 3.3.3 release candidate 1?
...
@@ -12,6 +12,8 @@ What's New in Python 3.3.3 release candidate 1?
Core and Builtins
Core and Builtins
-----------------
-----------------
- Issue #19014: memoryview.cast() is now allowed on zero-length views.
- Issue #19098: Prevent overflow in the compiler when the recursion limit is set
- Issue #19098: Prevent overflow in the compiler when the recursion limit is set
absurdly high.
absurdly high.
...
...
Objects/memoryobject.c
View file @
35613175
...
@@ -1330,7 +1330,7 @@ memory_cast(PyMemoryViewObject *self, PyObject *args, PyObject *kwds)
...
@@ -1330,7 +1330,7 @@ memory_cast(PyMemoryViewObject *self, PyObject *args, PyObject *kwds)
"memoryview: casts are restricted to C-contiguous views"
);
"memoryview: casts are restricted to C-contiguous views"
);
return
NULL
;
return
NULL
;
}
}
if
(
zero_in_shape
(
self
))
{
if
(
(
shape
||
self
->
view
.
ndim
!=
1
)
&&
zero_in_shape
(
self
))
{
PyErr_SetString
(
PyExc_TypeError
,
PyErr_SetString
(
PyExc_TypeError
,
"memoryview: cannot cast view with zeros in shape or strides"
);
"memoryview: cannot cast view with zeros in shape or strides"
);
return
NULL
;
return
NULL
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment