New submission from CireSnave <[email protected]>:
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
----------
components: ctypes
messages: 402582
nosy: ciresnave
priority: normal
severity: normal
status: open
title: c_char incorrectly treated as bytes in Structure
type: behavior
versions: Python 3.9
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue45285>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com