[ python-Bugs-1563759 ] struct.unpack doens't support buffer protocol objects

SourceForge.net noreply at sourceforge.net
Wed Apr 4 02:45:20 CEST 2007


Bugs item #1563759, was opened at 2006-09-22 17:17
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1563759&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.5
Status: Open
Resolution: None
>Priority: 7
Private: No
Submitted By: Adal Chiriliuc (adalx)
Assigned to: Nobody/Anonymous (nobody)
Summary: struct.unpack doens't support buffer protocol objects

Initial Comment:
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.

----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2007-04-03 19:45

Message:
Logged In: YES 
user_id=80475
Originator: NO

This was due to Bob Ippolito's commit in revision 46184.

----------------------------------------------------------------------

Comment By: Adal Chiriliuc (adalx)
Date: 2006-09-23 07:57

Message:
Logged In: YES 
user_id=1067739

test_struct_run.py works in 2.4, throws exception in 2.5

----------------------------------------------------------------------

Comment By: Adal Chiriliuc (adalx)
Date: 2006-09-23 07:56

Message:
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.


----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2006-09-23 07:12

Message:
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?

----------------------------------------------------------------------

Comment By: Adal Chiriliuc (adalx)
Date: 2006-09-23 06:37

Message:
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.

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2006-09-23 06:19

Message:
Logged In: YES 
user_id=21627

Why is this a bug?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1563759&group_id=5470


More information about the Python-bugs-list mailing list