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: Replace Py_BUILD_ASSERT() with static_assert() #91730

Merged
merged 1 commit into from
Apr 20, 2022
Merged

gh-91731: Replace Py_BUILD_ASSERT() with static_assert() #91730

merged 1 commit into from
Apr 20, 2022

Conversation

vstinner
Copy link
Member

Python 3.11 now uses C11 standard which adds static_assert()
to <assert.h>.

  • In pytime.c, replace Py_BUILD_ASSERT() with preprocessor checks on
    SIZEOF_TIME_T with #error.
  • On macOS, py_mach_timebase_info() now accepts timebase members with
    the same size than _PyTime_t.
  • py_get_monotonic_clock() now saturates GetTickCount64() to
    _PyTime_MAX: GetTickCount64() is unsigned, whereas _PyTime_t is
    signed.

@vstinner
Copy link
Member Author

Failure on macOS:

gcc -c (...) -std=c99 (...) -o Objects/longobject.o Objects/longobject.c
(...)
Objects/longobject.c:5653:5: error: implicit declaration of function 'static_assert' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    static_assert(PyLong_SHIFT <= 32, "digit is larger than uint32_t");

Oh, Python is still built with -std=c99, whereas we switched to C11 in PEP 7.

@vstinner
Copy link
Member Author

I will first merge #91733 which replaces -std=c99 with -std=c11.

Python 3.11 now uses C11 standard which adds static_assert()
to <assert.h>.

* In pytime.c, replace Py_BUILD_ASSERT() with preprocessor checks on
  SIZEOF_TIME_T with #error.
* On macOS, py_mach_timebase_info() now accepts timebase members with
  the same size than _PyTime_t.
* py_get_monotonic_clock() now saturates GetTickCount64() to
  _PyTime_MAX: GetTickCount64() is unsigned, whereas _PyTime_t is
  signed.
@vstinner vstinner changed the title Replace Py_BUILD_ASSERT() with static_assert() gh-91731: Replace Py_BUILD_ASSERT() with static_assert() Apr 20, 2022
@vstinner vstinner added 🔨 test-with-buildbots Test PR w/ buildbots; report in status section and removed skip issue labels Apr 20, 2022
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @vstinner for commit 2a32c43 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 20, 2022
@vstinner
Copy link
Member Author

I scheduled buildbot jobs to check how it goes on other platforms/C compilers.

@vstinner
Copy link
Member Author

buildbot/AMD64 Fedora Stable Refleaks PR — Build done.

This is unrelated to my PR. The leak is known in the main branch.

@vstinner
Copy link
Member Author

Python was built successfully on various versions of Windows, macOS, Ubuntu and FreeBSD on various architectures. I confirm that it confirms that C11 is now well supported. If a platform doesn't support C11, it can reimplement static_assert() with Py_BUILD_ASSERT() or get a C11 compiler :-) I merge my PR.

@vstinner
Copy link
Member Author

This is unrelated to my PR. The leak is known in the main branch.

See #91757

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.

2 participants