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.

classification
Title: c_bool type not supported for BigEndianStructure on little-endian machine
Type: compile error Stage:
Components: ctypes Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Hassan El Karouni, iritkatriel, terry.reedy
Priority: normal Keywords:

Created on 2017-05-30 10:35 by Hassan El Karouni, last changed 2022-04-11 14:58 by admin.

Files
File name Uploaded Description Edit
c_bool_bug.py Hassan El Karouni, 2017-06-06 07:15 example of bug
__init__.py Hassan El Karouni, 2017-06-06 07:16 patched file solving problem
Messages (3)
msg294747 - (view) Author: Hassan El Karouni (Hassan El Karouni) Date: 2017-05-30 10:35
When trying to create a BigEndianStructure containing a c_bool field (on a windows machine), i get the following traceback:

  File "/home/elkarouh/anaconda2/lib/python2.7/ctypes/_endian.py", line 24, in _other_endian
    raise TypeError("This type does not support other endian: %s" % typ)
TypeError: This type does not support other endian: <class 'ctypes.c_bool'>

I fixed the problem by patching __init__.py under the ctypes directory by adding the following two lines:

c_bool.__ctype_le__ = c_bool.__ctype_be__ = c_bool
_check_size(c_bool)
msg295063 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-06-03 00:33
Please post or upload minimal code that reproduces the problem for you.
msg411394 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-01-23 18:29
Reproduced on 3.11:

>>> from ctypes import *
>>> class r( BigEndianStructure ):
...     _fields_ = [( "d0", c_uint32),
...                 ( "d1", c_bool )
...                      ]
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/iritkatriel/src/cpython-654/Lib/ctypes/_endian.py", line 31, in __setattr__
    fields.append((name, _other_endian(typ)) + rest)
                         ^^^^^^^^^^^^^^^^^^
  File "/Users/iritkatriel/src/cpython-654/Lib/ctypes/_endian.py", line 21, in _other_endian
    raise TypeError("This type does not support other endian: %s" % typ)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: This type does not support other endian: <class 'ctypes.c_bool'>
History
Date User Action Args
2022-04-11 14:58:47adminsetgithub: 74695
2022-01-23 18:29:53iritkatrielsetnosy: + iritkatriel

messages: + msg411394
versions: + Python 3.11, - Python 2.7
2017-06-06 07:16:52Hassan El Karounisetfiles: + __init__.py
2017-06-06 07:15:42Hassan El Karounisetfiles: + c_bool_bug.py
2017-06-03 00:33:27terry.reedysetnosy: + terry.reedy
messages: + msg295063
2017-05-30 10:35:54Hassan El Karounicreate