diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-12-06 16:26:10 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-06 16:26:10 (GMT) |
commit | 6bf992a1ac6f3f4d0f83ead9c6403a76afdbe6eb (patch) | |
tree | 592a2085a4d49a5fc394e96b4e3b57d25d82b38a /Python/pylifecycle.c | |
parent | 672b6baa71010f236ee8c8ce912e98cb542385c6 (diff) | |
download | cpython-6bf992a1ac6f3f4d0f83ead9c6403a76afdbe6eb.zip cpython-6bf992a1ac6f3f4d0f83ead9c6403a76afdbe6eb.tar.gz cpython-6bf992a1ac6f3f4d0f83ead9c6403a76afdbe6eb.tar.bz2 |
bpo-32030: Add pymain_get_global_config() (#4735)
* Py_Main() now starts by reading Py_xxx configuration variables to
only work on its own private structure, and then later writes back
the configuration into these variables.
* Replace Py_GETENV() with pymain_get_env_var() which ignores empty
variables.
* Add _PyCoreConfig.dump_refs
* Add _PyCoreConfig.malloc_stats
* _PyObject_DebugMallocStats() is now responsible to check if debug
hooks are installed. The function returns 1 if stats were written,
or 0 if the hooks are disabled. Mark _PyMem_PymallocEnabled() as
static.
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r-- | Python/pylifecycle.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 504036c..0b3aa98 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1103,6 +1103,10 @@ Py_FinalizeEx(void) tstate = PyThreadState_GET(); interp = tstate->interp; + /* Copy the core config to be able to use it even + after PyInterpreterState_Delete() */ + _PyCoreConfig core_config = interp->core_config; + /* Remaining threads (e.g. daemon threads) will automatically exit after taking the GIL (in PyEval_RestoreThread()). */ _PyRuntime.finalizing = tstate; @@ -1186,7 +1190,7 @@ Py_FinalizeEx(void) _PyHash_Fini(); #ifdef Py_REF_DEBUG - if (interp->core_config.show_ref_count) { + if (core_config.show_ref_count) { _PyDebug_PrintTotalRefs(); } #endif @@ -1197,8 +1201,9 @@ Py_FinalizeEx(void) * Alas, a lot of stuff may still be alive now that will be cleaned * up later. */ - if (Py_GETENV("PYTHONDUMPREFS")) + if (core_config.dump_refs) { _Py_PrintReferences(stderr); + } #endif /* Py_TRACE_REFS */ /* Clear interpreter state and all thread states. */ @@ -1260,14 +1265,13 @@ Py_FinalizeEx(void) * An address can be used to find the repr of the object, printed * above by _Py_PrintReferences. */ - if (Py_GETENV("PYTHONDUMPREFS")) + if (core_config.dump_refs) { _Py_PrintReferenceAddresses(stderr); + } #endif /* Py_TRACE_REFS */ #ifdef WITH_PYMALLOC - if (_PyMem_PymallocEnabled()) { - char *opt = Py_GETENV("PYTHONMALLOCSTATS"); - if (opt != NULL && *opt != '\0') - _PyObject_DebugMallocStats(stderr); + if (core_config.malloc_stats) { + _PyObject_DebugMallocStats(stderr); } #endif |