Skip to content

Commit 37a53fb

Browse files
authored
pythongh-91502: Add a new API to check if a frame is an entry frame (pythonGH-91503)
1 parent 54f67ad commit 37a53fb

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

Include/cpython/frameobject.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *,
1919

2020
PyAPI_FUNC(void) PyFrame_LocalsToFast(PyFrameObject *, int);
2121

22+
/* -- Caveat emptor --
23+
* The concept of entry frames is an implementation detail of the CPython
24+
* interpreter. This API is considered unstable and is provided for the
25+
* convenience of debuggers, profilers and state-inspecting tools. Notice that
26+
* this API can be changed in future minor versions if the underlying frame
27+
* mechanism change or the concept of an 'entry frame' or its semantics becomes
28+
* obsolete or outdated. */
29+
30+
PyAPI_FUNC(int) _PyFrame_IsEntryFrame(PyFrameObject *frame);
31+
2232
PyAPI_FUNC(int) PyFrame_FastToLocalsWithError(PyFrameObject *f);
2333
PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *);
2434

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add a new :c:func:`_PyFrame_IsEntryFrame` API function, to check if a
2+
:c:type:`PyFrameObject` is an entry frame. Patch by Pablo Galindo.

Objects/frameobject.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,14 @@ PyFrame_LocalsToFast(PyFrameObject *f, int clear)
11041104
}
11051105
}
11061106

1107+
1108+
int _PyFrame_IsEntryFrame(PyFrameObject *frame)
1109+
{
1110+
assert(frame != NULL);
1111+
return frame->f_frame->is_entry;
1112+
}
1113+
1114+
11071115
PyCodeObject *
11081116
PyFrame_GetCode(PyFrameObject *frame)
11091117
{

0 commit comments

Comments
 (0)