struct _obmalloc_state *obmalloc;
PyObject *audit_hooks;
- PyMutex audit_hooks_mutex;
PyType_WatchCallback type_watchers[TYPE_MAX_WATCHERS];
PyCode_WatchCallback code_watchers[CODE_MAX_WATCHERS];
PyContext_WatchCallback context_watchers[CONTEXT_MAX_WATCHERS];
workers = [lambda: worker(i) for i in range(5)]
threading_helper.run_concurrently(workers)
- def test_sys_audit_hooks(self):
- def _hook(*args):
- return None
-
- def adder():
- for _ in range(100):
- sys.addaudithook(_hook)
-
- def auditor():
- for _ in range(2000):
- sys.audit("fusil.tsan.test")
-
- threading_helper.run_concurrently([adder, auditor])
-
if __name__ == "__main__":
unittest.main()
llist_init(&interp->mem_free_queue.head);
llist_init(&interp->asyncio_tasks_head);
interp->asyncio_tasks_lock = (PyMutex){0};
- interp->audit_hooks_mutex = (PyMutex){0};
for (int i = 0; i < _PY_MONITORING_UNGROUPED_EVENTS; i++) {
interp->monitors.tools[i] = 0;
}
return 0;
}
return (interp->runtime->audit_hooks.head
- || FT_ATOMIC_LOAD_PTR_ACQUIRE(interp->audit_hooks)
+ || interp->audit_hooks
|| PyDTrace_AUDIT_ENABLED());
}
}
/* Call interpreter hooks */
- PyObject *audit_hooks = FT_ATOMIC_LOAD_PTR_ACQUIRE(is->audit_hooks);
- if (audit_hooks) {
+ if (is->audit_hooks) {
eventName = PyUnicode_FromString(event);
if (!eventName) {
goto exit;
}
- hooks = PyObject_GetIter(audit_hooks);
+ hooks = PyObject_GetIter(is->audit_hooks);
if (!hooks) {
goto exit;
}
}
PyInterpreterState *interp = tstate->interp;
- PyMutex mutex = interp->audit_hooks_mutex;
- PyMutex_Lock(&mutex);
-
if (interp->audit_hooks == NULL) {
- PyObject *new_list = PyList_New(0);
- if (new_list == NULL) {
- goto error;
+ interp->audit_hooks = PyList_New(0);
+ if (interp->audit_hooks == NULL) {
+ return NULL;
}
/* Avoid having our list of hooks show up in the GC module */
- PyObject_GC_UnTrack(new_list);
- FT_ATOMIC_STORE_PTR_RELEASE(interp->audit_hooks, new_list);
+ PyObject_GC_UnTrack(interp->audit_hooks);
}
if (PyList_Append(interp->audit_hooks, hook) < 0) {
- goto error;
+ return NULL;
}
- PyMutex_Unlock(&mutex);
Py_RETURN_NONE;
-
-error:
- PyMutex_Unlock(&mutex);
- return NULL;
}
/*[clinic input]