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
685bdb06
Commit
685bdb06
authored
Apr 04, 2007
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug #1563759: struct.unpack doens't support buffer protocol objects
parent
e3dcb878
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
3 deletions
+25
-3
Lib/test/test_struct.py
Lib/test/test_struct.py
+6
-0
Misc/NEWS
Misc/NEWS
+2
-0
Modules/_struct.c
Modules/_struct.c
+17
-3
No files found.
Lib/test/test_struct.py
View file @
685bdb06
...
...
@@ -612,8 +612,14 @@ def test_pack_into_fn():
assertRaises
(
struct
.
error
,
pack_into
,
small_buf
,
0
,
test_string
)
assertRaises
(
struct
.
error
,
pack_into
,
small_buf
,
2
,
test_string
)
def
test_unpack_with_buffer
():
# SF bug 1563759: struct.unpack doens't support buffer protocol objects
data
=
array
.
array
(
'B'
,
'
\
x12
\
x34
\
x56
\
x78
'
)
value
,
=
struct
.
unpack
(
'>I'
,
data
)
vereq
(
value
,
0x12345678
)
# Test methods to pack and unpack from buffers rather than strings.
test_unpack_from
()
test_pack_into
()
test_pack_into_fn
()
test_unpack_with_buffer
()
Misc/NEWS
View file @
685bdb06
...
...
@@ -134,6 +134,8 @@ Core and builtins
Extension
Modules
-----------------
-
Bug
#
1563759
:
struct
.
unpack
doens
't support buffer protocol objects
- Bug #1686475: Support stat'
ing
open
files
on
Windows
again
.
-
Bug
#
1647541
:
Array
module
's buffer interface can now handle empty arrays.
...
...
Modules/_struct.c
View file @
685bdb06
...
...
@@ -1485,17 +1485,31 @@ strings.");
static
PyObject
*
s_unpack
(
PyObject
*
self
,
PyObject
*
inputstr
)
{
char
*
start
;
int
len
;
PyObject
*
args
;
PyStructObject
*
soself
=
(
PyStructObject
*
)
self
;
assert
(
PyStruct_Check
(
self
));
assert
(
soself
->
s_codes
!=
NULL
);
if
(
inputstr
==
NULL
||
!
PyString_Check
(
inputstr
)
||
PyString_GET_SIZE
(
inputstr
)
!=
soself
->
s_size
)
{
if
(
inputstr
!=
NULL
&&
PyString_Check
(
inputstr
)
&&
PyString_GET_SIZE
(
inputstr
)
==
soself
->
s_size
)
{
return
s_unpack_internal
(
soself
,
PyString_AS_STRING
(
inputstr
));
}
args
=
PyTuple_Pack
(
1
,
inputstr
);
if
(
args
==
NULL
)
return
NULL
;
if
(
!
PyArg_ParseTuple
(
args
,
"s#:unpack"
,
&
start
,
&
len
))
{
Py_DECREF
(
args
);
return
NULL
;
}
Py_DECREF
(
args
);
if
(
soself
->
s_size
!=
len
)
{
PyErr_Format
(
StructError
,
"unpack requires a string argument of length %zd"
,
soself
->
s_size
);
return
NULL
;
}
return
s_unpack_internal
(
soself
,
PyString_AS_STRING
(
inputstr
)
);
return
s_unpack_internal
(
soself
,
start
);
}
PyDoc_STRVAR
(
s_unpack_from__doc__
,
...
...
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