This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients JelleZijlstra, docs@python, eryksun, shreyanavigyan, talhayon1
Date 2021-04-11.21:16:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
> the name "address" and "addr" respectively which are misleading 
> because it is asking for ctypes.c_char_p or ctypes.c_wchar_p which 
> are C pointer types

string_at() and wstring_at() take a c_void_p value. This can be initialized by an integer (i.e. an address), bytes, str, or any ctypes pointer, array, or byref() reference. 

Additionally it works with an object that has a compatible _as_parameter_ attribute, e.g.:

    >>> class A:
    ...    _as_parameter_ = b'spam'
    >>> ctypes.string_at(A)

If the docstring is change to use "ptr", for string_at() it can succinctly say the following: "Return the byte string at void *ptr." 

For wstring_at(), replace "byte string" with "wide-character string" or "wchar_t string". Specifying the type matters because it depends on the platform. Windows uses a 16-bit wchar_t, and the memory will be interpreted as UTF-16 (e.g. surrogate pairs), whereas other platforms use a 32-bit wchar_t, and the memory will be interpreted as UTF-32. For example:


    >>> ascii(ctypes.wstring_at(b'\x00\xd8\x00\xdc'))


    >>> try: ctypes.wstring_at(b'\x00\xd8\x00\xdc')
    ... except Exception as e: print(e)
    character U+dc00d800 is not in range [U+0000; U+10ffff]
Date User Action Args
2021-04-11 21:16:09eryksunsetrecipients: + eryksun, docs@python, JelleZijlstra, shreyanavigyan, talhayon1
2021-04-11 21:16:08eryksunsetmessageid: <>
2021-04-11 21:16:08eryksunlinkissue43803 messages
2021-04-11 21:16:08eryksuncreate