[issue18225] ctypes Structure data size is incorrect

2013-06-17 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc added the comment:

You can also use _pack_ = 1 to override the default alignment rules:
http://docs.python.org/3/library/ctypes.html#ctypes.Structure._pack_

--
nosy: +amaury.forgeotdarc

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18225
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18225] ctypes Structure data size is incorrect

2013-06-15 Thread Tomer Levi

New submission from Tomer Levi:

Whenever you create a ctypes.Structure with mixed ctypes, the size of all 
components is calculated by the size of largest one. This is especially 
irritating when trying to use Structure on bytearray.
The problem repeated for me in Python2.6 and 2.7 (both 32bit and 64bit 
versions) [My computer is 64bit]

Example:
#Creating a Structure that should take up 5 bytes
class Test(ctypes.Structure):
_fields_ = [(test, ctypes.c_byte),
(test2, ctypes.c_uint32),]

#Initiating the Structure
Test.from_buffer(bytearray(5))

--- OUTPUT 

Traceback (most recent call last):

  File ipython-input-45-cd4b7501baee, line 1, in module
Test.from_buffer(bytearray(5))

ValueError: Buffer size too small (5 instead of at least 8 bytes)

--
components: ctypes
messages: 191213
nosy: Tomer.Levi
priority: normal
severity: normal
status: open
title: ctypes Structure data size is incorrect
type: behavior
versions: Python 2.6, Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18225
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18225] ctypes Structure data size is incorrect

2013-06-15 Thread Alex Gaynor

Alex Gaynor added the comment:

This is how padding works in the C ABI, not a bug.

--
nosy: +alex
resolution:  - invalid
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18225
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com