mirror of
https://github.com/python/cpython.git
synced 2025-07-27 21:24:32 +00:00

Currently, if an arg value escapes (into the closure for an inner function) we end up allocating two indices in the fast locals even though only one gets used. Additionally, using the lower index would be better in some cases, such as with no-arg `super()`. To address this, we update the compiler to fix the offsets so each variable only gets one "fast local". As a consequence, now some cell offsets are interspersed with the locals (only when an arg escapes to an inner function). https://bugs.python.org/issue43693
38 lines
818 B
C
38 lines
818 B
C
#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 */
|