◐ Shell
clean mode source ↗

bpo-38205: replace get_small_int(ival) macro with a function version · Pull Request #16270 · python/cpython

Use Py_UNREACHABLE() macro in a safe way.

ghost


/* If use inline functions here, may lose performance due to
unnecessary type casting. */
#define IS_SMALL_INT(ival) (-NSMALLNEGINTS <= (ival) && (ival) < NSMALLPOSINTS)

Choose a reason for hiding this comment

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

Address STINNER Victor's advice:

Morever, if using a static inline function is causing issues, it would be nice to add a comment to explain why, so the issue will be avoided in the future.
https://bugs.python.org/issue37812#msg352670

vstinner

Choose a reason for hiding this comment

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

" bpo-38205: replace get_small_int(ival) macro with a function version #16270 "

Wait, https://bugs.python.org/issue38205 is about a macro which became a function and then was revert to a macro again... I don't understand why you make it a function... one more time.

Py_UNREACHABLE() should be fixed, not longobject.c.

@bedevere-bot

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@ghost

I like the idea of implementing Py_UNREACHABLE() as a function.

+1, close this PR.

@ghost ghost closed this

Sep 19, 2019

@ghost

I don't understand why you make it a function... one more time.

The current code is not consistent:
If "preallocated small integers" enalbed, get_small_int(ival) is a function.
If "preallocated small integers" disabled, get_small_int(ival) is a macro.

@ghost ghost deleted the unreachable branch

September 20, 2019 02:47

This pull request was closed.