FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add PyEval_GetFrameBuiltins() by vstinner · Pull Request #200 · python/pythoncapi-compat · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .h  (1) .rst  (2) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
12 changes: 12 additions & 0 deletions docs/api.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,18 @@ Python 3.13

See `PyType_GetFullyQualifiedName() documentation <https://docs.python.org/dev/c-api/type.html#c.PyType_GetFullyQualifiedName>`__.

.. c:function:: PyObject* PyEval_GetFrameLocals(void)

See `PyEval_GetFrameLocals() documentation <https://docs.python.org/dev/c-api/reflection.html#c.PyEval_GetFrameLocals>`__.

.. c:function:: PyObject* PyEval_GetFrameGlobals(void)

See `PyEval_GetFrameGlobals() documentation <https://docs.python.org/dev/c-api/reflection.html#c.PyEval_GetFrameGlobals>`__.

.. c:function:: PyObject* PyEval_GetFrameBuiltins(void)

See `PyEval_GetFrameBuiltins() documentation <https://docs.python.org/dev/c-api/reflection.html#c.PyEval_GetFrameBuiltins>`__.

.. c:macro:: Py_BEGIN_CRITICAL_SECTION(op)
.. c:macro:: Py_END_CRITICAL_SECTION()
.. c:macro:: Py_BEGIN_CRITICAL_SECTION2(a, b)
Expand Down
6 changes: 6 additions & 0 deletions docs/changelog.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

* 2026-10-12: Add functions:

* ``PyEval_GetFrameBuiltins()``
* ``PyEval_GetFrameGlobals()``
* ``PyEval_GetFrameLocals()``

* 2026-10-11: Remove the ``upgrade_pythoncapi.py`` script.
* 2026-10-10: Add ``PyObject_GenericHash()`` and
``PyUnicodeWriter_WriteUCS4()`` functions. runtests.py now runs tests in
Expand Down
23 changes: 23 additions & 0 deletions pythoncapi_compat.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3132,6 +3132,29 @@ PyType_GetFullyQualifiedName(PyTypeObject *type)
#endif


// Python 3.13 added PyEval_GetFrameLocals(), PyEval_GetFrameGlobals() and
// PyEval_GetFrameBuiltins() (PEP 667).
#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 13)
static inline PyObject*
PyEval_GetFrameLocals(void)
{
return Py_XNewRef(PyEval_GetLocals());
}

static inline PyObject*
PyEval_GetFrameGlobals(void)
{
return Py_XNewRef(PyEval_GetGlobals());
}

static inline PyObject*
PyEval_GetFrameBuiltins(void)
{
return Py_XNewRef(PyEval_GetBuiltins());
}
#endif


#ifdef __cplusplus
}
#endif
Expand Down
29 changes: 29 additions & 0 deletions tests/test_pythoncapi_compat_cext.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2669,6 +2669,34 @@ test_type(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
}


static PyObject *
test_eval(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
{
// Test PyEval_GetFrameLocals()
PyObject *locals = PyEval_GetFrameLocals();
if (locals != NULL) {
assert(PyMapping_Check(locals));
Py_DECREF(locals);
}

// Test PyEval_GetFrameGlobals()
PyObject *globals = PyEval_GetFrameGlobals();
if (globals != NULL) {
assert(PyMapping_Check(globals));
Py_DECREF(globals);
}

// Test PyEval_GetFrameBuiltins()
PyObject *builtins = PyEval_GetFrameBuiltins();
if (builtins != NULL) {
assert(PyMapping_Check(builtins));
Py_DECREF(builtins);
}

Py_RETURN_NONE;
}


static struct PyMethodDef methods[] = {
{"test_object", test_object, METH_NOARGS, _Py_NULL},
{"test_py_is", test_py_is, METH_NOARGS, _Py_NULL},
Expand Down Expand Up @@ -2744,6 +2772,7 @@ static struct PyMethodDef methods[] = {
{"test_set_immortal", test_set_immortal, METH_NOARGS, _Py_NULL},
#endif
{"test_type", test_type, METH_NOARGS, _Py_NULL},
{"test_eval", test_eval, METH_NOARGS, _Py_NULL},
{_Py_NULL, _Py_NULL, 0, _Py_NULL}
};

Expand Down
Loading

Back | FazBrowse Home | New Git URL