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-69011:ctypes.create_*_buffer clarify NUL termination character inclusion#132858

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 5 commits intopython:mainfromStanFromIreland:ctypes-note
May 29, 2025

Conversation

StanFromIreland
Copy link
Contributor

@StanFromIrelandStanFromIreland commentedApr 23, 2025
edited
Loading

There was little support for raising errors so a docs note is probably the best thing to do -- atleast for now


📚 Documentation preview 📚:https://cpython-previews--132858.org.readthedocs.build/

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.

This looks fine. I'll tag@encukou as the current ctypes expert, but be aware he's currently on leave.

@encukou
Copy link
Member

encukou commentedApr 28, 2025
edited
Loading

I'd write it like this, to also mention what happens ifsize is too large:

.. function:: create_string_buffer(init, size=None)              create_string_buffer(size)   Create a mutable character buffer. The returned object is a   ctypes array of :class:`c_char`.   If *size* is given (and not None), it must be an :cls:`int.   It specifies the size of the returned array.   If the *init* argument is given, it must be :cls:`bytes`. It is used   to initialize the array items. Bytes not initialized this way are   set to zero (NUL).   If *size* is not given (or if it is None), the buffer is made one byte   larger than *init*, effectively adding a NUL termination byte.   If both arguments are given, *size* must not be less than ``len(init)``.   .. warning::      If *size* is equal to ``len(init)``, a NUL terminator is      not added. Do not treat such a buffer as a C string.   For example::      >>> bytes(create_string_buffer(2))      b'\x00\x00'      >>> bytes(create_string_buffer(b'ab'))      b'ab\x00'      >>> bytes(create_string_buffer(b'ab', 2))      b'ab'      >>> bytes(create_string_buffer(b'ab', 4))      b'ab\x00\x00'      >>> bytes(create_string_buffer(b'abcdef', 2))      Traceback (most recent call last):         ...      ValueError: byte string too long

# Conflicts:#Doc/library/ctypes.rst
@StanFromIreland
Copy link
ContributorAuthor

@encukou I have applied your suggested format.

@serhiy-storchakaserhiy-storchaka added the needs backport to 3.14bugs and security fixes labelMay 8, 2025
@StanFromIreland
Copy link
ContributorAuthor

@encukou Friendly ping :-)

Copy link
Member

@encukouencukou left a comment

Choose a reason for hiding this comment

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

Oops, I left my comments in the “pending” state. Sorry for the delay!

@encukou
Copy link
Member

Looks great now. Thank you!

@encukouencukou merged commitb783e17 intopython:mainMay 29, 2025
24 checks passed
@github-project-automationgithub-project-automationbot moved this fromTodo toDone inDocs PRsMay 29, 2025
@miss-islington-app
Copy link

Thanks@StanFromIreland for the PR, and@encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestMay 29, 2025
…pythonGH-132858)This adds a warning about the possibly-missing NUL terminator, but in a waythat doesn't make it sound like a bug/wart.(cherry picked from commitb783e17)Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestMay 29, 2025
…pythonGH-132858)This adds a warning about the possibly-missing NUL terminator, but in a waythat doesn't make it sound like a bug/wart.(cherry picked from commitb783e17)Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
@bedevere-app
Copy link

GH-134881 is a backport of this pull request to the3.14 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.14bugs and security fixes labelMay 29, 2025
@bedevere-app
Copy link

GH-134882 is a backport of this pull request to the3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13bugs and security fixes labelMay 29, 2025
@StanFromIrelandStanFromIreland deleted the ctypes-note branchMay 29, 2025 13:17
encukou pushed a commit that referenced this pull requestMay 29, 2025
GH-132858) (GH-134882)This adds a warning about the possibly-missing NUL terminator, but in a waythat doesn't make it sound like a bug/wart.(cherry picked from commitb783e17)Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
encukou pushed a commit that referenced this pull requestMay 29, 2025
…H-132858) (GH-134881)This adds a warning about the possibly-missing NUL terminator, but in a waythat doesn't make it sound like a bug/wart.(cherry picked from commitb783e17)Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ZeroIntensityZeroIntensityZeroIntensity approved these changes

@encukouencukouAwaiting requested review from encukou

Assignees
No one assigned
Labels
docsDocumentation in the Doc dirskip newstopic-ctypes
Projects
Status: Done
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@StanFromIreland@encukou@ZeroIntensity@serhiy-storchaka

[8]ページ先頭

©2009-2025 Movatter.jp