-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-134411: assert PyLong_FromLong(x) != NULL
when x
is known to be small
#134415
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
base: main
Are you sure you want to change the base?
Conversation
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.
PyLong_FromLong
sets an exception when it fails, so the call to PyObject_SetAttrString
is unsafe. We should return NULL
instead of switching to Py_XDECREF
.
But, as @sergey-miryanov mentioned, this can't fail for integers <255. I think it's also reasonable to add an assertion here instead of adding error handling.
…case and can't return NULL. Added assert for extra confidence. python#134411 (comment)
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.
LGTM, with one little note.
Python/instrumentation.c
Outdated
@@ -2558,18 +2558,22 @@ PyObject *_Py_CreateMonitoringObject(void) | |||
err = PyObject_SetAttrString(events, "NO_EVENTS", _PyLong_GetZero()); | |||
if (err) goto error; | |||
PyObject *val = PyLong_FromLong(PY_MONITORING_DEBUGGER_ID); | |||
assert(val != NULL); |
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 think it'd be a good idea to add a comment explaining why it can't ever fail.
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'll add it tomorrow.
PyLong_FromLong(x) != NULL
when x
is known to be small
Python/instrumentation.c
: ensure non-NULLPyLong_FromLong
results when possible #134411