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.
Created on 2014年07月31日 08:31 by stangelandcl, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| struct_pack_into.py | stangelandcl, 2014年07月31日 08:31 | Similar to comment. Demonstrates struct.pack_into throwing an exception | ||
| struct_pack_into_memoryview.patch | serhiy.storchaka, 2014年11月18日 18:15 | review | ||
| Messages (9) | |||
|---|---|---|---|
| msg224386 - (view) | Author: Clayton Stangeland (stangelandcl) * | Date: 2014年07月31日 08:31 | |
I expect struct.pack_into to work for a memoryview. Currently struct.pack_into throws an exception.
>>> import struct
>>> buf = bytearray(10)
>>> struct.pack_into("<B", buf, 0, 99)
>>> buf[0]
99
>>> view = memoryview(buf)
>>> view.readonly
False
>>> struct.pack_into("<B", view, 0, 88)
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: expected a writeable buffer object
>>> view[0:1] = 'a'
>>> view[0]
'a'
>>> buf[0]
97
>>> chr(buf[0])
'a'
The memoryview is writeable and from what I can tell from the documentation it implements the buffer interface, but struct.pack_into will not use it.
|
|||
| msg224387 - (view) | Author: Stefan Krah (skrah) * (Python committer) | Date: 2014年07月31日 08:58 | |
This works in Python 3.3+. It is a bug in 2.7, so we have to wait for someone motivated enough to work on an outdated Python version. |
|||
| msg231321 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2014年11月18日 13:48 | |
This issue is similar to issue10212. Here is a patch which makes struct.pack_into() support new buffer protocol. Something similar should be applied to 3.x because PyObject_AsWriteBuffer() is deprecated and not safe. |
|||
| msg231336 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2014年11月18日 18:08 | |
I think you forgot to upload your patch. |
|||
| msg231337 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2014年11月18日 18:15 | |
Oh, sorry. Here is it. |
|||
| msg232931 - (view) | Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) | Date: 2014年12月19日 10:22 | |
lgtm :) |
|||
| msg236352 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2015年02月21日 06:03 | |
Benjamin, what are your thoughts as RM? > Something similar should be applied to 3.x because PyObject_AsWriteBuffer() is deprecated and not safe. Done in issue22896. |
|||
| msg236371 - (view) | Author: Benjamin Peterson (benjamin.peterson) * (Python committer) | Date: 2015年02月21日 16:09 | |
I suppose this is okay. |
|||
| msg236378 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2015年02月21日 17:57 | |
New changeset 4d8e37e54a7d by Serhiy Storchaka in branch '2.7': Issue #22113: struct.pack_into() now supports new buffer protocol (in https://hg.python.org/cpython/rev/4d8e37e54a7d |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:06 | admin | set | github: 66311 |
| 2015年02月21日 17:59:52 | serhiy.storchaka | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2015年02月21日 17:57:16 | python-dev | set | nosy:
+ python-dev messages: + msg236378 |
| 2015年02月21日 16:09:39 | benjamin.peterson | set | messages: + msg236371 |
| 2015年02月21日 06:03:16 | serhiy.storchaka | set | nosy:
+ benjamin.peterson messages: + msg236352 |
| 2014年12月19日 10:22:00 | kristjan.jonsson | set | messages: + msg232931 |
| 2014年12月19日 00:05:47 | Arfrever | set | nosy:
+ Arfrever |
| 2014年12月18日 16:23:58 | serhiy.storchaka | set | keywords: + needs review |
| 2014年11月18日 18:15:15 | serhiy.storchaka | set | files:
+ struct_pack_into_memoryview.patch keywords: + patch messages: + msg231337 |
| 2014年11月18日 18:08:10 | pitrou | set | messages: + msg231336 |
| 2014年11月18日 13:48:36 | serhiy.storchaka | set | nosy:
+ terry.reedy, serhiy.storchaka, kristjan.jonsson, pitrou messages: + msg231321 assignee: serhiy.storchaka stage: needs patch -> patch review |
| 2014年10月14日 17:21:38 | skrah | set | nosy:
- skrah |
| 2014年07月31日 08:58:54 | skrah | set | nosy:
+ skrah messages: + msg224387 components: + Interpreter Core stage: needs patch |
| 2014年07月31日 08:31:11 | stangelandcl | create | |