-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
gh-135763: Argument Clinic: Implement allow_negative for ssize_t #138150
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
Conversation
42f8e13
to
4ff6d71
Compare
8d977a3
to
a36d270
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert all changes that are not tests. Do not use it yet. In addition, consider expanding the tests in test_clinic.py if possible.
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 |
a36d270
to
119ccf3
Compare
119ccf3
to
31863c4
Compare
I have made the requested changes; please review again I am going to raise a follow-up issue for migrating the existing manual bound checks, after this PR landed |
Thanks for making the requested changes! @picnixz: please review the changes made to this pull request. |
@@ -0,0 +1,2 @@ | |||
Add ``allow_negative`` flag to ``Py_ssize_t`` Argument Clinic converter, to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AC is unfortunately an internal tool so I don't think we should document it. However, what could be interesting is whether we want to expose a new parsing character for positive Py_ssize_t
values. For now, https://docs.python.org/3/c-api/arg.html#numbers only documents n
for Py_ssize_t
but maybe having something for Py_ssize_t >= 0
would make sense (I don't know, so for now, don't change anything).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AC is unfortunately an internal tool so I don't think we should document it.
There are already entries regarding arg clinic in the changelog 1, therefore I think it's plausible to keep the entry. I moved it to tools/demos however - should be a better fit.
Whether we want to expose a new parsing character for positive Py_ssize_t values.
I wonder why not providing a format unit for conversion to size_t
directly.
The only advantage is see with Py_ssize_t(allow_negative)
in comparison to size_t
is the fact that you could provide a negative value e.g. -1
default value as undefined / None
sentinel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree no NEWS entry is needed, but @wiomoc could create a PR for the devguide after this is merged, which is where we document AC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why not providing a format unit for conversion to size_t directly.
Because we use ssize_t for most internal sizes in Python as we need to indicate when a conversion failed with value = -1 && PyErr_Occurred() (I think).
The only advantage is see with Py_ssize_t(allow_negative) in comparison to size_t is the fact that you could provide a negative value e.g. -1 default value as undefined / None sentinel.
Unfortunately, internally, most structures use ssize_t
for sizes and not size_t
, so we could have overflows here (that is, we pass a value that fits on a size_t but not on a ssize_t). See Py_buffer
for instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation. Now I can make sense of it. I'll create an issue for adding N
as the format unit for Py_ssize_t
>= 0.
I have made the requested changes; please review again |
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 |
|
|
…ython#138150) Co-authored-by: Adam Turner <[email protected]>
Py_ssize_t
(but notsize_t
) #135763