gh-130163: Fix usage of borrow references from _PySys_GetAttr #130282
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
WIP
printand concurrently modifyingsys.stdout#130163_pickle.c/whichmodule_threadmodule.c/thread_excepthookfaulthandler.c/faulthandler_get_filenobltinmodule.c/builtin_print_implbltinmodule.c/builtin_input_implerrors.c/write_unraisable_excerrors.c/format_unraisable_v_warnings.c/show_warningintrinsics.c/print_exprpylifecycle.c/flush_std_filespythonrun.c/_PyRun_InteractiveLoopObjectpythonrun.c/pyrun_one_parse_astpythonrun.c/_Py_HandleSystemExitAndKeyboardInterruptpythonrun.c/_PyErr_PrintExpythonrun.c/PyErr_Displaypythonrun.c/flush_io_streamsysmodule.c/sys_displayhooksysmodule.c/get_warnoptionssysmodule.c/PySys_ResetWarnOptionssysmodule.c/PySys_HasWarnOptionssysmodule.c/_PySys_AddXOptionWithErrorsysmodule.c/PySys_SetArgvExsysmodule.c/sys_writesysmodule.c/sys_formattraceback.c/_Py_FindSourceFilesys_displayhook, but not where it's used.sys_write,sys_format- I have checked all the places where they called, and most of the locations are safe. However, a few places use%sspecifier, in such places it is very tricky to getsegfault.get_warnoptions,PySys_ResetWarnOptions,_PySys_AddXOptionWithError- are deprecated, but it is a very tricky to getsegfaulttoo.flush_io_stream,PyErr_Display,pyrun_one_parse_ast,print_expr,write_unraisable_exc,thread_excepthook- very tight - They use a borrowed reference right after getting. It might be possible to reproduce it under heavy contention, but I wasn't able to do so._PyRun_InteractiveLoopObjectonly checks presence ofps1andps2.flush_std_filesused from_Py_Finalizeand fromfatal_error. For_Py_FinalizeI can repro, forfatal_error- no.whichmodule,_Py_FindSourceFileiterate borrowed reference, but I wasn't able to reproducesegfault._PySys_GetAttrcalled without an exception set.