mirror of
https://github.com/python/cpython.git
synced 2025-10-07 07:31:46 +00:00
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.
This commit is contained in:
parent
2ebd3813af
commit
caba55b3b7
22 changed files with 107 additions and 93 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue