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 dudenwatschn
Recipients dudenwatschn, paul.moore, steve.dower, tim.golden, zach.ware
Date 2022-02-15.12:01:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1644926516.47.0.674432386115.issue46758@roundup.psfhosted.org>
In-reply-to
Content
Setting/getting values in a Structure containing multiple c_bool bitfields like:
_fields_ = [
  ('one', c_bool, 1),
  ('two', c_bool, 1),
  ]
results in an unexpected behavior.
Setting any one of these fields to `True` results in ALL of these fields being set to `True` (i.e.: setting `struct.one` to `True` causes both `struct.one` as well as `struct.two` to be set to `True`.
This also results in the binary representation of the struct to be incorrect. The only possible outcomes for `bytes(struct)` are `b'\x00` and `b'\x01'`

Expected behavior should be that when setting `struct.one` only sets the desired field.
This is achievable when defining the same Structure with `c_byte` rather than `c_bool`.
When defining the struct like:
_fields_ = [
  ('one', c_byte, 1),
  ('two', c_byte, 1),
  ]
setting `struct.one` only affects `struct.one` and not `struct.two`.
The binary representation of the structure is also correct. When setting `struct.two` to `True`, `bytes(struct)` returns `b'\x02'` (aka. 0b10).

I've attached a Minimal Runnable Example that hopefully helps outline the issue.
History
Date User Action Args
2022-02-15 12:01:56dudenwatschnsetrecipients: + dudenwatschn, paul.moore, tim.golden, zach.ware, steve.dower
2022-02-15 12:01:56dudenwatschnsetmessageid: <1644926516.47.0.674432386115.issue46758@roundup.psfhosted.org>
2022-02-15 12:01:56dudenwatschnlinkissue46758 messages
2022-02-15 12:01:56dudenwatschncreate