Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python.h includes stdbool.h #90904

Closed
encukou opened this issue Feb 14, 2022 · 11 comments
Closed

Python.h includes stdbool.h #90904

encukou opened this issue Feb 14, 2022 · 11 comments
Labels
3.11 only security fixes

Comments

@encukou
Copy link
Member

encukou commented Feb 14, 2022

BPO 46748
Nosy @vstinner, @encukou, @ericsnowcurrently, @serhiy-storchaka, @brandtbucher, @erlend-aasland, @kumaraditya303
PRs
  • bpo-46748: Don't import <stdbool.h> in public headers #31553
  • bpo-46748: fix failing ctypes tests on buildbots #31600
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2022-02-28.09:48:40.970>
    created_at = <Date 2022-02-14.09:28:19.600>
    labels = ['3.11']
    title = 'Python.h includes stdbool.h'
    updated_at = <Date 2022-02-28.15:02:34.507>
    user = 'https://github.com/encukou'

    bugs.python.org fields:

    activity = <Date 2022-02-28.15:02:34.507>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-02-28.09:48:40.970>
    closer = 'petr.viktorin'
    components = []
    creation = <Date 2022-02-14.09:28:19.600>
    creator = 'petr.viktorin'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46748
    keywords = ['patch']
    message_count = 11.0
    messages = ['413216', '413217', '413220', '413235', '413239', '413970', '414053', '414121', '414165', '414183', '414200']
    nosy_count = 7.0
    nosy_names = ['vstinner', 'petr.viktorin', 'eric.snow', 'serhiy.storchaka', 'brandtbucher', 'erlendaasland', 'kumaraditya']
    pr_nums = ['31553', '31600']
    priority = 'normal'
    resolution = None
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue46748'
    versions = ['Python 3.11']

    @encukou
    Copy link
    Member Author

    encukou commented Feb 14, 2022

    In main, cpython/pystate.h newly includes stdbool.h, providing a definition for bool that might be incompatible with other software.

    See here: cmusphinx/sphinxbase#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?

    @encukou encukou added 3.11 only security fixes labels Feb 14, 2022
    @serhiy-storchaka
    Copy link
    Member

    Is it compatible with C++?

    @encukou
    Copy link
    Member Author

    encukou commented Feb 14, 2022

    Yes, stdbool.h is essentially a backport of C++'s bool type to C.

    @ericsnowcurrently
    Copy link
    Member

    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. :) )

    @encukou
    Copy link
    Member Author

    encukou commented Feb 14, 2022

    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...

    @encukou
    Copy link
    Member Author

    encukou commented Feb 25, 2022

    New changeset 2c228a7 by Petr Viktorin in branch 'main':
    bpo-46748: Don't import <stdbool.h> in public headers (GH-31553)
    2c228a7

    @vstinner
    Copy link
    Member

    New changeset 2c228a7 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

    @vstinner
    Copy link
    Member

    New changeset e182c66 by Kumar Aditya in branch 'main':
    bpo-46748: Fix ctypes test_frozentable() (GH-31600)
    e182c66

    @erlend-aasland
    Copy link
    Contributor

    Can we close this?

    @encukou
    Copy link
    Member Author

    encukou commented Feb 28, 2022

    Thank you, Kumar & Victor, for fixing up the issue!

    I meant to check the buildbots before closing the issue, but got side-tracked.

    @vstinner
    Copy link
    Member

    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.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants