Skip to content

Commit

Permalink
Restore _PySys_GetAttr().
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka committed Feb 25, 2025
1 parent 1e4b133 commit 2d895cb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions Include/internal/pycore_sysmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif

PyAPI_FUNC(PyObject *) _PySys_GetAttr(PyThreadState *, PyObject *); /* unused */
PyAPI_FUNC(int) _PySys_GetOptionalAttr(PyObject *, PyObject **);
PyAPI_FUNC(int) _PySys_GetOptionalAttrString(const char *, PyObject **);
PyAPI_FUNC(PyObject *) _PySys_GetRequiredAttr(PyObject *);
Expand Down
15 changes: 15 additions & 0 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ module sys


PyObject *
_PySys_GetAttr(PyThreadState *tstate, PyObject *name)
{
PyObject *sd = tstate->interp->sysdict;
if (sd == NULL) {
return NULL;
}
PyObject *exc = _PyErr_GetRaisedException(tstate);
/* XXX Suppress a new exception if it was raised and restore
* the old one. */
PyObject *value = _PyDict_GetItemWithError(sd, name);
_PyErr_SetRaisedException(tstate, exc);
return value;
}

PyObject *
_PySys_GetRequiredAttr(PyObject *name)
{
if (!PyUnicode_Check(name)) {
Expand Down

0 comments on commit 2d895cb

Please sign in to comment.