gh-108512: Add and use new replacements for PySys_GetObject() (GH-111035)

Add functions PySys_GetAttr(), PySys_GetAttrString(),
PySys_GetOptionalAttr() and PySys_GetOptionalAttrString().
This commit is contained in:
Serhiy Storchaka 2025-05-28 20:11:09 +03:00 committed by GitHub
parent b265a7ddeb
commit bac3fcba5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
32 changed files with 287 additions and 93 deletions

View file

@ -14,7 +14,6 @@
#include "pycore_pyerrors.h" // _PyErr_NoMemory()
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_pythonrun.h" // _Py_SourceAsString()
#include "pycore_sysmodule.h" // _PySys_GetRequiredAttr()
#include "pycore_tuple.h" // _PyTuple_FromArray()
#include "pycore_cell.h" // PyCell_GetRef()
@ -465,7 +464,7 @@ builtin_callable(PyObject *module, PyObject *obj)
static PyObject *
builtin_breakpoint(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *keywords)
{
PyObject *hook = _PySys_GetRequiredAttrString("breakpointhook");
PyObject *hook = PySys_GetAttrString("breakpointhook");
if (hook == NULL) {
return NULL;
}
@ -2164,7 +2163,7 @@ builtin_print_impl(PyObject *module, PyObject * const *args,
int i, err;
if (file == Py_None) {
file = _PySys_GetRequiredAttr(&_Py_ID(stdout));
file = PySys_GetAttr(&_Py_ID(stdout));
if (file == NULL) {
return NULL;
}
@ -2270,7 +2269,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt)
int tty;
/* Check that stdin/out/err are intact */
fin = _PySys_GetRequiredAttr(&_Py_ID(stdin));
fin = PySys_GetAttr(&_Py_ID(stdin));
if (fin == NULL) {
goto error;
}
@ -2278,7 +2277,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt)
PyErr_SetString(PyExc_RuntimeError, "lost sys.stdin");
goto error;
}
fout = _PySys_GetRequiredAttr(&_Py_ID(stdout));
fout = PySys_GetAttr(&_Py_ID(stdout));
if (fout == NULL) {
goto error;
}
@ -2286,7 +2285,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt)
PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
goto error;
}
ferr = _PySys_GetRequiredAttr(&_Py_ID(stderr));
ferr = PySys_GetAttr(&_Py_ID(stderr));
if (ferr == NULL) {
goto error;
}