diff options
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 59 |
1 files changed, 35 insertions, 24 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 852babb..080c541 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -519,8 +519,6 @@ Return the profiling function set with sys.setprofile.\n\ See the profiler chapter in the library manual." ); -static int _check_interval = 100; - static PyObject * sys_setcheckinterval(PyObject *self, PyObject *args) { @@ -529,7 +527,8 @@ sys_setcheckinterval(PyObject *self, PyObject *args) "are deprecated. Use sys.setswitchinterval() " "instead.", 1) < 0) return NULL; - if (!PyArg_ParseTuple(args, "i:setcheckinterval", &_check_interval)) + PyInterpreterState *interp = PyThreadState_GET()->interp; + if (!PyArg_ParseTuple(args, "i:setcheckinterval", &interp->check_interval)) return NULL; Py_RETURN_NONE; } @@ -549,7 +548,8 @@ sys_getcheckinterval(PyObject *self, PyObject *args) "are deprecated. Use sys.getswitchinterval() " "instead.", 1) < 0) return NULL; - return PyLong_FromLong(_check_interval); + PyInterpreterState *interp = PyThreadState_GET()->interp; + return PyLong_FromLong(interp->check_interval); } PyDoc_STRVAR(getcheckinterval_doc, @@ -1339,7 +1339,7 @@ Clear the internal type lookup cache."); static PyObject * sys_is_finalizing(PyObject* self, PyObject* args) { - return PyBool_FromLong(_Py_Finalizing != NULL); + return PyBool_FromLong(_Py_IS_FINALIZING()); } PyDoc_STRVAR(is_finalizing_doc, @@ -1479,11 +1479,24 @@ list_builtin_module_names(void) return list; } -static PyObject *warnoptions = NULL; +static PyObject * +get_warnoptions(void) +{ + PyObject *warnoptions = PyThreadState_GET()->interp->warnoptions; + if (warnoptions == NULL || !PyList_Check(warnoptions)) { + Py_XDECREF(warnoptions); + warnoptions = PyList_New(0); + if (warnoptions == NULL) + return NULL; + PyThreadState_GET()->interp->warnoptions = warnoptions; + } + return warnoptions; +} void PySys_ResetWarnOptions(void) { + PyObject *warnoptions = PyThreadState_GET()->interp->warnoptions; if (warnoptions == NULL || !PyList_Check(warnoptions)) return; PyList_SetSlice(warnoptions, 0, PyList_GET_SIZE(warnoptions), NULL); @@ -1492,12 +1505,9 @@ PySys_ResetWarnOptions(void) void PySys_AddWarnOptionUnicode(PyObject *unicode) { - if (warnoptions == NULL || !PyList_Check(warnoptions)) { - Py_XDECREF(warnoptions); - warnoptions = PyList_New(0); - if (warnoptions == NULL) - return; - } + PyObject *warnoptions = get_warnoptions(); + if (warnoptions == NULL) + return; PyList_Append(warnoptions, unicode); } @@ -1515,17 +1525,20 @@ PySys_AddWarnOption(const wchar_t *s) int PySys_HasWarnOptions(void) { + PyObject *warnoptions = PyThreadState_GET()->interp->warnoptions; return (warnoptions != NULL && (PyList_Size(warnoptions) > 0)) ? 1 : 0; } -static PyObject *xoptions = NULL; - static PyObject * get_xoptions(void) { + PyObject *xoptions = PyThreadState_GET()->interp->xoptions; if (xoptions == NULL || !PyDict_Check(xoptions)) { Py_XDECREF(xoptions); xoptions = PyDict_New(); + if (xoptions == NULL) + return NULL; + PyThreadState_GET()->interp->xoptions = xoptions; } return xoptions; } @@ -2130,17 +2143,15 @@ _PySys_EndInit(PyObject *sysdict) SET_SYS_FROM_STRING_INT_RESULT("base_exec_prefix", PyUnicode_FromWideChar(Py_GetExecPrefix(), -1)); - if (warnoptions == NULL) { - warnoptions = PyList_New(0); - if (warnoptions == NULL) - return -1; - } - - SET_SYS_FROM_STRING_INT_RESULT("warnoptions", - PyList_GetSlice(warnoptions, - 0, Py_SIZE(warnoptions))); + PyObject *warnoptions = get_warnoptions(); + if (warnoptions == NULL) + return -1; + SET_SYS_FROM_STRING_BORROW_INT_RESULT("warnoptions", warnoptions); - SET_SYS_FROM_STRING_BORROW_INT_RESULT("_xoptions", get_xoptions()); + PyObject *xoptions = get_xoptions(); + if (xoptions == NULL) + return -1; + SET_SYS_FROM_STRING_BORROW_INT_RESULT("_xoptions", xoptions); if (PyErr_Occurred()) return -1; |