Skip to content
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

Provide ctypes.buffer_at() #112015

Open
rianhunter opened this issue Nov 13, 2023 · 0 comments · May be fixed by #112018
Open

Provide ctypes.buffer_at() #112015

rianhunter opened this issue Nov 13, 2023 · 0 comments · May be fixed by #112018
Labels
stdlib Python modules in the Lib dir topic-ctypes type-feature A feature request or enhancement

Comments

@rianhunter
Copy link

rianhunter commented Nov 13, 2023

Feature or enhancement

Proposal:

It should be possible to easily make memoryview objects from pointer-able ctypes objects with an arbitrary length. In the same way we can currently use ctypes.string_at() to create bytes objects. The advantage of using memoryview objects is that we can elide a buffer copy.

import ctypes
a = (ctypes.c_ubyte * 10)()
ctypes.buffer_at(a, 10, True)[0] = 1
assert a[0] == 1
a[0] = 2
assert ctypes.buffer_at(a, 10, True)[0] == 2

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

@rianhunter rianhunter added the type-feature A feature request or enhancement label Nov 13, 2023
@iritkatriel iritkatriel added the stdlib Python modules in the Lib dir label Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir topic-ctypes type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants