Skip to content

Commit 2bef8ea

Browse files
authored
GH-127705: Use _PyStackRefs in the default build. (GH-127875)
1 parent 7cc99a5 commit 2bef8ea

21 files changed

+667
-233
lines changed

Include/internal/pycore_ceval.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ _Py_eval_breaker_bit_is_set(PyThreadState *tstate, uintptr_t bit)
342342
void _Py_set_eval_breaker_bit_all(PyInterpreterState *interp, uintptr_t bit);
343343
void _Py_unset_eval_breaker_bit_all(PyInterpreterState *interp, uintptr_t bit);
344344

345-
PyAPI_FUNC(PyObject *) _PyFloat_FromDouble_ConsumeInputs(_PyStackRef left, _PyStackRef right, double value);
345+
PyAPI_FUNC(_PyStackRef) _PyFloat_FromDouble_ConsumeInputs(_PyStackRef left, _PyStackRef right, double value);
346346

347347
#ifdef __cplusplus
348348
}

Include/internal/pycore_frame.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,26 @@ _PyFrame_NumSlotsForCodeObject(PyCodeObject *code)
148148

149149
static inline void _PyFrame_Copy(_PyInterpreterFrame *src, _PyInterpreterFrame *dest)
150150
{
151-
*dest = *src;
151+
dest->f_executable = PyStackRef_MakeHeapSafe(src->f_executable);
152+
// Don't leave a dangling pointer to the old frame when creating generators
153+
// and coroutines:
154+
dest->previous = NULL;
155+
dest->f_funcobj = PyStackRef_MakeHeapSafe(src->f_funcobj);
156+
dest->f_globals = src->f_globals;
157+
dest->f_builtins = src->f_builtins;
158+
dest->f_locals = src->f_locals;
159+
dest->frame_obj = src->frame_obj;
160+
dest->instr_ptr = src->instr_ptr;
161+
#ifdef Py_GIL_DISABLED
162+
dest->tlbc_index = src->tlbc_index;
163+
#endif
152164
assert(src->stackpointer != NULL);
153165
int stacktop = (int)(src->stackpointer - src->localsplus);
154-
assert(stacktop >= _PyFrame_GetCode(src)->co_nlocalsplus);
166+
assert(stacktop >= 0);
155167
dest->stackpointer = dest->localsplus + stacktop;
156-
for (int i = 1; i < stacktop; i++) {
157-
dest->localsplus[i] = src->localsplus[i];
168+
for (int i = 0; i < stacktop; i++) {
169+
dest->localsplus[i] = PyStackRef_MakeHeapSafe(src->localsplus[i]);
158170
}
159-
// Don't leave a dangling pointer to the old frame when creating generators
160-
// and coroutines:
161-
dest->previous = NULL;
162171
}
163172

164173
#ifdef Py_GIL_DISABLED
@@ -393,7 +402,7 @@ _PyFrame_PushTrampolineUnchecked(PyThreadState *tstate, PyCodeObject *code, int
393402

394403
PyAPI_FUNC(_PyInterpreterFrame *)
395404
_PyEvalFramePushAndInit(PyThreadState *tstate, _PyStackRef func,
396-
PyObject *locals, _PyStackRef const* args,
405+
PyObject *locals, _PyStackRef const *args,
397406
size_t argcount, PyObject *kwnames,
398407
_PyInterpreterFrame *previous);
399408

Include/internal/pycore_object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ PyAPI_FUNC(int) _PyObject_IsFreed(PyObject *);
8282
#define _PyObject_HEAD_INIT(type) \
8383
{ \
8484
.ob_refcnt = _Py_IMMORTAL_INITIAL_REFCNT, \
85-
.ob_flags = _Py_STATICALLY_ALLOCATED_FLAG, \
85+
.ob_flags = _Py_STATIC_FLAG_BITS, \
8686
.ob_type = (type) \
8787
}
8888
#else

Include/internal/pycore_opcode_metadata.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)