8000 gh-81057: Move More Globals to _PyRuntimeState by ericsnowcurrently · Pull Request #100092 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-81057: Move More Globals to _PyRuntimeState #100092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move orig_argv to _PyRuntimeState.
  • Loading branch information
ericsnowcurrently committed Dec 7, 2022
commit cca8253ff52d3382be9fda6bfba7e15a693ce60c
2 changes: 2 additions & 0 deletions Include/internal/pycore_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ typedef struct pyruntimestate {

unsigned long main_thread;

PyWideStringList orig_argv;

#define NEXITFUNCS 32
void (*exitfuncs[NEXITFUNCS])(void);
int nexitfuncs;
Expand Down
14 changes: 6 additions & 8 deletions Python/initconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,17 +595,13 @@ _Py_ClearStandardStreamEncoding(void)

/* --- Py_GetArgcArgv() ------------------------------------------- */

/* For Py_GetArgcArgv(); set by _Py_SetArgcArgv() */
static PyWideStringList orig_argv = {.length = 0, .items = NULL};


void
_Py_ClearArgcArgv(void)
{
PyMemAllocatorEx old_alloc;
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);

_PyWideStringList_Clear(&orig_argv);
_PyWideStringList_Clear(&_PyRuntime.orig_argv);

PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
}
Expand All @@ -620,7 +616,9 @@ _Py_SetArgcArgv(Py_ssize_t argc, wchar_t * const *argv)
PyMemAllocatorEx old_alloc;
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);

res = _PyWideStringList_Copy(&orig_argv, &argv_list);
// XXX _PyRuntime.orig_argv only gets cleared by Py_Main(),
// so it it currently leaks for embedders.
res = _PyWideStringList_Copy(&_PyRuntime.orig_argv, &argv_list);

PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
return res;
Expand All @@ -631,8 +629,8 @@ _Py_SetArgcArgv(Py_ssize_t argc, wchar_t * const *argv)
void
Py_GetArgcArgv(int *argc, wchar_t ***argv)
{
*argc = (int)orig_argv.length;
*argv = orig_argv.items;
*argc = (int)_PyRuntime.orig_argv.length;
*argv = _PyRuntime.orig_argv.items;
}


Expand Down
2 changes: 0 additions & 2 deletions Tools/c-analyzer/cpython/ignored.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ Parser/myreadline.c - PyOS_ReadlineFunctionPointer -

Python/ini 502E tconfig.c - _Py_StandardStreamEncoding -
Python/initconfig.c - _Py_StandardStreamErrors -
# XXX This only gets cleared by Py_Main().
Python/initconfig.c - orig_argv -

##-----------------------
## public C-API
Expand Down
0