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: signed:1 bitfields rarely make sense
Type: behavior Stage: resolved
Components: IO Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, amaury.forgeotdarc, hfuru, python-dev, vstinner
Priority: normal Keywords: patch

Created on 2010-11-04 11:51 by hfuru, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
signed-1-bitfield.diff hfuru, 2010-11-04 11:51 patch for signed:1 bitfields
Messages (3)
msg120392 - (view) Author: Hallvard B Furuseth (hfuru) Date: 2010-11-04 11:51
In Python 2.7 and 3.2a3, Modules/_io/textio.c uses signed:1 bitfields.

They have value -1 or 0 in two's complement, but are not used thus here:
gcc complains of <bitfield> = 1 overflow.  If the point was that they
are assigned signed values, well, unsigned:1 is promoted to signed int.

I also fix a strange (int) cast doing (truncate flag to int) & 1.
My guess is someone shut up a compiler warning about the above,
by cleaning up in the wrong place.  I kept a cast in case that's
not it, and some compiler would get noisy anyway.

There are possibly-signed 1-bit fields Modules/_ctypes/_ctypes_test.c:
struct BITS too, but I don't know what that code is for.  It does not
specify signedness of the bitfields, which (as with char) makes it the
compiler's choice.  That's usually a bad idea, but maybe that code is
for exploring the compiler?
msg220859 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-06-17 18:48
Could we have a patch review on this please.
msg220897 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-06-17 21:32
New changeset 3aeca1fd4c0e by Victor Stinner in branch 'default':
Issue #10310: Use "unsigned int field:1" instead of "signed int field:1" in a
http://hg.python.org/cpython/rev/3aeca1fd4c0e
History
Date User Action Args
2022-04-11 14:57:08adminsetgithub: 54519
2014-06-18 21:27:20berker.peksagsetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: + Python 3.5, - Python 3.1, Python 2.7, Python 3.2
2014-06-17 21:32:24python-devsetnosy: + python-dev
messages: + msg220897
2014-06-17 18:48:48BreamoreBoysetnosy: + BreamoreBoy
messages: + msg220859
2010-11-04 12:54:22pitrousetnosy: + amaury.forgeotdarc
stage: patch review

versions: + Python 3.1, Python 2.7
2010-11-04 11:54:35vstinnersetnosy: + vstinner
2010-11-04 11:51:18hfurucreate