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 MrSurly
Recipients MrSurly
Date 2021-01-30.04:38:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1611981538.61.0.504435630016.issue43073@roundup.psfhosted.org>
In-reply-to
Content
Placing a ctypes.Union inside of a ctypes.BigEndianStructure results in "TypeError: This type does not support other endian".  I believe this is a similar problem to issue #4376 (https://bugs.python.org/issue4376)

Minimum repro test case:

import ctypes as ct

class U(ct.Union):
    _pack_=True
    _fields_=[
        ('a', ct.c_int),
        ('b', ct.c_int),
    ]

class S(ct.BigEndianStructure):
    _pack_=True
    _fields_=[
        ('x', ct.c_int),
        ('y', U),
    ]

I believe the fix is similar to that issue, though I admit I don't know enough about this code to be sure.

diff --git a/Lib/ctypes/_endian.py b/Lib/ctypes/_endian.py
index 37444bd6a7..525c5e58c9 100644
--- a/Lib/ctypes/_endian.py
+++ b/Lib/ctypes/_endian.py
@@ -18,6 +18,9 @@ def _other_endian(typ):
     # if typ is structure
     if issubclass(typ, Structure):
         return typ
+    # if typ is union:
+    if issubclass(typ, Union):
+        return typ
     raise TypeError("This type does not support other endian: %s" % typ)
 
 class _swapped_meta(type(Structure)):
History
Date User Action Args
2021-01-30 04:38:58MrSurlysetrecipients: + MrSurly
2021-01-30 04:38:58MrSurlysetmessageid: <1611981538.61.0.504435630016.issue43073@roundup.psfhosted.org>
2021-01-30 04:38:58MrSurlylinkissue43073 messages
2021-01-30 04:38:58MrSurlycreate