Skip to content

gh-121153: Change _PyLong_CompactValue() return type to int #121536

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

Closed
wants to merge 12 commits into from

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Jul 9, 2024

@vstinner
Copy link
Member Author

vstinner commented Jul 9, 2024

cc @serhiy-storchaka @markshannon

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

This is incomplete change. You need also to change the code that calls _PyLong_CompactValue() (and simplify it).

@bedevere-app
Copy link

bedevere-app bot commented Jul 9, 2024

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@vstinner
Copy link
Member Author

You need also to change the code that calls _PyLong_CompactValue() (and simplify it).

Ok, I updated _PyLong_CompactValue() usage as well.

Copy link
Member Author

@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.

@serhiy-storchaka: It would be nice if you could review this change since I'm not sure if it's correct.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

You need to update also other code. Take #121154 and replace Py_ssize_t with int. Then remove dead code.

@@ -2644,8 +2644,7 @@ builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start)
b = PyLong_AsLongAndOverflow(item, &overflow);
}
if (overflow == 0 &&
(i_result >= 0 ? (b <= LONG_MAX - i_result)
: (b >= LONG_MIN - i_result)))
(i_result >= 0 ? (1 - i_result) : (1 - i_result)))
Copy link
Member

Choose a reason for hiding this comment

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

This code does not make sense.

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 don't understand this code.

Copy link
Member

Choose a reason for hiding this comment

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

This is an overflow check for i_result += b.

@vstinner
Copy link
Member Author

You need to update also other code. Take #121154 and replace Py_ssize_t with int. Then remove dead code.

I'm not sure that I'm not the right person to implement this change. Maybe you should create your own PR and I abandon this PR.

@vstinner
Copy link
Member Author

This PR changes PyUnstable_Long_CompactValue() return type. I documented that change.

If it's an issue, we can leave PyUnstable_Long_CompactValue() return type unchanged.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

Yes, it needs also changing PyUnstable_Long_CompactValue which may be defined as an alias of _PyLong_CompactValue.

Technically, it now LGTM. But we should ask @markshannon what he thinks about changing the return type. Why it was Py_ssize_t at first place?

@vstinner
Copy link
Member Author

#121154 was merged instead.

@vstinner vstinner closed this Jul 13, 2024
@vstinner vstinner deleted the long_compact branch July 13, 2024 17:35
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