@@ -258,10 +258,57 @@ These are utility functions that make functionality from the :mod:`sys` module
258258accessible to C code. They all work with the current interpreter thread's
259259:mod:`sys` module's dict, which is contained in the internal thread state structure.
260260
261+ .. c:function:: PyObject *PySys_GetAttr(PyObject *name)
262+
263+ Get the attribute *name * of the :mod: `sys ` module.
264+ Return a :term: `strong reference `.
265+ Raise :exc: `RuntimeError ` and return ``NULL `` if it does not exist or
266+ if the :mod: `sys ` module cannot be found.
267+
268+ If the non-existing object should not be treated as a failure, you can use
269+ :c:func: `PySys_GetOptionalAttr ` instead.
270+
271+ .. versionadded :: next
272+
273+ .. c :function :: PyObject *PySys_GetAttrString (const char *name)
274+
275+ This is the same as :c:func: `PySys_GetAttr `, but *name * is
276+ specified as a :c:expr: `const char* ` UTF-8 encoded bytes string,
277+ rather than a :c:expr: `PyObject* `.
278+
279+ If the non-existing object should not be treated as a failure, you can use
280+ :c:func: `PySys_GetOptionalAttrString ` instead.
281+
282+ .. versionadded :: next
283+
284+ .. c :function :: int PySys_GetOptionalAttr (PyObject *name, PyObject **result)
285+
286+ Variant of :c:func: `PySys_GetAttr ` which doesn't raise
287+ exception if the object does not exist.
288+
289+ * Set *\* result * to a new :term: `strong reference ` to the object and
290+ return ``1 `` if the object exists.
291+ * Set *\* result * to ``NULL `` and return ``0 `` without setting an exception
292+ if the object does not exist.
293+ * Set an exception, set *\* result * to ``NULL ``, and return ``-1 ``,
294+ if an error occurred.
295+
296+ .. versionadded :: next
297+
298+ .. c :function :: int PySys_GetOptionalAttrString (const char *name, PyObject **result)
299+
300+ This is the same as :c:func: `PySys_GetOptionalAttr `, but *name * is
301+ specified as a :c:expr: `const char* ` UTF-8 encoded bytes string,
302+ rather than a :c:expr: `PyObject* `.
303+
304+ .. versionadded :: next
305+
261306.. c :function :: PyObject *PySys_GetObject (const char *name)
262307
263- Return the object *name * from the :mod: `sys ` module or ``NULL `` if it does
264- not exist, without setting an exception.
308+ Similar to :c:func: `PySys_GetAttrString `, but return a :term: `borrowed
309+ reference ` and return ``NULL `` *without * setting exception on failure.
310+
311+ Preserves exception that was set before the call.
265312
266313.. c :function :: int PySys_SetObject (const char *name, PyObject *v)
267314
0 commit comments