Skip to content

gh-87969: Amend docs and docstrings for ctypes.string_at and ctypes.wstring_at #25384

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

Merged
merged 7 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Doc/library/ctypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2018,13 +2018,13 @@ Utility functions
Does the same as the C ``sizeof`` operator.


.. function:: string_at(address, size=-1)
.. function:: string_at(ptr, size=-1)

This function returns the C string starting at memory address *address* as a bytes
This function returns the C string starting at memory address *ptr* as a bytes
object. If size is specified, it is used as size, otherwise the string is assumed
to be zero-terminated.

.. audit-event:: ctypes.string_at address,size ctypes.string_at
.. audit-event:: ctypes.string_at ptr,size ctypes.string_at


.. function:: WinError(code=None, descr=None)
Expand All @@ -2039,14 +2039,14 @@ Utility functions
An instance of :exc:`WindowsError` used to be created.


.. function:: wstring_at(address, size=-1)
.. function:: wstring_at(ptr, size=-1)

This function returns the wide character string starting at memory address
*address* as a string. If *size* is specified, it is used as the number of
*ptr* as a string. If *size* is specified, it is used as the number of
characters of the string, otherwise the string is assumed to be
zero-terminated.

.. audit-event:: ctypes.wstring_at address,size ctypes.wstring_at
.. audit-event:: ctypes.wstring_at ptr,size ctypes.wstring_at


.. _ctypes-data-types:
Expand Down
8 changes: 4 additions & 4 deletions Lib/ctypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,9 @@ def cast(obj, typ):

_string_at = PYFUNCTYPE(py_object, c_void_p, c_int)(_string_at_addr)
def string_at(ptr, size=-1):
"""string_at(addr[, size]) -> string
"""string_at(ptr[, size]) -> string

Return the string at addr."""
Return the string at ptr."""
return _string_at(ptr, size)

try:
Expand All @@ -523,9 +523,9 @@ def string_at(ptr, size=-1):
else:
_wstring_at = PYFUNCTYPE(py_object, c_void_p, c_int)(_wstring_at_addr)
def wstring_at(ptr, size=-1):
"""wstring_at(addr[, size]) -> string
"""wstring_at(ptr[, size]) -> string

Return the string at addr."""
Return the string at ptr."""
return _wstring_at(ptr, size)


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The docstrings, docs and argument lists of the functions ctypes.string_at
and ctypes.wstring_at used different names to refer to the first argument.
Changing them to only use the name "ptr" to refer to the first argument.