This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: struct.unpack doens't support buffer protocol objects
Type: Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: loewis, moese, rhettinger
Priority: high Keywords:

Created on 2006-09-22 22:17 by moese, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test_struct.py moese, 2006-09-23 12:56 Append to end of test_struct.py
test_struct_run.py moese, 2006-09-23 12:57 Runnable test version for both Python 2.4 and 2.5
Messages (8)
msg29930 - (view) Author: Moese (moese) Date: 2006-09-22 22:17
If you pass an object which supports the buffer
protocol to struct.unpack it will fail because it
specifically checks for a string.

You should use PyObject_AsReadBuffer instead.

If this code is performance critical, you could add an
unpack_buffer method or something like that.
msg29931 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2006-09-23 11:19
Logged In: YES 
user_id=21627

Why is this a bug?
msg29932 - (view) Author: Moese (moese) Date: 2006-09-23 11:37
Logged In: YES 
user_id=1067739

Well, because it broke previously working code and there is
no warning in the documentation about that.

In the mean-time, I've found out about pack_into and
unpack_from which accept buffer like objects. Note that they
are not documented in the struct module section, only
mentioned in the "What's new" chapter.
msg29933 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2006-09-23 12:12
Logged In: YES 
user_id=21627

Ah, so you say that was working previously? It's a bug,
then. Can you provide a test case?
msg29934 - (view) Author: Moese (moese) Date: 2006-09-23 12:56
Logged In: YES 
user_id=1067739

The actual code which broke used a Pointer extension class
implemented in C++.

I reproduced the problem using array.array. Using array in
this way (without calling tostring) looks a bit weird.
msg29935 - (view) Author: Moese (moese) Date: 2006-09-23 12:57
Logged In: YES 
user_id=1067739

test_struct_run.py works in 2.4, throws exception in 2.5
msg29936 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2007-04-04 00:45
This was due to Bob Ippolito's commit in revision 46184.
msg29937 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2007-04-04 20:32
Fixed.  See revision 54690.
History
Date User Action Args
2022-04-11 14:56:20adminsetgithub: 44012
2006-09-22 22:17:45moesecreate