bpo-38644: Add _PySys_Audit() which takes tstate (GH-19180)

Add _PySys_Audit() function to the internal C API: similar to
PySys_Audit(), but requires a mandatory tstate parameter.

Cleanup sys_audit_tstate() code: remove code path for NULL tstate,
since the function exits at entry if tstate is NULL. Remove also code
path for NULL tstate->interp: should_audit() now ensures that it is
not NULL (even if tstate->interp cannot be NULL in practice).

PySys_AddAuditHook() now checks if tstate is not NULL to decide if
tstate can be used or not, and tstate is set to NULL if the runtime
is not initialized yet.

Use _PySys_Audit() in sysmodule.c.
This commit is contained in:
Victor Stinner 2020-03-26 18:57:32 +01:00 committed by GitHub
parent e0b8101492
commit 08faf0016e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 146 additions and 67 deletions

View file

@ -16,6 +16,7 @@
#include "pycore_pylifecycle.h"
#include "pycore_pymem.h"
#include "pycore_pystate.h"
#include "pycore_sysmodule.h"
#include "pycore_traceback.h"
#include "grammar.h"
#include "node.h"
@ -1409,11 +1410,7 @@ Py_FinalizeEx(void)
_PyGC_CollectIfEnabled();
/* Clear all loghooks */
/* We want minimal exposure of this function, so define the extern
* here. The linker should discover the correct function without
* exporting a symbol. */
extern void _PySys_ClearAuditHooks(void);
_PySys_ClearAuditHooks();
_PySys_ClearAuditHooks(tstate);
/* Destroy all modules */
_PyImport_Cleanup(tstate);