Skip to content

gh-112014: Extend memoryview to support formats with explicit endian prefix - #112013

Closed
rianhunter wants to merge 3 commits into
python:mainfrom
rianhunter:fix-accepted-formats-memoryview
Closed

gh-112014: Extend memoryview to support formats with explicit endian prefix#112013
rianhunter wants to merge 3 commits into
python:mainfrom
rianhunter:fix-accepted-formats-memoryview

Conversation

@rianhunter

@rianhunter rianhunter commented Nov 13, 2023

Copy link
Copy Markdown
Contributor

Previously the memoryview object supported the native endian format prefix '@'. It would fail when passed the explicit endian format prefixes '<' (little endian) or '>' (big endian) even when it matched the endianness of the running platform. This affects ctypes code like this:

import ctypes

ArrayType = (ctypes.c_ubyte * 10)

a = ArrayType()
b = memoryview(a)
b[0] = 1 # this used to throw an exception

The fix is to detect when the format prefix used is the endianness of the running platform and then treat it equivalently to the '@' prefix.

Fixes #112014

Previously the memoryview object supported the native endian format
prefix '@'. It would fail when passed the explicit endian format
prefixes '<' (little endian) or '>' (big endian) even when it matched
the endianness of the running platform. This affects ctypes code like
this:

```
import ctypes

ArrayType = (ctypes.c_ubyte * 10)

a = ArrayType()
b = memoryview(a)
b[0] = 1 # this used to throw an exception
```

The fix is to detect when the format prefix used is the endianness
of the running platform and then treat it equivalently to the '@'
prefix.
@ghost

ghost commented Nov 13, 2023

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app

bedevere-app Bot commented Nov 13, 2023

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@arhadthedev arhadthedev changed the title Extend memoryview to support formats with explicit endian prefix gh-112014: Extend memoryview to support formats with explicit endian prefix Nov 13, 2023
@rianhunter

rianhunter commented Nov 13, 2023

Copy link
Copy Markdown
Contributor Author

This PR is incorrect, the '@' format can never be replaced with '<' or '>' since the former has a native size and alignment while the latter have standard size and no alignment. I will close and find another solution.

@rianhunter rianhunter closed this Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow memoryview objects to support ctypes Arrays

1 participant