Skip to content
Open
Show file tree
Hide file tree
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
break local == instrumented assumption
  • Loading branch information
P403n1x87 committed Mar 19, 2026
commit 1a3e8285f51ea8b5de671666030395f3b6108ee5
10 changes: 6 additions & 4 deletions Include/cpython/monitoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ extern "C" {
#define PY_MONITORING_EVENT_BRANCH_LEFT 8
#define PY_MONITORING_EVENT_BRANCH_RIGHT 9
#define PY_MONITORING_EVENT_STOP_ITERATION 10
#define PY_MONITORING_EVENT_PY_UNWIND 11

// TODO: PY_UNWIND requires no instrumentation so this definition is not
// entirely correct.
#define PY_MONITORING_IS_INSTRUMENTED_EVENT(ev) \
((ev) <= _PY_MONITORING_LOCAL_EVENTS)
((ev) <= PY_MONITORING_EVENT_STOP_ITERATION)

#define PY_MONITORING_EVENT_PY_UNWIND 11

#define PY_MONITORING_IS_LOCAL_EVENT(ev) \
((ev) < _PY_MONITORING_LOCAL_EVENTS)

Comment on lines +27 to +33
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

IMO all these data should be encoded in a "table", e.g.

typedef struct _monitoring_event {
    int id;
    bool local;
    bool instrumented;
    char* name; // maybe
} monitoring_event_t;

monitoring_event_t MONITORING_EVENTS[] = { ... };

#define PY_MONITORING_IS_INSTRUMENTED_EVENT(ev) (MONITORING_EVENTS[ev].instrumented)


/* Other events, mainly exceptions */
Expand Down
2 changes: 1 addition & 1 deletion Python/instrumentation.c
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ get_tools_for_instruction(PyCodeObject *code, PyInterpreterState *interp, int i,
event == PY_MONITORING_EVENT_C_RETURN);
event = PY_MONITORING_EVENT_CALL;
}
if (PY_MONITORING_IS_INSTRUMENTED_EVENT(event)) {
if (PY_MONITORING_IS_LOCAL_EVENT(event)) {
CHECK(debug_check_sanity(interp, code));
if (code->_co_monitoring->tools) {
tools = code->_co_monitoring->tools[i];
Expand Down
Loading