summaryrefslogtreecommitdiffstats
path: root/Python/pystate.c
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2019-05-23 15:45:22 (GMT)
committerGitHub <noreply@github.com>2019-05-23 15:45:22 (GMT)
commitb82e17e626f7b1cd98aada0b1ebb65cb9f8fb184 (patch)
tree5370a2a075707cb0b37ce135cad6ffe23da424c4 /Python/pystate.c
parente788057a9188ff37e232729815dfda2529079420 (diff)
downloadcpython-b82e17e626f7b1cd98aada0b1ebb65cb9f8fb184.zip
cpython-b82e17e626f7b1cd98aada0b1ebb65cb9f8fb184.tar.gz
cpython-b82e17e626f7b1cd98aada0b1ebb65cb9f8fb184.tar.bz2
bpo-36842: Implement PEP 578 (GH-12613)
Adds sys.audit, sys.addaudithook, io.open_code, and associated C APIs.
Diffstat (limited to 'Python/pystate.c')
-rw-r--r--Python/pystate.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/Python/pystate.c b/Python/pystate.c
index 879a5a9..41c6622 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -45,8 +45,19 @@ static void _PyThreadState_Delete(_PyRuntimeState *runtime, PyThreadState *tstat
static _PyInitError
_PyRuntimeState_Init_impl(_PyRuntimeState *runtime)
{
+ /* We preserve the hook across init, because there is
+ currently no public API to set it between runtime
+ initialization and interpreter initialization. */
+ void *open_code_hook = runtime->open_code_hook;
+ void *open_code_userdata = runtime->open_code_userdata;
+ _Py_AuditHookEntry *audit_hook_head = runtime->audit_hook_head;
+
memset(runtime, 0, sizeof(*runtime));
+ runtime->open_code_hook = open_code_hook;
+ runtime->open_code_userdata = open_code_userdata;
+ runtime->audit_hook_head = audit_hook_head;
+
_PyGC_Initialize(&runtime->gc);
_PyEval_Initialize(&runtime->ceval);
_PyPreConfig_InitPythonConfig(&runtime->preconfig);
@@ -181,6 +192,10 @@ _PyInterpreterState_Enable(_PyRuntimeState *runtime)
PyInterpreterState *
PyInterpreterState_New(void)
{
+ if (PySys_Audit("cpython.PyInterpreterState_New", NULL) < 0) {
+ return NULL;
+ }
+
PyInterpreterState *interp = PyMem_RawMalloc(sizeof(PyInterpreterState));
if (interp == NULL) {
return NULL;
@@ -233,6 +248,8 @@ PyInterpreterState_New(void)
interp->tstate_next_unique_id = 0;
+ interp->audit_hooks = NULL;
+
return interp;
}
@@ -240,11 +257,18 @@ PyInterpreterState_New(void)
static void
_PyInterpreterState_Clear(_PyRuntimeState *runtime, PyInterpreterState *interp)
{
+ if (PySys_Audit("cpython.PyInterpreterState_Clear", NULL) < 0) {
+ PyErr_Clear();
+ }
+
HEAD_LOCK(runtime);
for (PyThreadState *p = interp->tstate_head; p != NULL; p = p->next) {
PyThreadState_Clear(p);
}
HEAD_UNLOCK(runtime);
+
+ Py_CLEAR(interp->audit_hooks);
+
_PyCoreConfig_Clear(&interp->core_config);
Py_CLEAR(interp->codec_search_path);
Py_CLEAR(interp->codec_search_cache);
@@ -1057,6 +1081,10 @@ _PyThread_CurrentFrames(void)
PyObject *result;
PyInterpreterState *i;
+ if (PySys_Audit("sys._current_frames", NULL) < 0) {
+ return NULL;
+ }
+
result = PyDict_New();
if (result == NULL)
return NULL;