From 6e8f7d14da96ad32bbfb3a20c5266342d288a8b3 Mon Sep 17 00:00:00 2001 From: xiejunyi Date: Mon, 22 Mar 2021 21:07:55 +0800 Subject: [PATCH] fix sysmodule.c use static variables under building under building Python with --with-experimental-isolated-subinterpreters may cause crash --- Python/sysmodule.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 686b6cae3b2947..d7f951e428e374 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -695,7 +695,6 @@ sys_displayhook(PyObject *module, PyObject *o) { PyObject *outf; PyObject *builtins; - static PyObject *newline = NULL; PyThreadState *tstate = _PyThreadState_GET(); builtins = _PyImport_GetModuleId(&PyId_builtins); @@ -736,11 +735,13 @@ sys_displayhook(PyObject *module, PyObject *o) return NULL; } } - if (newline == NULL) { - newline = PyUnicode_FromString("\n"); - if (newline == NULL) - return NULL; + + PyObject *newline = PyUnicode_FromString("\n"); + if (newline == NULL) + { + return NULL; } + if (PyFile_WriteObject(newline, outf, Py_PRINT_RAW) != 0) return NULL; if (_PyObject_SetAttrId(builtins, &PyId__, o) != 0)