Message390795
> 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] |
|
Date |
User |
Action |
Args |
2021-04-11 21:16:09 | eryksun | set | recipients:
+ eryksun, docs@python, JelleZijlstra, shreyanavigyan, talhayon1 |
2021-04-11 21:16:08 | eryksun | set | messageid: <1618175768.97.0.746342683311.issue43803@roundup.psfhosted.org> |
2021-04-11 21:16:08 | eryksun | link | issue43803 messages |
2021-04-11 21:16:08 | eryksun | create | |
|