summaryrefslogtreecommitdiff
path: root/Include/internal/pycore_frame.h
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2021-05-21 10:57:35 +0100
committerGitHub <noreply@github.com>2021-05-21 10:57:35 +0100
commitb11a951f16f0603d98de24fee5c023df83ea552c (patch)
tree82e7807515db0e284d9ebc3b8c3ba6ff08699ea5 /Include/internal/pycore_frame.h
parentbe4dd7fcd93ed29d362c4bbcc48151bc619d6595 (diff)
downloadcpython-git-b11a951f16f0603d98de24fee5c023df83ea552c.tar.gz
bpo-44032: Move data stack to thread from FrameObject. (GH-26076)
* Remove 'zombie' frames. We won't need them once we are allocating fixed-size frames. * Add co_nlocalplus field to code object to avoid recomputing size of locals + frees + cells. * Move locals, cells and freevars out of frame object into separate memory buffer. * Use per-threadstate allocated memory chunks for local variables. * Move globals and builtins from frame object to per-thread stack. * Move (slow) locals frame object to per-thread stack. * Move internal frame functions to internal header.
Diffstat (limited to 'Include/internal/pycore_frame.h')
-rw-r--r--Include/internal/pycore_frame.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h
new file mode 100644
index 0000000000..44f58fb694
--- /dev/null
+++ b/Include/internal/pycore_frame.h
@@ -0,0 +1,38 @@
+#ifndef Py_INTERNAL_FRAME_H
+#define Py_INTERNAL_FRAME_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+enum {
+ FRAME_SPECIALS_GLOBALS_OFFSET = 0,
+ FRAME_SPECIALS_BUILTINS_OFFSET = 1,
+ FRAME_SPECIALS_LOCALS_OFFSET = 2,
+ FRAME_SPECIALS_SIZE = 3
+};
+
+static inline PyObject **
+_PyFrame_Specials(PyFrameObject *f) {
+ return &f->f_valuestack[-FRAME_SPECIALS_SIZE];
+}
+
+/* Returns a *borrowed* reference. */
+static inline PyObject *
+_PyFrame_GetGlobals(PyFrameObject *f)
+{
+ return _PyFrame_Specials(f)[FRAME_SPECIALS_GLOBALS_OFFSET];
+}
+
+/* Returns a *borrowed* reference. */
+static inline PyObject *
+_PyFrame_GetBuiltins(PyFrameObject *f)
+{
+ return _PyFrame_Specials(f)[FRAME_SPECIALS_BUILTINS_OFFSET];
+}
+
+int _PyFrame_TakeLocals(PyFrameObject *f);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_INTERNAL_FRAME_H */