mirror of
https://github.com/python/cpython.git
synced 2025-10-17 04:08:28 +00:00
gh-130163: Fix crashes related to PySys_GetObject() (GH-130503)
The use of PySys_GetObject() and _PySys_GetAttr(), which return a borrowed reference, has been replaced by using one of the following functions, which return a strong reference and distinguish a missing attribute from an error: _PySys_GetOptionalAttr(), _PySys_GetOptionalAttrString(), _PySys_GetRequiredAttr(), and _PySys_GetRequiredAttrString().
This commit is contained in:
parent
2dad1e08ec
commit
0ef4ffeefd
23 changed files with 513 additions and 213 deletions
|
@ -9,7 +9,7 @@
|
|||
#include "pycore_intrinsics.h" // INTRINSIC_PRINT
|
||||
#include "pycore_pyerrors.h" // _PyErr_SetString()
|
||||
#include "pycore_runtime.h" // _Py_ID()
|
||||
#include "pycore_sysmodule.h" // _PySys_GetAttr()
|
||||
#include "pycore_sysmodule.h" // _PySys_GetRequiredAttr()
|
||||
#include "pycore_typevarobject.h" // _Py_make_typevar()
|
||||
|
||||
|
||||
|
@ -23,16 +23,16 @@ no_intrinsic1(PyThreadState* tstate, PyObject *unused)
|
|||
}
|
||||
|
||||
static PyObject *
|
||||
print_expr(PyThreadState* tstate, PyObject *value)
|
||||
print_expr(PyThreadState* Py_UNUSED(ignored), PyObject *value)
|
||||
{
|
||||
PyObject *hook = _PySys_GetAttr(tstate, &_Py_ID(displayhook));
|
||||
PyObject *hook = _PySys_GetRequiredAttr(&_Py_ID(displayhook));
|
||||
// Can't use ERROR_IF here.
|
||||
if (hook == NULL) {
|
||||
_PyErr_SetString(tstate, PyExc_RuntimeError,
|
||||
"lost sys.displayhook");
|
||||
return NULL;
|
||||
}
|
||||
return PyObject_CallOneArg(hook, value);
|
||||
PyObject *res = PyObject_CallOneArg(hook, value);
|
||||
Py_DECREF(hook);
|
||||
return res;
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue