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 2012年09月03日 16:24 by belopolsky, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (5) | |||
|---|---|---|---|
| msg169771 - (view) | Author: Alexander Belopolsky (belopolsky) * (Python committer) | Date: 2012年09月03日 16:24 | |
Starting with the example in memoryview documentation:
>>> from ctypes import BigEndianStructure, c_long
>>> class BEPoint(BigEndianStructure):
... _fields_ = [("x", c_long), ("y", c_long)]
...
>>> point = BEPoint(100, 200)
>>> a = memoryview(point)
I am trying to unpack the resulting view:
>>> a.tolist()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NotImplementedError: memoryview: unsupported format T{>l:x:>l:y:}
>>> struct.unpack_from(a.format,a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
struct.error: bad char in struct format
>>> struct.unpack_from('>ll',a)
(0, 100)
It looks like there is one or more bugs in play here.
|
|||
| msg169777 - (view) | Author: Stefan Krah (skrah) * (Python committer) | Date: 2012年09月03日 16:53 | |
It's deliberately not implemented (and documented): Since memoryview is a complete rewrite, I tried go easy on new features in order to facilitate review. My plan was to implement struct packing/unpacking in 3.3.1 in the same manner as in the new equality function. The struct error you see is tracked in #3132. |
|||
| msg169782 - (view) | Author: Alexander Belopolsky (belopolsky) * (Python committer) | Date: 2012年09月03日 16:59 | |
What about
>>> struct.unpack_from('>ll',a)
(0, 100)
shouldn't that return (100, 200)?
|
|||
| msg169789 - (view) | Author: Stefan Krah (skrah) * (Python committer) | Date: 2012年09月03日 17:43 | |
'>' in struct syntax implies "standard size" for 'l', which is 4 bytes.
ctypes uses machine size for c_long, so on an LP64 machine you can unpack
the data as:
>>> struct.unpack_from('>qq', a)
(100, 200)
|
|||
| msg229296 - (view) | Author: Stefan Krah (skrah) * (Python committer) | Date: 2014年10月14日 14:58 | |
Closing, since the main request is tracked in #3132. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:35 | admin | set | github: 60061 |
| 2014年10月14日 15:21:10 | skrah | set | status: open -> closed |
| 2014年10月14日 14:58:02 | skrah | set | resolution: duplicate messages: + msg229296 stage: needs patch -> |
| 2012年09月04日 07:51:36 | Arfrever | set | nosy:
+ Arfrever |
| 2012年09月03日 17:43:36 | skrah | set | messages: + msg169789 |
| 2012年09月03日 16:59:35 | belopolsky | set | messages: + msg169782 |
| 2012年09月03日 16:53:53 | skrah | set | versions:
- Python 3.4 title: memoryview of a ctypes struct has incompatible invalid format -> memoryview: complete support for struct packing/unpacking messages: + msg169777 components: + Interpreter Core type: behavior -> enhancement stage: needs patch |
| 2012年09月03日 16:24:57 | belopolsky | create | |