[Python-checkins] [3.12] gh-91054: make code watcher tests resilient to other watchers (GH-107821) (#107835)
Yhg1s
webhook-mailer at python.org
Fri Aug 11 10:13:17 EDT 2023
https://github.com/python/cpython/commit/98dd9d9725e6fa137e14f00b2907fdec19aee4ac
commit: 98dd9d9725e6fa137e14f00b2907fdec19aee4ac
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Yhg1s <thomas at python.org>
date: 2023-08-11T16:13:14+02:00
summary:
[3.12] gh-91054: make code watcher tests resilient to other watchers (GH-107821) (#107835)
gh-91054: make code watcher tests resilient to other watchers (GH-107821)
(cherry picked from commit 2ec16fed14aae896e38dd5bd9e73e2eddc974439)
Co-authored-by: Carl Meyer <carl at oddbird.net>
files:
M Modules/_testcapi/watchers.c
M Tools/c-analyzer/cpython/ignored.tsv
diff --git a/Modules/_testcapi/watchers.c b/Modules/_testcapi/watchers.c
index 7167943fffab3..fd695df749070 100644
--- a/Modules/_testcapi/watchers.c
+++ b/Modules/_testcapi/watchers.c
@@ -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};
@@ -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;
}
@@ -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;
}
diff --git a/Tools/c-analyzer/cpython/ignored.tsv b/Tools/c-analyzer/cpython/ignored.tsv
index 78be97da41b50..6a7c14ebb220a 100644
--- a/Tools/c-analyzer/cpython/ignored.tsv
+++ b/Tools/c-analyzer/cpython/ignored.tsv
@@ -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 -
More information about the Python-checkins
mailing list