Yet another possible fix for #528#530
Merged
jonasmalacofilho merged 3 commits intopyusb:masterfrom Jan 8, 2025
Merged
Conversation
731058d to
913546d
Compare
`Device.ctrl_transfer` depends on `create_buffer` raising a `TypeError` if its parameter is not a valid length. In particular, if an array is passed in, `create_buffer` must *not* return a copy of it. Commit 3ea79b0 accidentally broke this and, consequently, any calls to `ctrl_transfer` passing in a buffer. Thanks @kauwua for reporting the issue and discussing the potential solutions. Note that `length * b'\x00'` is actually faster than `bytes(length)` (tested with Python 3.13 on x86_64). Fixes: pyusb#528 Fixes: 3ea79b0 ("util: remove left over python 2 compatibility workaround")
While discussing pyusb#527, @kauwua made the valid point that we could optimize for the case where the user has passed in a byte `array`. In that spirit, prioritize the no-op conversion case, but also accept the parameter to be a length for a new array in preparation for replacing the conditional in `Device.ctrl_transfer`. Related: pyusb#528
913546d to
7000919
Compare
|
Works for me |
Member
Author
|
Thanks! |
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.
(See individual commit messages).
Fixes: #528
Closes: #527
Closes: #529