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
0ce5b6e2
Commit
0ce5b6e2
authored
Nov 10, 2015
by
Stefan Krah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Iaaue #25598: Fix memory_hex from #9951 for non-contiguous buffers.
parent
e46e09d0
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
1 deletion
+28
-1
Lib/test/test_buffer.py
Lib/test/test_buffer.py
+5
-0
Lib/test/test_memoryview.py
Lib/test/test_memoryview.py
+7
-0
Objects/memoryobject.c
Objects/memoryobject.c
+16
-1
No files found.
Lib/test/test_buffer.py
View file @
0ce5b6e2
...
...
@@ -841,6 +841,11 @@ class TestBufferProtocol(unittest.TestCase):
# test tobytes()
self
.
assertEqual
(
result
.
tobytes
(),
b
)
# test hex()
m
=
memoryview
(
result
)
h
=
""
.
join
(
"%02x"
%
c
for
c
in
b
)
self
.
assertEqual
(
m
.
hex
(),
h
)
# lst := expected multi-dimensional logical representation
# flatten(lst) := elements in C-order
ff
=
fmt
if
fmt
else
'B'
...
...
Lib/test/test_memoryview.py
View file @
0ce5b6e2
...
...
@@ -512,6 +512,13 @@ class OtherTest(unittest.TestCase):
m
[
2
:]
=
memoryview
(
p6
).
cast
(
format
)[
2
:]
self
.
assertEqual
(
d
.
value
,
0.6
)
def
test_memoryview_hex
(
self
):
# Issue #9951: memoryview.hex() segfaults with non-contiguous buffers.
x
=
b'0'
*
200000
m1
=
memoryview
(
x
)
m2
=
m1
[::
-
1
]
self
.
assertEqual
(
m2
.
hex
(),
'30'
*
200000
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Objects/memoryobject.c
View file @
0ce5b6e2
...
...
@@ -2156,8 +2156,23 @@ static PyObject *
memory_hex
(
PyMemoryViewObject
*
self
,
PyObject
*
dummy
)
{
Py_buffer
*
src
=
VIEW_ADDR
(
self
);
PyObject
*
bytes
;
PyObject
*
ret
;
CHECK_RELEASED
(
self
);
if
(
MV_C_CONTIGUOUS
(
self
->
flags
))
{
return
_Py_strhex
(
src
->
buf
,
src
->
len
);
}
bytes
=
memory_tobytes
(
self
,
dummy
);
if
(
bytes
==
NULL
)
return
NULL
;
ret
=
_Py_strhex
(
PyBytes_AS_STRING
(
bytes
),
Py_SIZE
(
bytes
));
Py_DECREF
(
bytes
);
return
ret
;
}
static
PyObject
*
...
...
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