Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
encukou merged 25 commits intopython:mainfromrianhunter:ctypes-buffer-at
Jan 3, 2025

Conversation

@rianhunter
Copy link
Contributor

@rianhunterrianhunter commentedNov 13, 2023
edited
Loading

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/

JesseTG and a-reich reacted with thumbs up emoji
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.
@rianhunterrianhunter changed the titleImplementctypes.buffer_at()gh-112015: Implementctypes.buffer_at()Nov 13, 2023
Copy link
Member

@serhiy-storchakaserhiy-storchaka left a 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.

rianhunterand others added6 commitsJanuary 18, 2024 14:14
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
Copy link
ContributorAuthor

When merging, just flatten all the commits down to a single commit.

@rianhunterrianhunter changed the titlegh-112015: Implementctypes.buffer_at()gh-112015: Implementctypes.memoryview_at()Jan 19, 2024
@rianhunter
Copy link
ContributorAuthor

Abandoned

@encukou
Copy link
Member

I'm sorry but I no longer have time to work on this patch.

No worries. Thank you for your work so far!
I hope you won't mind if I take over and finish it.

@encukouencukou reopened thisSep 26, 2024
@rianhunter
Copy link
ContributorAuthor

No problem, feel free

@encukou
Copy link
Member

OK. I went back to thestring_at mechanism of calling the C code via ctypes, as the conversion toc_void_p is much more flexible.

@encukou
Copy link
Member

encukou commentedDec 16, 2024
edited
Loading

Does this look interesting to you,@ZeroIntensity or@picnixz?

@picnixzpicnixz self-requested a reviewDecember 16, 2024 17:25
@ZeroIntensity
Copy link
Member

I'll review sometime soon (today or in the next few days).

encukouand others added3 commitsDecember 19, 2024 14:33
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Copy link
Member

@ZeroIntensityZeroIntensity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Mostly LGTM

Copy link
Member

@ZeroIntensityZeroIntensity left a 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!

encukou reacted with heart emoji
@encukouencukou merged commitb4f799b intopython:mainJan 3, 2025
45 checks passed
WolframAlph pushed a commit to WolframAlph/cpython that referenced this pull requestJan 4, 2025
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>
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull requestJan 8, 2025
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>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@encukouencukouencukou left review comments

@serhiy-storchakaserhiy-storchakaserhiy-storchaka left review comments

@picnixzpicnixzpicnixz left review comments

@ZeroIntensityZeroIntensityZeroIntensity approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Providectypes.memoryview_at()

5 participants

@rianhunter@encukou@ZeroIntensity@serhiy-storchaka@picnixz

[8]ページ先頭

©2009-2025 Movatter.jp