bpo-44895: Introduce PYTHONDUMPREFSFILE variable for refcount dumping (GH-27767)

This commit is contained in:
Dong-hee Na 2021-08-17 15:52:50 +00:00 committed by GitHub
parent 96346cb6d0
commit c2c857b40f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 0 deletions

View file

@ -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) {