bpo-45786: Allocate space for frame in frame object. (GH-29729) · python/cpython@6092957 · GitHub
Skip to content

Commit 6092957

Browse files
authored
bpo-45786: Allocate space for frame in frame object. (GH-29729)
1 parent 7431448 commit 6092957

12 files changed

Lines changed: 76 additions & 181 deletions

File tree

Include/cpython/frameobject.h

Lines changed: 4 additions & 2 deletions

Include/internal/pycore_frame.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ static inline void _PyFrame_StackPush(InterpreterFrame *f, PyObject *value) {
6969

7070
#define FRAME_SPECIALS_SIZE ((sizeof(InterpreterFrame)-1)/sizeof(PyObject *))
7171

72-
InterpreterFrame *
73-
_PyInterpreterFrame_HeapAlloc(PyFunctionObject *func, PyObject *locals);
72+
InterpreterFrame *_PyFrame_Copy(InterpreterFrame *frame);
7473

7574
static inline void
7675
_PyFrame_InitializeSpecials(
@@ -139,8 +138,8 @@ _PyFrame_GetFrameObject(InterpreterFrame *frame)
139138
* take should be set to 1 for heap allocated
140139
* frames like the ones in generators and coroutines.
141140
*/
142-
int
143-
_PyFrame_Clear(InterpreterFrame * frame, int take);
141+
void
142+
_PyFrame_Clear(InterpreterFrame * frame);
144143

145144
int
146145
_PyFrame_Traverse(InterpreterFrame *frame, visitproc visit, void *arg);

Include/internal/pycore_gc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ extern Py_ssize_t _PyGC_CollectNoFail(PyThreadState *tstate);
167167

168168

169169
// Functions to clear types free lists
170-
extern void _PyFrame_ClearFreeList(PyInterpreterState *interp);
171170
extern void _PyTuple_ClearFreeList(PyInterpreterState *interp);
172171
extern void _PyFloat_ClearFreeList(PyInterpreterState *interp);
173172
extern void _PyList_ClearFreeList(PyInterpreterState *interp);

Include/internal/pycore_interp.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ struct _Py_unicode_state {
9393
# define PyTuple_MAXFREELIST 1
9494
# define PyList_MAXFREELIST 0
9595
# define PyDict_MAXFREELIST 0
96-
# define PyFrame_MAXFREELIST 0
9796
# define _PyAsyncGen_MAXFREELIST 0
9897
# define PyContext_MAXFREELIST 0
9998
#endif
@@ -158,18 +157,6 @@ struct _Py_dict_state {
158157
#endif
159158
};
160159

161-
#ifndef PyFrame_MAXFREELIST
162-
# define PyFrame_MAXFREELIST 200
163-
#endif
164-
165-
struct _Py_frame_state {
166-
#if PyFrame_MAXFREELIST > 0
167-
PyFrameObject *free_list;
168-
/* number of frames currently in free_list */
169-
int numfree;
170-
#endif
171-
};
172-
173160
#ifndef _PyAsyncGen_MAXFREELIST
174161
# define _PyAsyncGen_MAXFREELIST 80
175162
#endif
@@ -332,7 +319,6 @@ struct _is {
332319
struct _Py_tuple_state tuple;
333320
struct _Py_list_state list;
334321
struct _Py_dict_state dict_state;
335-
struct _Py_frame_state frame;
336322
struct _Py_async_gen_state async_gen;
337323
struct _Py_context_state context;
338324
struct _Py_exc_state exc_state;

Lib/test/test_exceptions.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def check(self, src, lineno, offset, encoding='utf-8'):
209209
src = src.decode(encoding, 'replace')
210210
line = src.split('\n')[lineno-1]
211211
self.assertIn(line, cm.exception.text)
212-
212+
213213
def test_error_offset_continuation_characters(self):
214214
check = self.check
215215
check('"\\\n"(1 for c in I,\\\n\\', 2, 2)
@@ -1342,9 +1342,7 @@ def recurse(cnt):
13421342
"""
13431343
with SuppressCrashReport():
13441344
rc, out, err = script_helper.assert_python_failure("-c", code)
1345-
self.assertIn(b'Fatal Python error: _PyErr_NormalizeException: '
1346-
b'Cannot recover from MemoryErrors while '
1347-
b'normalizing exceptions.', err)
1345+
self.assertIn(b'MemoryError', err)
13481346

13491347
@cpython_only
13501348
def test_MemoryError(self):

Lib/test/test_sys.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,9 +1320,10 @@ class C(object): pass
13201320
# sys.floatinfo
13211321
check(sys.float_info, vsize('') + self.P * len(sys.float_info))
13221322
# frame
1323-
import inspect
1324-
x = inspect.currentframe()
1325-
check(x, size('3Pi3c'))
1323+
def func():
1324+
return sys._getframe()
1325+
x = func()
1326+
check(x, size('3Pi3c8P2iciP'))
13261327
# function
13271328
def func(): pass
13281329
check(func, size('14Pi'))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Allocate space for the interpreter frame in the frame object, to avoid an
2+
additional allocation when the frame object outlives the frame activation.

Modules/gcmodule.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,6 @@ delete_garbage(PyThreadState *tstate, GCState *gcstate,
10381038
static void
10391039
clear_freelists(PyInterpreterState *interp)
10401040
{
1041-
_PyFrame_ClearFreeList(interp);
10421041
_PyTuple_ClearFreeList(interp);
10431042
_PyFloat_ClearFreeList(interp);
10441043
_PyList_ClearFreeList(interp);

Objects/frameobject.c

Lines changed: 26 additions & 115 deletions

0 commit comments

Comments
 (0)