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 ciresnave
Recipients ciresnave
Date 2021-09-24.19:23:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1632511425.07.0.917515072933.issue45285@roundup.psfhosted.org>
In-reply-to
Content
When dealing with a Structure containing c_char variables, the variables are incorrectly being typed as bytes.  As a result, a pointer to those c_char variables can not be created because bytes is not a ctypes type.

from ctypes import (
    Structure,
    c_char,
    pointer,
)


class MyStruct(Structure):
    _fields_ = [("a", c_char), ("b", c_char), ("c", c_char)]


x: MyStruct = MyStruct(98, 99, 100)

print(type(x.a))
# Prints <class 'bytes'> ???  Both mypy and PyRight agree that x.a is a c_char.

some_variable = pointer(x.a)
# Traceback (most recent call last):
#   File "C:\Users\cires\ctypes_test.py", line 23, in <module>
#     some_variable = pointer(x.a)
# TypeError: _type_ must have storage info
History
Date User Action Args
2021-09-24 19:23:45ciresnavesetrecipients: + ciresnave
2021-09-24 19:23:45ciresnavesetmessageid: <1632511425.07.0.917515072933.issue45285@roundup.psfhosted.org>
2021-09-24 19:23:45ciresnavelinkissue45285 messages
2021-09-24 19:23:44ciresnavecreate