Skip to content

Conversation

@encukou
Copy link
Member

@encukou encukou commented Feb 4, 2026

This is a follow-up to #143508. When all the public macros were documented, the section became somewhat unwieldy.

  • Group the macros
  • Roughly order them to put the most important ones first
  • Add expansions where it makes sense; especially if there's an equivalent in modern C or a common compiler

📚 Documentation preview 📚: https://cpython-previews--144471.org.readthedocs.build/

- Group the macros
- Roughly order them to put the most important ones first
- Add expansions where it makes sense; especially if there's
  an equivalent in modern C or a common compiler
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.

Since you're already moving many functions, it may be interesting to sort functions in each category.


A use for ``Py_UNREACHABLE()`` is following a call a function that
never returns but that is not declared :c:macro:`_Py_NO_RETURN`.
never returns but that is not declared ``_Noreturn``.
Copy link
Member

Choose a reason for hiding this comment

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

Note: C11 added _Noreturn, but C23 adds [[noreturn]] and deprecates _Noreturn.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm aware, but don't want to get in the details too much.
We require C11, and as far as I know, deprecations in the C standard don't mean planned removal.

encukou and others added 2 commits February 4, 2026 15:35
Co-authored-by: Victor Stinner <vstinner@python.org>
@encukou
Copy link
Member Author

encukou commented Feb 4, 2026

it may be interesting to sort functions in each category

Sort by what?
IMO, sorting by relevance works great, even though it's not objective.

@vstinner
Copy link
Member

vstinner commented Feb 4, 2026

Sort by what?

I'm thinking at the alphabetical order.

@ZeroIntensity
Copy link
Member

Sorry, I just caused conflicts here with #144279.

@encukou
Copy link
Member Author

encukou commented Feb 5, 2026

More macros -- more structure. How does this version look?

I've grouped them in categories, and sorted by relevance first, alphabet second. For example, Py_MAX/Py_MIN before Py_CHARMASK.

FWIW, I think combined entries are a great way to reduce duplication for things that do almost the same thing: Py_MAX & Py_MIN, Py_LL & Py_ULL. Sorting alphabetically would make these harder to find.

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, with two little things below.

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. I like the new organization.

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

LGTM as well, thanks for the cleanup!

@encukou encukou added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Feb 6, 2026
@encukou encukou merged commit f85e117 into python:main Feb 6, 2026
33 checks passed
@encukou encukou deleted the doc-useful-macros branch February 6, 2026 10:55
@github-project-automation github-project-automation bot moved this from Todo to Done in Docs PRs Feb 6, 2026
@miss-islington-app
Copy link

Thanks @encukou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 6, 2026
…ythonGH-144471)

- Group the macros
- Roughly order them to put the most important ones first
- Add expansions where it makes sense; especially if there's
  an equivalent in modern C or a common compiler
(cherry picked from commit f85e1170d2b22d2ee42cd568144e0c9f57b0db67)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
@miss-islington-app
Copy link

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

cherry_picker f85e1170d2b22d2ee42cd568144e0c9f57b0db67 3.13

@bedevere-app
Copy link

bedevere-app bot commented Feb 6, 2026

GH-144541 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Feb 6, 2026
encukou added a commit that referenced this pull request Feb 6, 2026
…H-144471) (GH-144541)

- Group the macros
- Roughly order them to put the most important ones first
- Add expansions where it makes sense; especially if there's
  an equivalent in modern C or a common compiler

(cherry picked from commit f85e117)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot s390x Fedora Stable Refleaks 3.14 (tier-3) has failed when building commit 3fe9735.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1776/builds/892) and take a look at the build logs.
  4. Check if the failure is related to this commit (3fe9735) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1776/builds/892

Failed tests:

  • test_external_inspection
  • test_pyrepl

Failed subtests:

  • test_only_active_thread - test.test_external_inspection.TestGetStackTrace.test_only_active_thread
  • test_repl_eio - test.test_pyrepl.test_unix_console.TestUnixConsoleEIOHandling.test_repl_eio

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.14.cstratak-fedora-stable-s390x.refleak/build/Lib/test/test_external_inspection.py", line 1246, in test_only_active_thread
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        len(gil_traces), 1, "Should have exactly one GIL holder"
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
AssertionError: 0 != 1 : Should have exactly one GIL holder


Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.14.cstratak-fedora-stable-s390x.refleak/build/Lib/test/test_pyrepl/test_unix_console.py", line 390, in test_repl_eio
    _, err = proc.communicate(timeout=support.LONG_TIMEOUT)
             ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.14.cstratak-fedora-stable-s390x.refleak/build/Lib/subprocess.py", line 1220, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)
                     ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.14.cstratak-fedora-stable-s390x.refleak/build/Lib/subprocess.py", line 2153, in _communicate
    self._check_timeout(endtime, orig_timeout, stdout, stderr)
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.14.cstratak-fedora-stable-s390x.refleak/build/Lib/subprocess.py", line 1267, in _check_timeout
    raise TimeoutExpired(
    ...<2 lines>...
            stderr=b''.join(stderr_seq) if stderr_seq else None)
subprocess.TimeoutExpired: Command '['/home/buildbot/buildarea/3.14.cstratak-fedora-stable-s390x.refleak/build/python', '-E', '-S', '/home/buildbot/buildarea/3.14.cstratak-fedora-stable-s390x.refleak/build/Lib/test/test_pyrepl/eio_test_script.py']' timed out after 675.0 seconds


Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.14.cstratak-fedora-stable-s390x.refleak/build/Lib/subprocess.py", line 1138, in __del__
    _warn("subprocess %s is still running" % self.pid,
ResourceWarning: subprocess 2751248 is still running
Warning -- Unraisable exception
Exception ignored while finalizing file <_io.FileIO name=10 mode='rb' closefd=True>:
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.14.cstratak-fedora-stable-s390x.refleak/build/Lib/unittest/case.py", line 668, in run
    with outcome.testPartExecutor(self):
ResourceWarning: unclosed file <_io.TextIOWrapper name=10 encoding='UTF-8'>
Warning -- Unraisable exception
Exception ignored while finalizing file <_io.FileIO name=8 mode='rb' closefd=True>:
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.14.cstratak-fedora-stable-s390x.refleak/build/Lib/unittest/case.py", line 668, in run
    with outcome.testPartExecutor(self):
ResourceWarning: unclosed file <_io.TextIOWrapper name=8 encoding='UTF-8'>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir needs backport to 3.13 bugs and security fixes skip news topic-C-API

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants