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 ciresnave, eryksun
Date 2021-09-24.20:19:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1632514744.34.0.42687227853.issue45285@roundup.psfhosted.org>
In-reply-to
Content
A simple ctypes type implements a get function that's called when its value is returned as an attribute of struct/union, index of an array/pointer, or result of a function pointer. For example:

    >>> a = (ctypes.c_char * 1)(97)
    >>> a[0]
    b'a'

    >>> p = ctypes.POINTER(ctypes.c_char)(a)
    >>> p[0]
    b'a'

This behavior can't be changed. However, using a subclass of c_char works around it. For example:

    >>> class my_char(ctypes.c_char): pass
    ... 

    >>> a = (my_char * 1)(97)
    >>> a[0]
    <my_char object at 0x7f007dadf640>
    >>> a[0].value
    b'a'

    >>> p = ctypes.POINTER(my_char)(a)
    >>> p[0]
    <my_char object at 0x7f007dadf6c0>
    >>> p[0].value
    b'a'
History
Date User Action Args
2021-09-24 20:19:04eryksunsetrecipients: + eryksun, ciresnave
2021-09-24 20:19:04eryksunsetmessageid: <1632514744.34.0.42687227853.issue45285@roundup.psfhosted.org>
2021-09-24 20:19:04eryksunlinkissue45285 messages
2021-09-24 20:19:04eryksuncreate