Skip to content

Commit 4e60017

Browse files
committed
Move internal frame functions to internal header.
1 parent 9204189 commit 4e60017

File tree

7 files changed

+42
-32
lines changed

7 files changed

+42
-32
lines changed

Include/cpython/frameobject.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ enum _framestate {
1919

2020
typedef signed char PyFrameState;
2121

22-
enum {
23-
FRAME_SPECIALS_GLOBALS_OFFSET = 0,
24-
FRAME_SPECIALS_BUILTINS_OFFSET = 1,
25-
FRAME_SPECIALS_LOCALS_OFFSET = 2,
26-
FRAME_SPECIALS_SIZE = 3
27-
};
28-
2922
struct _frame {
3023
PyObject_HEAD
3124
struct _frame *f_back; /* previous frame, or NULL */
@@ -82,8 +75,3 @@ PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *);
8275
PyAPI_FUNC(void) _PyFrame_DebugMallocStats(FILE *out);
8376

8477
PyAPI_FUNC(PyFrameObject *) PyFrame_GetBack(PyFrameObject *frame);
85-
86-
/** Internal -- Not to be used outside of the interpreter core */
87-
int _PyFrame_TakeLocals(PyFrameObject *f);
88-
PyObject *_PyFrame_GetGlobals(PyFrameObject *f);
89-
PyObject *_PyFrame_GetBuiltins(PyFrameObject *f);

Include/internal/pycore_frame.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifndef Py_INTERNAL_FRAME_H
2+
#define Py_INTERNAL_FRAME_H
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
enum {
8+
FRAME_SPECIALS_GLOBALS_OFFSET = 0,
9+
FRAME_SPECIALS_BUILTINS_OFFSET = 1,
10+
FRAME_SPECIALS_LOCALS_OFFSET = 2,
11+
FRAME_SPECIALS_SIZE = 3
12+
};
13+
14+
static inline PyObject **
15+
_PyFrame_Specials(PyFrameObject *f) {
16+
return &f->f_valuestack[-FRAME_SPECIALS_SIZE];
17+
}
18+
19+
/* Returns a *borrowed* reference. */
20+
static inline PyObject *
21+
_PyFrame_GetGlobals(PyFrameObject *f)
22+
{
23+
return _PyFrame_Specials(f)[FRAME_SPECIALS_GLOBALS_OFFSET];
24+
}
25+
26+
static inline PyObject *
27+
_PyFrame_GetBuiltins(PyFrameObject *f)
28+
{
29+
return _PyFrame_Specials(f)[FRAME_SPECIALS_BUILTINS_OFFSET];
30+
}
31+
32+
int _PyFrame_TakeLocals(PyFrameObject *f);
33+
34+
#ifdef __cplusplus
35+
}
36+
#endif
37+
#endif /* !Py_INTERNAL_FRAME_H */

Objects/frameobject.c

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
77

88
#include "frameobject.h" // PyFrameObject
9+
#include "pycore_frame.h"
910
#include "opcode.h" // EXTENDED_ARG
1011
#include "structmember.h" // PyMemberDef
1112

@@ -25,11 +26,6 @@ get_frame_state(void)
2526
return &interp->frame;
2627
}
2728

28-
static inline PyObject **
29-
_PyFrame_Specials(PyFrameObject *f) {
30-
return &f->f_valuestack[-FRAME_SPECIALS_SIZE];
31-
}
32-
3329

3430
static PyObject *
3531
frame_getlocals(PyFrameObject *f, void *closure)
@@ -74,20 +70,6 @@ frame_getlasti(PyFrameObject *f, void *closure)
7470
return PyLong_FromLong(f->f_lasti*2);
7571
}
7672

77-
/* Returns a *borrowed* reference. Not part of the API. */
78-
PyObject *
79-
_PyFrame_GetGlobals(PyFrameObject *f)
80-
{
81-
return _PyFrame_Specials(f)[FRAME_SPECIALS_GLOBALS_OFFSET];
82-
}
83-
84-
/* Returns a *borrowed* reference. Not part of the API. */
85-
PyObject *
86-
_PyFrame_GetBuiltins(PyFrameObject *f)
87-
{
88-
return _PyFrame_Specials(f)[FRAME_SPECIALS_BUILTINS_OFFSET];
89-
}
90-
9173
static PyObject *
9274
frame_getglobals(PyFrameObject *f, void *closure)
9375
{

Python/_warnings.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "pycore_pyerrors.h"
66
#include "pycore_pystate.h" // _PyThreadState_GET()
77
#include "frameobject.h" // PyFrame_GetBack()
8+
#include "pycore_frame.h"
89
#include "clinic/_warnings.c.h"
910

1011
#define MODULE_NAME "_warnings"

Python/ceval.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "code.h"
2727
#include "dictobject.h"
2828
#include "frameobject.h"
29+
#include "pycore_frame.h"
2930
#include "opcode.h"
3031
#include "pydtrace.h"
3132
#include "setobject.h"

Python/pystate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ new_threadstate(PyInterpreterState *interp, int init)
680680
PyMem_RawFree(tstate);
681681
return NULL;
682682
}
683-
/* If top points to entry 0, then _PyThreadState_PopLocals willl try to pop this chunk */
683+
/* If top points to entry 0, then _PyThreadState_PopLocals will try to pop this chunk */
684684
tstate->datastack_top = &tstate->datastack_chunk->data[1];
685685
tstate->datastack_limit = (PyObject **)(((char *)tstate->datastack_chunk) + DATA_STACK_CHUNK_SIZE);
686686

Python/suggestions.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "Python.h"
22
#include "frameobject.h"
3+
#include "pycore_frame.h"
34

45
#include "pycore_pyerrors.h"
56

0 commit comments

Comments
 (0)