Skip to content

Commit cca8253

Browse files
Move orig_argv to _PyRuntimeState.
1 parent c62b47b commit cca8253

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

Include/internal/pycore_runtime.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ typedef struct pyruntimestate {
129129

130130
unsigned long main_thread;
131131

132+
PyWideStringList orig_argv;
133+
132134
#define NEXITFUNCS 32
133135
void (*exitfuncs[NEXITFUNCS])(void);
134136
int nexitfuncs;

Python/initconfig.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -595,17 +595,13 @@ _Py_ClearStandardStreamEncoding(void)
595595

596596
/* --- Py_GetArgcArgv() ------------------------------------------- */
597597

598-
/* For Py_GetArgcArgv(); set by _Py_SetArgcArgv() */
599-
static PyWideStringList orig_argv = {.length = 0, .items = NULL};
600-
601-
602598
void
603599
_Py_ClearArgcArgv(void)
604600
{
605601
PyMemAllocatorEx old_alloc;
606602
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
607603

608-
_PyWideStringList_Clear(&orig_argv);
604+
_PyWideStringList_Clear(&_PyRuntime.orig_argv);
609605

610606
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
611607
}
@@ -620,7 +616,9 @@ _Py_SetArgcArgv(Py_ssize_t argc, wchar_t * const *argv)
620616
PyMemAllocatorEx old_alloc;
621617
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
622618

623-
res = _PyWideStringList_Copy(&orig_argv, &argv_list);
619+
// XXX _PyRuntime.orig_argv only gets cleared by Py_Main(),
620+
// so it it currently leaks for embedders.
621+
res = _PyWideStringList_Copy(&_PyRuntime.orig_argv, &argv_list);
624622

625623
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
626624
return res;
@@ -631,8 +629,8 @@ _Py_SetArgcArgv(Py_ssize_t argc, wchar_t * const *argv)
631629
void
632630
Py_GetArgcArgv(int *argc, wchar_t ***argv)
633631
{
634-
*argc = (int)orig_argv.length;
635-
*argv = orig_argv.items;
632+
*argc = (int)_PyRuntime.orig_argv.length;
633+
*argv = _PyRuntime.orig_argv.items;
636634
}
637635

638636

Tools/c-analyzer/cpython/ignored.tsv

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ Parser/myreadline.c - PyOS_ReadlineFunctionPointer -
8787

8888
Python/initconfig.c - _Py_StandardStreamEncoding -
8989
Python/initconfig.c - _Py_StandardStreamErrors -
90-
# XXX This only gets cleared by Py_Main().
91-
Python/initconfig.c - orig_argv -
9290

9391
##-----------------------
9492
## public C-API

0 commit comments

Comments
 (0)