Implement the frame evaluation API aspect of PEP 523. · pythoncapi/cpython@3cebf93 · GitHub
Skip to content

Commit 3cebf93

Browse files
committed
Implement the frame evaluation API aspect of PEP 523.
1 parent 625cb37 commit 3cebf93

6 files changed

Lines changed: 47 additions & 3 deletions

File tree

Doc/whatsnew/3.6.rst

Lines changed: 28 additions & 0 deletions

Include/ceval.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ PyAPI_FUNC(const char *) PyEval_GetFuncDesc(PyObject *);
119119
PyAPI_FUNC(PyObject *) PyEval_GetCallStats(PyObject *);
120120
PyAPI_FUNC(PyObject *) PyEval_EvalFrame(struct _frame *);
121121
PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(struct _frame *f, int exc);
122+
#ifndef Py_LIMITED_API
123+
PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(struct _frame *f, int exc);
124+
#endif
122125

123126
/* Interface for threads.
124127

Include/pystate.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ extern "C" {
1212

1313
struct _ts; /* Forward */
1414
struct _is; /* Forward */
15+
struct _frame; /* Forward declaration for PyFrameObject. */
1516

1617
#ifdef Py_LIMITED_API
1718
typedef struct _is PyInterpreterState;
1819
#else
20+
typedef PyObject* (*_PyFrameEvalFunction)(struct _frame *, int);
21+
1922
typedef struct _is {
2023

2124
struct _is *next;
@@ -42,14 +45,14 @@ typedef struct _is {
4245

4346
PyObject *builtins_copy;
4447
PyObject *import_func;
48+
/* Initialized to PyEval_EvalFrameDefault(). */
49+
_PyFrameEvalFunction eval_frame;
4550
} PyInterpreterState;
4651
#endif
4752

4853

4954
/* State unique per thread */
5055

51-
struct _frame; /* Avoid including frameobject.h */
52-
5356
#ifndef Py_LIMITED_API
5457
/* Py_tracefunc return -1 when raising an exception, or 0 for success. */
5558
typedef int (*Py_tracefunc)(PyObject *, struct _frame *, int, PyObject *);

Misc/NEWS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ Core and Builtins
1717
restriction: in beta 2, backslashes will only be disallowed inside
1818
the braces (where the expressions are). This is a breaking change
1919
from the 3.6 alpha releases.
20-
20+
21+
- Implement the frame evaluation part of PEP 523.
22+
2123
- Issue #27870: A left shift of zero by a large integer no longer attempts
2224
to allocate large amounts of memory.
2325

Python/ceval.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,13 @@ PyEval_EvalFrame(PyFrameObject *f) {
796796

797797
PyObject *
798798
PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
799+
{
800+
PyThreadState *tstate = PyThreadState_GET();
801+
return tstate->interp->eval_frame(f, throwflag);
802+
}
803+
804+
PyObject *
805+
_PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
799806
{
800807
#ifdef DXPAIRS
801808
int lastopcode = 0;

Python/pystate.c

Lines changed: 1 addition & 0 deletions

0 commit comments

Comments
 (0)