Skip to content

Commit 5324b4f

Browse files
committed
bpo-44895 Address Victor's suggestion
1 parent 5d93958 commit 5324b4f

File tree

5 files changed

+12
-14
lines changed

5 files changed

+12
-14
lines changed

Doc/using/cmdline.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -976,9 +976,9 @@ Debug-mode variables
976976

977977
Need Python configured with the :option:`--with-trace-refs` build option.
978978

979-
.. envvar:: PYTHONDUMPDIR
979+
.. envvar:: PYTHONDUMPFILE
980980

981-
If set, Python will create a file at '$(PYTHONDUMPDIR)/cpython-tracerefs-<pid>.txt` as dump file
981+
If set, Python will create a file at `$PYTHONDUMPFILE` as dump file
982982
which is generated by :envvar:`PYTHONDUMPREFS`.
983983

984984
Need Python configured with the :option:`--with-trace-refs` build option.

Include/cpython/initconfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ typedef struct PyConfig {
144144
int show_ref_count;
145145
int dump_refs;
146146
int malloc_stats;
147-
wchar_t *python_dump_dir;
147+
wchar_t *python_dump_file;
148148
wchar_t *filesystem_encoding;
149149
wchar_t *filesystem_errors;
150150
wchar_t *pycache_prefix;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
A debug variable :envvar:`PYTHONDUMPDIR` is added for creating a dump file
1+
A debug variable :envvar:`PYTHONDUMPFILE` is added for creating a dump file
22
which is generated by :envvar:`PYTHONDUMPREFS`. Patch by Dong-hee Na.

Python/initconfig.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ _PyConfig_Copy(PyConfig *config, const PyConfig *config2)
898898
COPY_ATTR(no_debug_ranges);
899899
COPY_ATTR(show_ref_count);
900900
COPY_ATTR(dump_refs);
901-
COPY_ATTR(python_dump_dir);
901+
COPY_ATTR(python_dump_file);
902902
COPY_ATTR(malloc_stats);
903903

904904
COPY_WSTR_ATTR(pycache_prefix);
@@ -1702,9 +1702,9 @@ config_read_env_vars(PyConfig *config)
17021702
config->malloc_stats = 1;
17031703
}
17041704

1705-
if (config->python_dump_dir == NULL) {
1706-
status = CONFIG_GET_ENV_DUP(config, &config->python_dump_dir,
1707-
L"PYTHONDUMPDIR", "PYTHONDUMPDIR");
1705+
if (config->python_dump_file == NULL) {
1706+
status = CONFIG_GET_ENV_DUP(config, &config->python_dump_file,
1707+
L"PYTHONDUMPFILE", "PYTHONDUMPFILE");
17081708
if (_PyStatus_EXCEPTION(status)) {
17091709
return status;
17101710
}

Python/pylifecycle.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#ifdef MS_WINDOWS
3333
# undef BYTE
3434
# include "windows.h"
35-
# define getpid GetCurrentProcessId
35+
3636
extern PyTypeObject PyWindowsConsoleIO_Type;
3737
# define PyWindowsConsoleIO_Check(op) \
3838
(PyObject_TypeCheck((op), &PyWindowsConsoleIO_Type))
@@ -1736,7 +1736,7 @@ Py_FinalizeEx(void)
17361736
int show_ref_count = tstate->interp->config.show_ref_count;
17371737
#endif
17381738
#ifdef Py_TRACE_REFS
1739-
wchar_t *python_dump_dir = tstate->interp->config.python_dump_dir;
1739+
wchar_t *python_dump_file = tstate->interp->config.python_dump_file;
17401740
int dump_refs = tstate->interp->config.dump_refs;
17411741
#endif
17421742
#ifdef WITH_PYMALLOC
@@ -1838,10 +1838,8 @@ Py_FinalizeEx(void)
18381838
*/
18391839

18401840
FILE *fp = stderr;
1841-
if (python_dump_dir != NULL) {
1842-
char dump_file_name[255];
1843-
sprintf(dump_file_name, "%S/python-tracerefs-%d.txt", python_dump_dir, getpid());
1844-
fp = fopen(dump_file_name,"w");
1841+
if (python_dump_file != NULL) {
1842+
fp = _Py_wfopen(python_dump_file, L"w");
18451843
}
18461844
if (dump_refs) {
18471845
_Py_PrintReferences(fp);

0 commit comments

Comments
 (0)