Uh oh!
There was an error while loading. Please reload this page.
gh-129149: Create a macro PYLONG_FROM_SIGNED, and leverage it in functions - #129215
gh-129149: Create a macro PYLONG_FROM_SIGNED, and leverage it in functions #129215srinivasreddy wants to merge 3 commits into
Conversation
…g_FromLong, PyLong_FromLongLong and PyLong_FromSsize_t so the repetitive code is removed.
skirpichev
commented
Jan 23, 2025
Test failures seems relevant. BTW, if you include PyLong_FromSsize_t change - please add news entry. |
picnixz
commented
Jan 23, 2025
I would prefer not changing the current code. It works and there is no need to have a macro which would add useless tests/casts for some functions. |
skirpichev
commented
Jan 23, 2025
Py_ssize_t case might be. |
picnixz
commented
Jan 23, 2025
In this case, I think we should only focus on the |
Then, we would just introduce roughly the same code block for Sure, that will do it's job to get us the fast path for medium-size integers, but the macro would be nice to remove the repetitive code and get symmetry with the already existing Those two macros would also be a pretty good fit for IMHO, all of those Then, there are less spots to consider when altering them. After all, I think this might be the reason why the fast path for medium-size integers was not done for all of them? |
picnixz
commented
Jan 23, 2025
Well.., I wouldn't mind if the 3 functions shared the exact same implementation, but it appears that there is an issue on Windows platforms. I actually don't mind the macro form but I'm -0 (I'm enclined to say yes because it would add symmetry but I'm also enclined to say no because overflow checks are apparently a bit different for |
chris-eibl
commented
Jan 23, 2025
They most probably relate to size_tabs_ival; /* Use size_t for unsigned operations */ \
size_tt; \which IMHO should read unsigned INT_TYPEabs_ival, t; /* Use size_t for unsigned operations */ \Which will make the macro harder to use for Another option might be, to implement |
picnixz
commented
Jan 23, 2025
Which in this case won't be symmetric anymore with the other macro. It would also affect readability. Currently, the code is fine as it is, albeit we're missing a fast path. We can add that fast path but we don't need to make it everything as macros. I guess we can use a macro for the long values but for |
chris-eibl
commented
Jan 23, 2025
They are not totally symmetric, anyway, because e.g. the signed and unsigned path are different in the fast path check: if (-(INT_TYPE)PyLong_MASK <= (ival) && (ival) <= (INT_TYPE)PyLong_MASK) { \
return_PyLong_FromMedium((sdigit)(ival)); \versus if ((ival) <= PyLong_MASK) { \
return_PyLong_FromMedium((sdigit)(ival)); \
} \But they are very similar. I trust you core devs here what to prefer (macro vs repetition). |
skirpichev
commented
Jan 24, 2025
I think it's a good opportunity to refactor repetitive code. |
chris-eibl
commented
Jan 25, 2025
How shall we proceed? @srinivasreddy do you plan to fix the errors? Or start over in a new PR? |
srinivasreddy
commented
Jan 25, 2025
@chris-eibl please feel free to start afresh . |
chris-eibl
commented
Jan 25, 2025
Done: #129301 |
gh-129149: Create a macro PYLONG_FROM_SIGNED, and leverage it in functions PyLong_FromLong, PyLong_FromLongLong and PyLong_FromSsize_t so that repetitive code is removed