-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix undefined memoryview format #2223
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
4aa3de5
Fix undefined memoryview format
kyamagu de4baa0
Add missing <algorithm> header
kyamagu 2c53550
Add workaround for py27 array compatibility
kyamagu 9ee1514
Workaround py27 memoryview behavior
kyamagu a239716
Fix memoryview constructor from buffer_info
kyamagu 5a3842f
Workaround PyMemoryView_FromMemory availability in py27
kyamagu 7db007d
Fix up memoryview tests
kyamagu 72e4394
Update memoryview test from buffer to check signedness
kyamagu a585ed3
Use static factory method to create memoryview
kyamagu 1c08215
Remove ndim arg from memoryview::frombuffer and add tests
kyamagu db1a2f4
Allow ndim=0 memoryview and documentation fixup
kyamagu 4c7cfef
Use void* to align to frombuffer method signature
kyamagu 640b45c
Add const variants of frombuffer and frommemory
kyamagu 8d508ee
Add memory view section in doc
kyamagu 841ba25
Fix docs
kyamagu 41cd25a
Add test for null buffer
kyamagu 2719c94
Workaround py27 nullptr behavior in test
kyamagu 7f64f8f
Rename frombuffer to from_buffer
kyamagu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Observations, I have to defer to @wjakob judgement for what to do (if anything):
Here the compiler has to work very hard just to put together the array of char pointers:
static const char* formats[] = {"?", "b", "B", "h", "H", "i", "I", "q", "Q", "f", "d", "g"};
That's basically the same as the hard-coded string in
detail/common.h
:static constexpr const char c = "?bBhHiIqQfdg"[...];
It's only a subset of the format strings accepted by the current Python implementation:
https://github.com/python/cpython/blob/e51dd9dad6590bf3a940723fbbaaf4f64a3c9228/Objects/memoryobject.c#L1150
Very unfortunately, this authoritative Python function is hidden away (
static
).My own choice would be to copy the function into pybind11 (probably with modifications), with a long comment to explain why. I'd also carefully check every released Python version to see if the list evolved over time, to track that in our copy, if necessary.
Alternatively, if we decide we only want the subset of format strings, I'd do a slight refactor of
detail/common.h
to make the list available without the very involved detour through the C++ template engine.