Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Length of struct.pack('HL', 1,1) incorrect (8 instead of 6 bytes) #47731

Closed
dparolin mannequin opened this issue Aug 1, 2008 · 2 comments
Closed

Length of struct.pack('HL', 1,1) incorrect (8 instead of 6 bytes) #47731

dparolin mannequin opened this issue Aug 1, 2008 · 2 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@dparolin
Copy link
Mannequin

dparolin mannequin commented Aug 1, 2008

BPO 3481
Nosy @amauryfa

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2008-08-01.00:40:32.380>
created_at = <Date 2008-08-01.00:17:05.150>
labels = ['invalid', 'type-bug', 'library']
title = "Length of struct.pack('HL', 1,1) incorrect (8 instead of 6 bytes)"
updated_at = <Date 2008-08-01.00:40:32.122>
user = 'https://bugs.python.org/dparolin'

bugs.python.org fields:

activity = <Date 2008-08-01.00:40:32.122>
actor = 'amaury.forgeotdarc'
assignee = 'none'
closed = True
closed_date = <Date 2008-08-01.00:40:32.380>
closer = 'amaury.forgeotdarc'
components = ['Library (Lib)']
creation = <Date 2008-08-01.00:17:05.150>
creator = 'dparolin'
dependencies = []
files = []
hgrepos = []
issue_num = 3481
keywords = []
message_count = 2.0
messages = ['70535', '70536']
nosy_count = 2.0
nosy_names = ['amaury.forgeotdarc', 'dparolin']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue3481'
versions = ['Python 2.5', 'Python 2.4']

@dparolin
Copy link
Mannequin Author

dparolin mannequin commented Aug 1, 2008

Python Versions tested:
Windows 2.5.2 (r252:60911)
Debian Linux Python 2.4.4

Example:
>>> import struct
>>> struct.pack('HL', 1, 1)

results in '\x01\x00\x00\x00\x01\x00\x00\x00'
although '\x01\x00\x01\x00\x00\x00' was expected.

if concatenated or done separately
>>> struct.pack('H', 1) + struct.pack('L', 1) 

result is as expected '\x01\x00\x01\x00\x00\x00'
or
'\x01\x00' and '\x01\x00\x00\x00' respectively

Error:
Length is 8 where it should be 6
This is as well true for "hl", "hL" and "Hl".

Free description:
I could not find another error regarding that, nor any information using
popular search.
Further no explanation found why that might be valid behaviour.

Regards,
Dominique

@dparolin dparolin mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Aug 1, 2008
@amauryfa
Copy link
Member

amauryfa commented Aug 1, 2008

The struct module is correct.
You see here the result of "alignment": the address of a long is always
a multiple of the size of a long.

The struct module mimics the C compiler: a "struct { short x; long y;
}", will actually occupy 8 bytes in memory (on a 32bit processor).
There are two padding bytes, that are not used.

@amauryfa amauryfa closed this as completed Aug 1, 2008
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant