diff options
author | Mark Shannon <mark@hotpy.org> | 2021-01-29 13:24:55 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-29 13:24:55 +0000 |
commit | d6c33fbd346765c6a8654dccacb2338006bf2b47 (patch) | |
tree | 857d7b70431dc74ca9b68e5ce1d56953f19f8d77 /Include | |
parent | bpo-23544: Disable IDLE Stack Viewer when running user code (GH-17163) (diff) | |
download | cpython-d6c33fbd346765c6a8654dccacb2338006bf2b47.tar.gz cpython-d6c33fbd346765c6a8654dccacb2338006bf2b47.tar.bz2 cpython-d6c33fbd346765c6a8654dccacb2338006bf2b47.zip |
bpo-42990: Introduce 'frame constructor' struct to simplify API for PyEval_CodeEval and friends (GH-24298)
* Introduce 'frame constructor' to simplify API for frame creation
* Embed struct using a macro to conform to PEP 7
Diffstat (limited to 'Include')
-rw-r--r-- | Include/cpython/frameobject.h | 4 | ||||
-rw-r--r-- | Include/funcobject.h | 26 | ||||
-rw-r--r-- | Include/internal/pycore_ceval.h | 7 |
3 files changed, 24 insertions, 13 deletions
diff --git a/Include/cpython/frameobject.h b/Include/cpython/frameobject.h index 28170615a04..f162e2465f3 100644 --- a/Include/cpython/frameobject.h +++ b/Include/cpython/frameobject.h @@ -72,7 +72,7 @@ PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *, /* only internal use */ PyFrameObject* _PyFrame_New_NoTrack(PyThreadState *, PyCodeObject *, - PyObject *, PyObject *); + PyObject *, PyObject *, PyObject *); /* The rest of the interface is specific for frame objects */ @@ -92,3 +92,5 @@ PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *); PyAPI_FUNC(void) _PyFrame_DebugMallocStats(FILE *out); PyAPI_FUNC(PyFrameObject *) PyFrame_GetBack(PyFrameObject *frame); + +PyObject *_PyEval_BuiltinsFromGlobals(PyObject *globals); diff --git a/Include/funcobject.h b/Include/funcobject.h index c5cc9d261a3..d7acd18c651 100644 --- a/Include/funcobject.h +++ b/Include/funcobject.h @@ -7,6 +7,21 @@ extern "C" { #endif + +#define COMMON_FIELDS(PREFIX) \ + PyObject *PREFIX ## globals; \ + PyObject *PREFIX ## builtins; \ + PyObject *PREFIX ## name; \ + PyObject *PREFIX ## qualname; \ + PyObject *PREFIX ## code; /* A code object, the __code__ attribute */ \ + PyObject *PREFIX ## defaults; /* NULL or a tuple */ \ + PyObject *PREFIX ## kwdefaults; /* NULL or a dict */ \ + PyObject *PREFIX ## closure; /* NULL or a tuple of cell objects */ + +typedef struct { + COMMON_FIELDS(fc_) +} PyFrameConstructor; + /* Function objects and code objects should not be confused with each other: * * Function objects are created by the execution of the 'def' statement. @@ -20,18 +35,12 @@ extern "C" { typedef struct { PyObject_HEAD - PyObject *func_code; /* A code object, the __code__ attribute */ - PyObject *func_globals; /* A dictionary (other mappings won't do) */ - PyObject *func_defaults; /* NULL or a tuple */ - PyObject *func_kwdefaults; /* NULL or a dict */ - PyObject *func_closure; /* NULL or a tuple of cell objects */ + COMMON_FIELDS(func_) PyObject *func_doc; /* The __doc__ attribute, can be anything */ - PyObject *func_name; /* The __name__ attribute, a string object */ PyObject *func_dict; /* The __dict__ attribute, a dict or NULL */ PyObject *func_weakreflist; /* List of weak references */ PyObject *func_module; /* The __module__ attribute, can be anything */ PyObject *func_annotations; /* Annotations, a dict or NULL */ - PyObject *func_qualname; /* The qualified name */ vectorcallfunc vectorcall; /* Invariant: @@ -84,6 +93,9 @@ PyAPI_FUNC(PyObject *) _PyFunction_Vectorcall( #define PyFunction_GET_ANNOTATIONS(func) \ (((PyFunctionObject *)func) -> func_annotations) +#define PyFunction_AS_FRAME_CONSTRUCTOR(func) \ + ((PyFrameConstructor *)&((PyFunctionObject *)(func))->func_globals) + /* The classmethod and staticmethod types lives here, too */ PyAPI_DATA(PyTypeObject) PyClassMethod_Type; PyAPI_DATA(PyTypeObject) PyStaticMethod_Type; diff --git a/Include/internal/pycore_ceval.h b/Include/internal/pycore_ceval.h index 38fd681f20c..a9da8b8f450 100644 --- a/Include/internal/pycore_ceval.h +++ b/Include/internal/pycore_ceval.h @@ -42,13 +42,10 @@ _PyEval_EvalFrame(PyThreadState *tstate, PyFrameObject *f, int throwflag) extern PyObject *_PyEval_EvalCode( PyThreadState *tstate, - PyObject *_co, PyObject *globals, PyObject *locals, + PyFrameConstructor *desc, PyObject *locals, PyObject *const *args, Py_ssize_t argcount, PyObject *const *kwnames, PyObject *const *kwargs, - Py_ssize_t kwcount, int kwstep, - PyObject *const *defs, Py_ssize_t defcount, - PyObject *kwdefs, PyObject *closure, - PyObject *name, PyObject *qualname); + Py_ssize_t kwcount, int kwstep); #ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS extern int _PyEval_ThreadsInitialized(PyInterpreterState *interp); |