Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
gh-112015: Implementctypes.memoryview_at()#112018
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation
ctypes currently has no way to easily create a buffer objectfrom a pointer and a dynamic size. It is possible to creatememoryview objects of array objects (e.g.memoryview((c_ubyte * 10)())) but this is excessively slow whenimplementing a callback function in Python that is passed adynamic void * and a size_t.`ctypes.buffer_at()` fills that gap in the API. This is similarto `ffi.buffer()` in the cffi module.
ctypes.buffer_at()ctypes.buffer_at()Uh oh!
There was an error while loading.Please reload this page.
serhiy-storchaka left a comment
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.
Please add tests and What's New entry.
And I think that it is worth to support large buffers.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Misc/NEWS.d/next/Library/2023-11-12-21-53-40.gh-issue-112015.2WPRxE.rst OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Misc/NEWS.d/next/Library/2023-11-12-21-53-40.gh-issue-112015.2WPRxE.rst OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Documentation improvementsCo-authored-by: Serhiy Storchaka <storchaka@gmail.com>
It's a more descriptive and precise name.
It's more common that the user will want a memoryview object that canbe mutated. An immutable object is more rare, so make the default casereturn a mutable object.
rianhunter commentedJan 19, 2024
When merging, just flatten all the commits down to a single commit. |
ctypes.buffer_at()ctypes.memoryview_at()Uh oh!
There was an error while loading.Please reload this page.
rianhunter commentedSep 19, 2024
Abandoned |
encukou commentedSep 26, 2024
No worries. Thank you for your work so far! |
rianhunter commentedSep 26, 2024
No problem, feel free |
…tics. Improve tests and docs.
encukou commentedNov 29, 2024
OK. I went back to the |
encukou commentedDec 16, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Does this look interesting to you,@ZeroIntensity or@picnixz? |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
ZeroIntensity commentedDec 16, 2024
I'll review sometime soon (today or in the next few days). |
Misc/NEWS.d/next/Library/2023-11-12-21-53-40.gh-issue-112015.2WPRxE.rst OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
ZeroIntensity left a comment
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.
Mostly LGTM
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
ZeroIntensity left a comment
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.
I'm happy with this!
b4f799b intopython:mainUh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>Co-authored-by: Petr Viktorin <encukou@gmail.com>Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>Co-authored-by: Petr Viktorin <encukou@gmail.com>Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Uh oh!
There was an error while loading.Please reload this page.
ctypes currently has no way to easily create a buffer object from a pointer and a dynamic size. It is possible to create memoryview objects of array objects that refer to existing memory (e.g.
memoryview((c_byte * size).from_address(address))) but this is inefficient and the resulting memoryview object doesn't allow editing via python (invalid format errors are thrown, this is due to how ctypes objects implements the buffer protocol).ctypes.memoryview_at()fills that gap in the API. This is similar toffi.buffer()in the cffi module.Fixes#112015
📚 Documentation preview 📚:https://cpython-previews--112018.org.readthedocs.build/
ctypes.memoryview_at()#112015