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: Python.h includes stdbool.h
Type: Stage: resolved
Components: Versions: Python 3.11
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: brandtbucher, eric.snow, erlendaasland, kumaraditya, petr.viktorin, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2022-02-14 09:28 by petr.viktorin, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 31553 merged petr.viktorin, 2022-02-24 12:16
PR 31600 merged kumaraditya, 2022-02-26 15:05
Messages (11)
msg413216 - (view) Author: Petr Viktorin (petr.viktorin) * (Python committer) Date: 2022-02-14 09:28
In main, cpython/pystate.h newly includes stdbool.h, providing a definition for `bool` that might be incompatible with other software.

See here: https://github.com/cmusphinx/sphinxbase/pull/90

Eric, is this necessary? Would an old-school `int` do?
Or should we say it's 2022 already and everyone needs to use stdbool.hfore bools?
msg413217 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2022-02-14 10:14
Is it compatible with C++?
msg413220 - (view) Author: Petr Viktorin (petr.viktorin) * (Python committer) Date: 2022-02-14 10:42
Yes, stdbool.h is essentially a backport of C++'s bool type to C.
msg413235 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2022-02-14 16:55
On Mon, Feb 14, 2022 at 2:28 AM Petr Viktorin <report@bugs.python.org> wrote:
> Eric, is this necessary? Would an old-school `int` do?
> Or should we say it's 2022 already and everyone needs to use stdbool.hfore bools?

I started using ``bool`` (stdbool.h) when I saw it specified in PEP 7
(https://www.python.org/dev/peps/pep-0007/#c-dialect).  If it is a
problem then I think it should be answered relative to PEP 7.  I'm not
sure what the best route is though.  Personally, I'd argue that if
it's in C99 then it should probably be standard at this point. :)
However, I'm not opposed to going back to plain int.  (And I know
there are definitely a number of old-school folks who prefer plain
int. :) )
msg413239 - (view) Author: Petr Viktorin (petr.viktorin) * (Python committer) Date: 2022-02-14 17:02
It is in C99, but in an optional header.
IMO, including the header in the internals is perfectly OK, but opting everyone else in isn't very nice.
i.e. it would probably be OK to use `_Bool`, the actual C99 keyword that `bool` is defined as. But that's ugly enough to prefer `int`...
msg413970 - (view) Author: Petr Viktorin (petr.viktorin) * (Python committer) Date: 2022-02-25 08:26
New changeset 2c228a7b8f89e9ed8d390370abd771d4993b79d8 by Petr Viktorin in branch 'main':
bpo-46748: Don't import <stdbool.h> in public headers (GH-31553)
https://github.com/python/cpython/commit/2c228a7b8f89e9ed8d390370abd771d4993b79d8
msg414053 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-02-26 01:11
> New changeset 2c228a7b8f89e9ed8d390370abd771d4993b79d8 by Petr Viktorin in branch 'main':
> bpo-46748: Don't import <stdbool.h> in public headers (GH-31553)

It seems like this change broke ctypes on some architectures like s390x:

https://buildbot.python.org/all/#/builders/3/builds/1573

======================================================================
FAIL: test_frozentable (ctypes.test.test_values.PythonValuesTestCase) [__phello_alias__]
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/dje/cpython-buildarea/3.x.edelsohn-fedora-z.clang/build/Lib/ctypes/test/test_values.py", line 86, in test_frozentable
    self.assertIsNone(spec.submodule_search_locations)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: [] is not None
======================================================================
FAIL: test_frozentable (ctypes.test.test_values.PythonValuesTestCase) [__phello__]
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/dje/cpython-buildarea/3.x.edelsohn-fedora-z.clang/build/Lib/ctypes/test/test_values.py", line 86, in test_frozentable
    self.assertIsNone(spec.submodule_search_locations)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: ['/home/dje/cpython-buildarea/3.x.edelsohn-fedora-z.clang/build/Lib/__phello__'] is not None
======================================================================
FAIL: test_frozentable (ctypes.test.test_values.PythonValuesTestCase) [__phello__.ham]
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/dje/cpython-buildarea/3.x.edelsohn-fedora-z.clang/build/Lib/ctypes/test/test_values.py", line 86, in test_frozentable
    self.assertIsNone(spec.submodule_search_locations)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: ['/home/dje/cpython-buildarea/3.x.edelsohn-fedora-z.clang/build/Lib/__phello__/ham'] is not None
msg414121 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-02-26 23:25
New changeset e182c660b63bc23420fb9f0593d77a3fa3b7f1c7 by Kumar Aditya in branch 'main':
bpo-46748: Fix ctypes test_frozentable() (GH-31600)
https://github.com/python/cpython/commit/e182c660b63bc23420fb9f0593d77a3fa3b7f1c7
msg414165 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2022-02-27 21:42
Can we close this?
msg414183 - (view) Author: Petr Viktorin (petr.viktorin) * (Python committer) Date: 2022-02-28 09:48
Thank you, Kumar & Victor, for fixing up the issue!

I meant to check the buildbots before closing the issue, but got side-tracked.
msg414200 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2022-02-28 15:02
> Thank you, Kumar & Victor, for fixing up the issue!

You're welcome. I'm happy to see that you reduced the number of #include in the C API ;-) I made similar changes in bpo-45434.
History
Date User Action Args
2022-04-11 14:59:56adminsetgithub: 90904
2022-02-28 15:02:34vstinnersetmessages: + msg414200
2022-02-28 09:48:40petr.viktorinsetstatus: pending -> closed

messages: + msg414183
stage: patch review -> resolved
2022-02-27 21:42:22erlendaaslandsetstatus: open -> pending
nosy: + erlendaasland
messages: + msg414165

2022-02-26 23:25:57vstinnersetmessages: + msg414121
2022-02-26 15:05:37kumaradityasetnosy: + kumaraditya
pull_requests: + pull_request29723
2022-02-26 01:11:01vstinnersetnosy: + vstinner
messages: + msg414053
2022-02-25 08:26:08petr.viktorinsetmessages: + msg413970
2022-02-24 12:16:58petr.viktorinsetkeywords: + patch
stage: patch review
pull_requests: + pull_request29674
2022-02-18 18:31:47brandtbuchersetnosy: + brandtbucher
2022-02-14 17:02:50petr.viktorinsetmessages: + msg413239
2022-02-14 16:55:00eric.snowsetmessages: + msg413235
2022-02-14 10:42:50petr.viktorinsetmessages: + msg413220
2022-02-14 10:14:59serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg413217
2022-02-14 09:28:19petr.viktorincreate