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

gh-91731: Add macro compatibility for static_assert for old libcs #92559

Merged
merged 6 commits into from
May 9, 2022

Conversation

pablogsal
Copy link
Member

No description provided.

#if defined(__GLIBC__) && __GLIBC__ <= 2 && __GLIBC_MINOR__ <= 16
# define static_assert _Static_assert
#endif
+
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe you left a stray + from a diff in there

Copy link
Member Author

Choose a reason for hiding this comment

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

Whops!

Include/pymacro.h Outdated Show resolved Hide resolved
Include/pymacro.h Outdated Show resolved Hide resolved
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.

I'm sad that FreeBSD and old glibc requires these workarounds, I expected that "C11" means "static_assert() is usable". But well, the real world is more complicated.

An alternative would be to define Py_static_assert(), but I prefer to use standard static_assert() name and hope that in a few years (20 years? :-D), we can remove these workaround for old platforms. The only drawback is that including <Python.h> defines static_assert(), but IMO it's an acceptable trade-off.

Include/pymacro.h Outdated Show resolved Hide resolved
Co-authored-by: Victor Stinner <vstinner@python.org>
Include/pymacro.h Outdated Show resolved Hide resolved
Include/pymacro.h Outdated Show resolved Hide resolved
@vstinner
Copy link
Member

vstinner commented May 9, 2022

I took the liberty of pushing directly changes to fix typos (and reindent the long condition) in your PR using the GitHub suggestion tool.

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.

IMO it's acceptable to have such code for old glibc versions, as I did for old FreeBSD versions.

@pablogsal pablogsal merged commit f0614ca into python:main May 9, 2022
@pablogsal pablogsal deleted the gh-91731 branch May 9, 2022 17:38
@miss-islington
Copy link
Contributor

Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-92566 is a backport of this pull request to the 3.11 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 9, 2022
…cs (pythonGH-92559)

(cherry picked from commit f0614ca)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
pablogsal added a commit that referenced this pull request May 9, 2022
…-92559) (#92566)

(cherry picked from commit f0614ca)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
@vstinner
Copy link
Member

vstinner commented May 9, 2022

Thanks for the fix ;-)

@@ -10,6 +10,14 @@
# define static_assert _Static_assert
#endif

// static_assert is defined in GLIB from version 2.16. Before it requires
Copy link
Member

Choose a reason for hiding this comment

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

GLIBC? (GLIB exists, but it's something quite different.)

Copy link
Member Author

@pablogsal pablogsal May 10, 2022

Choose a reason for hiding this comment

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

That's a typo, indeed. It should be GLIBC

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in #92618

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.

6 participants