Eryk Sun
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)
b'spam'
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:
Windows:
>>> ascii(ctypes.wstring_at(b'\x00\xd8\x00\xdc'))
"'\\U00010000'"
Linux:
>>> 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]
----------
nosy: +eryksun
_______________________________________
Python tracker