FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.12] gh-91054: make code watcher tests resilient to other watchers (GH-107821) by miss-islington · Pull Request #107835 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .tsv  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
14 changes: 11 additions & 3 deletions Modules/_testcapi/watchers.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ _testcapi_unwatch_type_impl(PyObject *module, int watcher_id, PyObject *type)
// Test code object watching

#define NUM_CODE_WATCHERS 2
static int code_watcher_ids[NUM_CODE_WATCHERS] = {-1, -1};
static int num_code_object_created_events[NUM_CODE_WATCHERS] = {0, 0};
static int num_code_object_destroyed_events[NUM_CODE_WATCHERS] = {0, 0};

Expand Down Expand Up @@ -345,11 +346,13 @@ add_code_watcher(PyObject *self, PyObject *which_watcher)
long which_l = PyLong_AsLong(which_watcher);
if (which_l == 0) {
watcher_id = PyCode_AddWatcher(first_code_object_callback);
code_watcher_ids[0] = watcher_id;
num_code_object_created_events[0] = 0;
num_code_object_destroyed_events[0] = 0;
}
else if (which_l == 1) {
watcher_id = PyCode_AddWatcher(second_code_object_callback);
code_watcher_ids[1] = watcher_id;
num_code_object_created_events[1] = 0;
num_code_object_destroyed_events[1] = 0;
}
Expand All @@ -375,9 +378,14 @@ clear_code_watcher(PyObject *self, PyObject *watcher_id)
return NULL;
}
// reset static events counters
if (watcher_id_l >= 0 && watcher_id_l < NUM_CODE_WATCHERS) {
num_code_object_created_events[watcher_id_l] = 0;
num_code_object_destroyed_events[watcher_id_l] = 0;
if (watcher_id_l >= 0) {
for (int i = 0; i < NUM_CODE_WATCHERS; i++) {
if (watcher_id_l == code_watcher_ids[i]) {
code_watcher_ids[i] = -1;
num_code_object_created_events[i] = 0;
num_code_object_destroyed_events[i] = 0;
}
}
}
Py_RETURN_NONE;
}
Expand Down
1 change: 1 addition & 0 deletions Tools/c-analyzer/cpython/ignored.tsv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ Modules/_testcapi/watchers.c - g_dict_watch_events -
Modules/_testcapi/watchers.c - g_dict_watchers_installed -
Modules/_testcapi/watchers.c - g_type_modified_events -
Modules/_testcapi/watchers.c - g_type_watchers_installed -
Modules/_testcapi/watchers.c - code_watcher_ids -
Modules/_testcapi/watchers.c - num_code_object_created_events -
Modules/_testcapi/watchers.c - num_code_object_destroyed_events -
Modules/_testcapi/watchers.c - pyfunc_watchers -
Expand Down

Back | FazBrowse Home | New Git URL