summaryrefslogtreecommitdiff
path: root/Python/sysmodule.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-08-03 15:33:52 +0200
committerGitHub <noreply@github.com>2018-08-03 15:33:52 +0200
commitcaba55b3b735405b280273f7d99866a046c18281 (patch)
tree3a98ac383b1fbab272158933255fb1a14107ebf6 /Python/sysmodule.c
parent2ebd3813af9172fe1f9b2f6004edf6f1e1e5d9f1 (diff)
downloadcpython-git-caba55b3b735405b280273f7d99866a046c18281.tar.gz
bpo-34301: Add _PyInterpreterState_Get() helper function (GH-8592)
sys_setcheckinterval() now uses a local variable to parse arguments, before writing into interp->check_interval.
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r--Python/sysmodule.c58
1 files changed, 31 insertions, 27 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index b6c816e9f6..177b830762 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -56,51 +56,55 @@ _Py_IDENTIFIER(write);
PyObject *
_PySys_GetObjectId(_Py_Identifier *key)
{
- PyThreadState *tstate = PyThreadState_GET();
- PyObject *sd = tstate->interp->sysdict;
- if (sd == NULL)
+ PyObject *sd = _PyInterpreterState_GET_UNSAFE()->sysdict;
+ if (sd == NULL) {
return NULL;
+ }
return _PyDict_GetItemId(sd, key);
}
PyObject *
PySys_GetObject(const char *name)
{
- PyThreadState *tstate = PyThreadState_GET();
- PyObject *sd = tstate->interp->sysdict;
- if (sd == NULL)
+ PyObject *sd = _PyInterpreterState_GET_UNSAFE()->sysdict;
+ if (sd == NULL) {
return NULL;
+ }
return PyDict_GetItemString(sd, name);
}
int
_PySys_SetObjectId(_Py_Identifier *key, PyObject *v)
{
- PyThreadState *tstate = PyThreadState_GET();
- PyObject *sd = tstate->interp->sysdict;
+ PyObject *sd = _PyInterpreterState_GET_UNSAFE()->sysdict;
if (v == NULL) {
- if (_PyDict_GetItemId(sd, key) == NULL)
+ if (_PyDict_GetItemId(sd, key) == NULL) {
return 0;
- else
+ }
+ else {
return _PyDict_DelItemId(sd, key);
+ }
}
- else
+ else {
return _PyDict_SetItemId(sd, key, v);
+ }
}
int
PySys_SetObject(const char *name, PyObject *v)
{
- PyThreadState *tstate = PyThreadState_GET();
- PyObject *sd = tstate->interp->sysdict;
+ PyObject *sd = _PyInterpreterState_GET_UNSAFE()->sysdict;
if (v == NULL) {
- if (PyDict_GetItemString(sd, name) == NULL)
+ if (PyDict_GetItemString(sd, name) == NULL) {
return 0;
- else
+ }
+ else {
return PyDict_DelItemString(sd, name);
+ }
}
- else
+ else {
return PyDict_SetItemString(sd, name, v);
+ }
}
static PyObject *
@@ -626,9 +630,13 @@ 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))
+
+ int check_interval;
+ if (!PyArg_ParseTuple(args, "i:setcheckinterval", &check_interval))
return NULL;
+
+ PyInterpreterState *interp = _PyInterpreterState_Get();
+ interp->check_interval = check_interval;
Py_RETURN_NONE;
}
@@ -647,7 +655,7 @@ sys_getcheckinterval(PyObject *self, PyObject *args)
"are deprecated. Use sys.getswitchinterval() "
"instead.", 1) < 0)
return NULL;
- PyInterpreterState *interp = PyThreadState_GET()->interp;
+ PyInterpreterState *interp = _PyInterpreterState_Get();
return PyLong_FromLong(interp->check_interval);
}
@@ -1154,12 +1162,10 @@ static PyObject *
sys_setdlopenflags(PyObject *self, PyObject *args)
{
int new_val;
- PyThreadState *tstate = PyThreadState_GET();
if (!PyArg_ParseTuple(args, "i:setdlopenflags", &new_val))
return NULL;
- if (!tstate)
- return NULL;
- tstate->interp->dlopenflags = new_val;
+ PyInterpreterState *interp = _PyInterpreterState_Get();
+ interp->dlopenflags = new_val;
Py_RETURN_NONE;
}
@@ -1176,10 +1182,8 @@ can be found in the os module (RTLD_xxx constants, e.g. os.RTLD_LAZY).");
static PyObject *
sys_getdlopenflags(PyObject *self, PyObject *args)
{
- PyThreadState *tstate = PyThreadState_GET();
- if (!tstate)
- return NULL;
- return PyLong_FromLong(tstate->interp->dlopenflags);
+ PyInterpreterState *interp = _PyInterpreterState_Get();
+ return PyLong_FromLong(interp->dlopenflags);
}
PyDoc_STRVAR(getdlopenflags_doc,