Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/ctypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ class c_void_p(_SimpleCData):

class c_bool(_SimpleCData):
_type_ = "?"
c_bool.__ctype_le__ = c_bool.__ctype_be__ = c_bool
_check_size(c_bool)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not disagreeing that this should be here, I'd prefer to keep unrelated changes out of a PR. Could you open a seperate PR that adds this? (No need for an issue or blurb entry on it, just the one line change should be fine; tag me and I'll add skip issue and skip news.)

Suggested change
_check_size(c_bool)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the input but it's not really worth my time to split this single line out into a separate PR. Any real reason it can't ride along with this one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't really like to accept changes that are unrelated to the actual fix. You can leave it in, but expect pushback from other reviewers.


from _ctypes import POINTER, pointer, _pointer_type_cache

Expand Down
11 changes: 7 additions & 4 deletions Lib/test/test_ctypes/test_byteswap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
c_byte, c_ubyte, c_char, c_wchar, c_void_p,
c_short, c_ushort, c_int, c_uint,
c_long, c_ulong, c_longlong, c_ulonglong,
c_uint32, c_float, c_double)
c_uint32, c_float, c_double, c_bool)


def bin(s):
Expand Down Expand Up @@ -173,6 +173,9 @@ def test_endian_other(self):
self.assertIs(c_char.__ctype_le__, c_char)
self.assertIs(c_char.__ctype_be__, c_char)

self.assertIs(c_bool.__ctype_le__, c_bool)
self.assertIs(c_bool.__ctype_be__, c_bool)

def test_struct_fields_unsupported_byte_order(self):

fields = [
Expand Down Expand Up @@ -373,13 +376,13 @@ def test_build_struct_union_opposite_system_byteorder(self):
_Union = LittleEndianUnion

class S1(_Structure):
_fields_ = [("a", c_byte), ("b", c_byte)]
_fields_ = [("a", c_byte), ("b", c_byte), ("c", c_bool)]

class U1(_Union):
_fields_ = [("s1", S1), ("ab", c_short)]
_fields_ = [("s1", S1), ("ab", c_short), ("ac", c_bool)]

class S2(_Structure):
_fields_ = [("u1", U1), ("c", c_byte)]
_fields_ = [("u1", U1), ("c", c_byte), ("d", c_bool)]


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for :class:`ctypes.c_bool` for structs/unions that have an endianness opposite of the current system.
Loading