summaryrefslogtreecommitdiff
path: root/Python/sysmodule.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2017-09-05 21:43:08 -0700
committerGitHub <noreply@github.com>2017-09-05 21:43:08 -0700
commit05351c1bd8b70d1878527762174cdaaba3572395 (patch)
treee97ef4ba0ae7ffe5bd2c8969199616bffbbc4d6f /Python/sysmodule.c
parent833860615bedfd2484ac0623d6f01ff0578ba09f (diff)
downloadcpython-git-05351c1bd8b70d1878527762174cdaaba3572395.tar.gz
Revert "bpo-30860: Consolidate stateful runtime globals." (#3379)
Windows buildbots started failing due to include-related errors.
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r--Python/sysmodule.c59
1 files changed, 24 insertions, 35 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 080c541c6d..852babbed7 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -519,6 +519,8 @@ 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)
{
@@ -527,8 +529,7 @@ sys_setcheckinterval(PyObject *self, PyObject *args)
"are deprecated. Use sys.setswitchinterval() "
"instead.", 1) < 0)
return NULL;
- PyInterpreterState *interp = PyThreadState_GET()->interp;
- if (!PyArg_ParseTuple(args, "i:setcheckinterval", &interp->check_interval))
+ if (!PyArg_ParseTuple(args, "i:setcheckinterval", &_check_interval))
return NULL;
Py_RETURN_NONE;
}
@@ -548,8 +549,7 @@ sys_getcheckinterval(PyObject *self, PyObject *args)
"are deprecated. Use sys.getswitchinterval() "
"instead.", 1) < 0)
return NULL;
- PyInterpreterState *interp = PyThreadState_GET()->interp;
- return PyLong_FromLong(interp->check_interval);
+ return PyLong_FromLong(_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_IS_FINALIZING());
+ return PyBool_FromLong(_Py_Finalizing != NULL);
}
PyDoc_STRVAR(is_finalizing_doc,
@@ -1479,24 +1479,11 @@ list_builtin_module_names(void)
return list;
}
-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;
-}
+static PyObject *warnoptions = NULL;
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);
@@ -1505,9 +1492,12 @@ PySys_ResetWarnOptions(void)
void
PySys_AddWarnOptionUnicode(PyObject *unicode)
{
- PyObject *warnoptions = get_warnoptions();
- if (warnoptions == NULL)
- return;
+ if (warnoptions == NULL || !PyList_Check(warnoptions)) {
+ Py_XDECREF(warnoptions);
+ warnoptions = PyList_New(0);
+ if (warnoptions == NULL)
+ return;
+ }
PyList_Append(warnoptions, unicode);
}
@@ -1525,20 +1515,17 @@ 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;
}
@@ -2143,15 +2130,17 @@ _PySys_EndInit(PyObject *sysdict)
SET_SYS_FROM_STRING_INT_RESULT("base_exec_prefix",
PyUnicode_FromWideChar(Py_GetExecPrefix(), -1));
- PyObject *warnoptions = get_warnoptions();
- if (warnoptions == NULL)
- return -1;
- SET_SYS_FROM_STRING_BORROW_INT_RESULT("warnoptions", warnoptions);
+ if (warnoptions == NULL) {
+ warnoptions = PyList_New(0);
+ if (warnoptions == NULL)
+ return -1;
+ }
- PyObject *xoptions = get_xoptions();
- if (xoptions == NULL)
- return -1;
- SET_SYS_FROM_STRING_BORROW_INT_RESULT("_xoptions", xoptions);
+ SET_SYS_FROM_STRING_INT_RESULT("warnoptions",
+ PyList_GetSlice(warnoptions,
+ 0, Py_SIZE(warnoptions)));
+
+ SET_SYS_FROM_STRING_BORROW_INT_RESULT("_xoptions", get_xoptions());
if (PyErr_Occurred())
return -1;