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

Open
StanFromIreland wants to merge5 commits intopython:main
base:main
Choose a base branch
Loading
fromStanFromIreland:ctypes-note

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!

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
awaiting core reviewdocsDocumentation in the Doc dirneeds backport to 3.13bugs and security fixesneeds backport to 3.14bugs and security fixesskip newstopic-ctypes
Projects
Status: Todo
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