X Tutup
The Wayback Machine - https://web.archive.org/web/20220906175255/https://github.com/python/cpython/issues/96467
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

Array.array Type Codes are not platforminvariant. #96467

Open
dajoke opened this issue Aug 31, 2022 · 4 comments
Open

Array.array Type Codes are not platforminvariant. #96467

dajoke opened this issue Aug 31, 2022 · 4 comments

Comments

@dajoke
Copy link

dajoke commented Aug 31, 2022

The platform-specific type codes interpretations for array.array make it more complex to write python code that contains known type codes and data bytes and will run reliably on all platforms. In particular, the 'l' and 'L' codes are 4 bytes on Windows, but 8 bytes on macOS. The 'i' and 'I' codes seem to be 4 in both cases, but that is a convention, not a requirement. There should be 4-byte and 8-byte integer types that guarantee that size regardless of platform---perhaps '4' and '8' for signed, '5' and '9' for unsigned. (I haven't tested other type codes.) The documentation should be updated in the meantime.

@mdboom
Copy link
Contributor

mdboom commented Aug 31, 2022

This is a problem I've run into in the past writing parsers for binary file formats.

If we do this, we should probably do the same for the struct module which has a similar shortcoming.

@TeamSpen210
Copy link

TeamSpen210 commented Aug 31, 2022

It's not an issue for struct, since you can specify an endianness which also forces a standard size for all the types.

@dajoke
Copy link
Author

dajoke commented Sep 1, 2022

Consistency between array and struct would be very desirable... I actually am using both, had meant to mention that. (I don't think there's any mention of specified endianness forcing a standard size FWIW)

@TeamSpen210
Copy link

TeamSpen210 commented Sep 1, 2022

It's mentioned here in the docs, along with the "standard size" column in the format characters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
X Tutup