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

Use _PyLong_GetOne() and _PyLong_GetZero() in long_invmod() #125044

Merged
merged 1 commit into from
Oct 7, 2024

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Oct 7, 2024

These functions cannot fail.

Copy link
Member

@corona10 corona10 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 0377547 into python:main Oct 7, 2024
40 checks passed
@vstinner vstinner deleted the long_invmod branch October 7, 2024 17:54
@vstinner
Copy link
Member Author

vstinner commented Oct 7, 2024

Merged, thanks for reviews!

Py_INCREF(a);
PyLongObject *b = (PyLongObject *)Py_NewRef(_PyLong_GetOne());
Copy link
Contributor

Choose a reason for hiding this comment

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

@vstinner Out of curiosity: why did you add the Py_NewRef when _PyLong_GetOne is documented to return an immortal singleton?
(or can modern compilers optimize this away?)

Copy link
Member Author

Choose a reason for hiding this comment

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

The Py_NewRef() is useless. I added it because the code wants a strong refererence and I didn't pay attention that these two constants are immortal.

(or can modern compilers optimize this away?)

No, Py_NewRef() is not optimized.

See also my PR gh-124076 attempt.

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.

4 participants