Skip to content

Commit e1da7df

Browse files
committed
Make _PyFrame_Copy inline for the JIT
1 parent 5fff5e5 commit e1da7df

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

Include/internal/pycore_frame.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,15 @@ _PyFrame_NumSlotsForCodeObject(PyCodeObject *code)
110110
return code->co_framesize - FRAME_SPECIALS_SIZE;
111111
}
112112

113-
void _PyFrame_Copy(_PyInterpreterFrame *src, _PyInterpreterFrame *dest);
113+
static inline void _PyFrame_Copy(_PyInterpreterFrame *src, _PyInterpreterFrame *dest)
114+
{
115+
assert(src->stacktop >= _PyFrame_GetCode(src)->co_nlocalsplus);
116+
Py_ssize_t size = ((char*)&src->localsplus[src->stacktop]) - (char *)src;
117+
memcpy(dest, src, size);
118+
// Don't leave a dangling pointer to the old frame when creating generators
119+
// and coroutines:
120+
dest->previous = NULL;
121+
}
114122

115123
/* Consumes reference to func and locals.
116124
Does not initialize frame->previous, which happens

Python/frame.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,6 @@ _PyFrame_MakeAndSetFrameObject(_PyInterpreterFrame *frame)
5353
return f;
5454
}
5555

56-
void
57-
_PyFrame_Copy(_PyInterpreterFrame *src, _PyInterpreterFrame *dest)
58-
{
59-
assert(src->stacktop >= _PyFrame_GetCode(src)->co_nlocalsplus);
60-
Py_ssize_t size = ((char*)&src->localsplus[src->stacktop]) - (char *)src;
61-
memcpy(dest, src, size);
62-
// Don't leave a dangling pointer to the old frame when creating generators
63-
// and coroutines:
64-
dest->previous = NULL;
65-
}
66-
67-
6856
static void
6957
take_ownership(PyFrameObject *f, _PyInterpreterFrame *frame)
7058
{

0 commit comments

Comments
 (0)