Skip to content

gh-157495: Avoid Py_MIN()/Py_MAX() side effects - #157591

Merged
vstinner merged 1 commit into
python:mainfrom
vstinner:macro_eval_once
Sep 16, 2026
Merged

vstinner merged 1 commit into
python:mainfrom
vstinner:macro_eval_once

Conversation

@vstinner

@vstinner vstinner commented Sep 15, 2026

Copy link
Copy Markdown
Member

Avoid calling Py_MIN() or Py_MAX() with non-trivial functions/expressions since these macros evaluate their arguments twice.

Avoid calling Py_MIN() or Py_MAX() with non-trivial
functions/expressions since these macros evaluate their arguments
twice.
@vstinner

vstinner commented Sep 15, 2026

Copy link
Copy Markdown
Member Author

@skirpichev: I checked Py_MIN/MAX/ABS calls in the Python code base and I found a few calls which are inefficient. I wrote this PR to fix them.

@vstinner
vstinner merged commit ba91215 into python:main Sep 16, 2026
59 checks passed
@vstinner
vstinner deleted the macro_eval_once branch September 16, 2026 16:44
@vstinner

Copy link
Copy Markdown
Member Author

The duplicated safe_get_max_fd() and _PyDeadline_Get() is not great, but I don't think that it's worth it to backport this change. It's not a big deal to call these functions twice.

@vstinner

Copy link
Copy Markdown
Member Author

Merged. Thanks for the review @methane!

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