summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-07-03 15:13:21 (GMT)
committerGitHub <noreply@github.com>2023-07-03 15:13:21 (GMT)
commit887a7e603628a7718233cf8068d7be8ccd9d7254 (patch)
tree94b9503d942912200cca2764b68c934f12479cc1 /Modules
parent5f20152f01febf4ffd9572a8ab3e980a4660ef69 (diff)
downloadcpython-887a7e603628a7718233cf8068d7be8ccd9d7254.zip
cpython-887a7e603628a7718233cf8068d7be8ccd9d7254.tar.gz
cpython-887a7e603628a7718233cf8068d7be8ccd9d7254.tar.bz2
[3.12] gh-91053: make func watcher tests resilient to other func watchers (GH-106286) (#106365)
gh-91053: make func watcher tests resilient to other func watchers (GH-106286) (cherry picked from commit 58906213cc5d8f2be311664766b4923ef29dae1f) Co-authored-by: Carl Meyer <carl@oddbird.net>
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testcapi/watchers.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/Modules/_testcapi/watchers.c b/Modules/_testcapi/watchers.c
index d2c71fb..7167943 100644
--- a/Modules/_testcapi/watchers.c
+++ b/Modules/_testcapi/watchers.c
@@ -432,9 +432,9 @@ allocate_too_many_code_watchers(PyObject *self, PyObject *args)
// Test function watchers
-#define NUM_FUNC_WATCHERS 2
-static PyObject *pyfunc_watchers[NUM_FUNC_WATCHERS];
-static int func_watcher_ids[NUM_FUNC_WATCHERS] = {-1, -1};
+#define NUM_TEST_FUNC_WATCHERS 2
+static PyObject *pyfunc_watchers[NUM_TEST_FUNC_WATCHERS];
+static int func_watcher_ids[NUM_TEST_FUNC_WATCHERS] = {-1, -1};
static PyObject *
get_id(PyObject *obj)
@@ -508,7 +508,7 @@ second_func_watcher_callback(PyFunction_WatchEvent event,
return call_pyfunc_watcher(pyfunc_watchers[1], event, func, new_value);
}
-static PyFunction_WatchCallback func_watcher_callbacks[NUM_FUNC_WATCHERS] = {
+static PyFunction_WatchCallback func_watcher_callbacks[NUM_TEST_FUNC_WATCHERS] = {
first_func_watcher_callback,
second_func_watcher_callback
};
@@ -533,26 +533,25 @@ add_func_watcher(PyObject *self, PyObject *func)
return NULL;
}
int idx = -1;
- for (int i = 0; i < NUM_FUNC_WATCHERS; i++) {
+ for (int i = 0; i < NUM_TEST_FUNC_WATCHERS; i++) {
if (func_watcher_ids[i] == -1) {
idx = i;
break;
}
}
if (idx == -1) {
- PyErr_SetString(PyExc_RuntimeError, "no free watchers");
- return NULL;
- }
- PyObject *result = PyLong_FromLong(idx);
- if (result == NULL) {
+ PyErr_SetString(PyExc_RuntimeError, "no free test watchers");
return NULL;
}
func_watcher_ids[idx] = PyFunction_AddWatcher(func_watcher_callbacks[idx]);
if (func_watcher_ids[idx] < 0) {
- Py_DECREF(result);
return NULL;
}
pyfunc_watchers[idx] = Py_NewRef(func);
+ PyObject *result = PyLong_FromLong(func_watcher_ids[idx]);
+ if (result == NULL) {
+ return NULL;
+ }
return result;
}
@@ -569,7 +568,7 @@ clear_func_watcher(PyObject *self, PyObject *watcher_id_obj)
return NULL;
}
int idx = -1;
- for (int i = 0; i < NUM_FUNC_WATCHERS; i++) {
+ for (int i = 0; i < NUM_TEST_FUNC_WATCHERS; i++) {
if (func_watcher_ids[i] == wid) {
idx = i;
break;