Skip to content

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

Merged
merged 7 commits into from
Jul 21, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Since PyLong_From Long(PY_MONITORING_DEBUGGER_ID) falls to small_int …
…case and can't return NULL. Added assert for extra confidence.

#134411 (comment)
  • Loading branch information
smurav committed May 21, 2025
commit 4429178da24e81355a5707fcd380a083ead8ab93
12 changes: 8 additions & 4 deletions Python/instrumentation.c
Original file line number Diff line number Diff line change
Expand Up @@ -2558,20 +2558,24 @@ 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);
Copy link
Member

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.

Copy link
Contributor Author

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.

err = PyObject_SetAttrString(mod, "DEBUGGER_ID", val);
Py_XDECREF(val);
Py_DECREF(val);
if (err) goto error;
val = PyLong_FromLong(PY_MONITORING_COVERAGE_ID);
assert(val != NULL);
err = PyObject_SetAttrString(mod, "COVERAGE_ID", val);
Py_XDECREF(val);
Py_DECREF(val);
if (err) goto error;
val = PyLong_FromLong(PY_MONITORING_PROFILER_ID);
assert(val != NULL);
err = PyObject_SetAttrString(mod, "PROFILER_ID", val);
Py_XDECREF(val);
Py_DECREF(val);
if (err) goto error;
val = PyLong_FromLong(PY_MONITORING_OPTIMIZER_ID);
assert(val != NULL);
err = PyObject_SetAttrString(mod, "OPTIMIZER_ID", val);
Py_XDECREF(val);
Py_DECREF(val);
if (err) goto error;
return mod;
error:
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy