Skip to content

postpone <stdbool.h> inclusion after Python.h #130641

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

Merged
merged 1 commit into from
Feb 28, 2025

Conversation

chouquette
Copy link
Contributor

stdbool.h will cause <features.h> to be included before Python.h can define some macros to enable some additional features, causing multiple types not to be defined down the line

In my specific case, this was causing build failures when building python with zig cc

stdbool.h will cause <features.h> to be included before Python.h can
define some macros to enable some additional features, causing multiple
types not to be defined down the line
@ghost
Copy link

ghost commented Feb 27, 2025

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Feb 27, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM

@vstinner vstinner merged commit 830f04b into python:main Feb 28, 2025
51 checks passed
@vstinner vstinner added the needs backport to 3.13 bugs and security fixes label Feb 28, 2025
@miss-islington-app
Copy link

Thanks @chouquette for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry, @chouquette and @vstinner, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 830f04b5056db92ba96387db0a778dcd19a39522 3.13

@bedevere-app
Copy link

bedevere-app bot commented Feb 28, 2025

GH-130675 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Feb 28, 2025
vstinner pushed a commit to vstinner/cpython that referenced this pull request Feb 28, 2025
Remove inclusions prior to Python.h.

<stdbool.h> will cause <features.h> to be included before Python.h can
define some macros to enable some additional features, causing multiple
types not to be defined down the line.

(cherry picked from commit 830f04b)
vstinner added a commit that referenced this pull request Feb 28, 2025
Postpone <stdbool.h> inclusion after Python.h (#130641)

Remove inclusions prior to Python.h.

<stdbool.h> will cause <features.h> to be included before Python.h can
define some macros to enable some additional features, causing multiple
types not to be defined down the line.

(cherry picked from commit 830f04b)

Co-authored-by: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
@colesbury
Copy link
Contributor

I noticed we still have a bunch of places where we #include <stdbool.h> first. When is this a problem and when is it not?

#include <stdbool.h>
#include "Python.h"

#include <stdbool.h>
#include "Python.h"

#include <stdbool.h>
#include <Python.h>

cpython/Python/codegen.c

Lines 15 to 17 in ddc27f9

#include <stdbool.h>
#include "Python.h"

#include <stdbool.h>
#include "Python.h"

#include <stdbool.h>
#include "Python.h"

@chouquette
Copy link
Contributor Author

Disclaimer: I don't know the python code base at all

My take on this is that it seems Python.h is meant to be included as the first header for any source, similar to how config.h usually is for most autoconf based projects.
If that's the case, not doing so is likely to break in various "fun" ways depending on the libc implementation, so I'd say there never a good reason not to include Python.h first.
I only patched the errors I encountered but I can open a follow up PR

@vstinner
Copy link
Member

vstinner commented Mar 3, 2025

Follow-up: PR #130738.

seehwan pushed a commit to seehwan/cpython that referenced this pull request Apr 16, 2025
Remove inclusions prior to Python.h.

<stdbool.h> will cause <features.h> to be included before Python.h can
define some macros to enable some additional features, causing multiple
types not to be defined down the line.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants