diff options
| author | Dong-hee Na <donghee.na92@gmail.com> | 2021-08-17 15:52:50 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-18 00:52:50 +0900 |
| commit | c2c857b40f226575d64e0d56a759cbd799f51e62 (patch) | |
| tree | 892cfca4ed158bdb48e1eefdee6aeaf230ec8911 /Python/pylifecycle.c | |
| parent | 96346cb6d0593ef9ec122614347ccb053cd63433 (diff) | |
| download | cpython-git-c2c857b40f226575d64e0d56a759cbd799f51e62.tar.gz | |
bpo-44895: Introduce PYTHONDUMPREFSFILE variable for refcount dumping (GH-27767)
Diffstat (limited to 'Python/pylifecycle.c')
| -rw-r--r-- | Python/pylifecycle.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index eeaf20b461..f3b6b0ac68 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1737,6 +1737,7 @@ Py_FinalizeEx(void) #endif #ifdef Py_TRACE_REFS int dump_refs = tstate->interp->config.dump_refs; + wchar_t *dump_refs_file = tstate->interp->config.dump_refs_file; #endif #ifdef WITH_PYMALLOC int malloc_stats = tstate->interp->config.malloc_stats; @@ -1835,9 +1836,22 @@ Py_FinalizeEx(void) * Alas, a lot of stuff may still be alive now that will be cleaned * up later. */ + + FILE *dump_refs_fp = NULL; + if (dump_refs_file != NULL) { + dump_refs_fp = _Py_wfopen(dump_refs_file, L"w"); + if (dump_refs_fp == NULL) { + fprintf(stderr, "PYTHONDUMPREFSFILE: cannot create file: %ls\n", dump_refs_file); + } + } + if (dump_refs) { _Py_PrintReferences(stderr); } + + if (dump_refs_fp != NULL) { + _Py_PrintReferences(dump_refs_fp); + } #endif /* Py_TRACE_REFS */ finalize_interp_clear(tstate); @@ -1848,9 +1862,15 @@ Py_FinalizeEx(void) * An address can be used to find the repr of the object, printed * above by _Py_PrintReferences. */ + if (dump_refs) { _Py_PrintReferenceAddresses(stderr); } + + if (dump_refs_fp != NULL) { + _Py_PrintReferenceAddresses(dump_refs_fp); + fclose(dump_refs_fp); + } #endif /* Py_TRACE_REFS */ #ifdef WITH_PYMALLOC if (malloc_stats) { |
