Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c_bool type not supported for BigEndianStructure on little-endian machine #74695

Open
HassanElKarouni mannequin opened this issue May 30, 2017 · 3 comments
Open

c_bool type not supported for BigEndianStructure on little-endian machine #74695

HassanElKarouni mannequin opened this issue May 30, 2017 · 3 comments
Labels
3.11 only security fixes build The build process and cross-build topic-ctypes

Comments

@HassanElKarouni
Copy link
Mannequin

HassanElKarouni mannequin commented May 30, 2017

BPO 30510
Nosy @terryjreedy, @iritkatriel
Files
  • c_bool_bug.py: example of bug
  • init.py: patched file solving problem
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2017-05-30.10:35:54.469>
    labels = ['ctypes', 'build', '3.11']
    title = 'c_bool type not supported for BigEndianStructure on little-endian machine'
    updated_at = <Date 2022-01-23.18:29:53.273>
    user = 'https://bugs.python.org/HassanElKarouni'

    bugs.python.org fields:

    activity = <Date 2022-01-23.18:29:53.273>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['ctypes']
    creation = <Date 2017-05-30.10:35:54.469>
    creator = 'Hassan El Karouni'
    dependencies = []
    files = ['46926', '46927']
    hgrepos = []
    issue_num = 30510
    keywords = []
    message_count = 3.0
    messages = ['294747', '295063', '411394']
    nosy_count = 3.0
    nosy_names = ['terry.reedy', 'Hassan El Karouni', 'iritkatriel']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'compile error'
    url = 'https://bugs.python.org/issue30510'
    versions = ['Python 3.11']

    @HassanElKarouni
    Copy link
    Mannequin Author

    HassanElKarouni mannequin commented May 30, 2017

    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)

    @HassanElKarouni HassanElKarouni mannequin added topic-ctypes build The build process and cross-build labels May 30, 2017
    @terryjreedy
    Copy link
    Member

    Please post or upload minimal code that reproduces the problem for you.

    @iritkatriel
    Copy link
    Member

    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'>

    @iritkatriel iritkatriel added the 3.11 only security fixes label Jan 23, 2022
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes build The build process and cross-build topic-ctypes
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants