gh-112014: correct buffer protocol support in ctypes (use native formats) - #155472
Open
skirpichev wants to merge 1 commit into
Open
gh-112014: correct buffer protocol support in ctypes (use native formats)#155472skirpichev wants to merge 1 commit into
skirpichev wants to merge 1 commit into
Conversation
…e formats) This allows better interoperation with the memoryview, e.g. support for ctypes arrays. Just like NumPy arrays, they also don't specify endianness: ```pycon >>> import numpy as np >>> memoryview(np.ndarray(3, dtype=np.float16)).format 'e' ``` But keep specified byteorder for byte-swapped types.
skirpichev
force-pushed
the
use-native-endianness-in-ctypes/112014
branch
from
August 10, 2026 07:55
45bebeb to
feb9f5a
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
skirpichev
marked this pull request as ready for review
August 10, 2026 08:53
skirpichev
requested review from
encukou and
vstinner
and removed request for
encukou
August 10, 2026 08:53
vstinner
reviewed
Aug 10, 2026
vstinner
left a comment
Member
There was a problem hiding this comment.
I think that I can understand the rationale for this change, but it seems like @encukou has a different opinion on how the issue should be addressed: #112014 (comment).
| Correct the :ref:`buffer protocol <bufferobjects>` support in the | ||
| :mod:`ctypes` module to use the machine’s native format and byte order, | ||
| rather than explicitly specify endianness (by ``'<'`` or ``'>'``). The | ||
| later kept for byte-swapped types. Patch by Sergey B Kirpichev. |
Member
There was a problem hiding this comment.
From this NEWS entry, it's uneasy to understand the rationale for the change. According to #112014 (comment), I understand that before, it was not possible to modify a ctypes type using memoryview, since the buffer format was rejected by memoryview when attempting to modify the view.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This allows better interoperation with the memoryview, e.g. support for ctypes arrays. Just like NumPy arrays, they also don't specify endianness:
But keep specified byteorder for byte-swapped types.