Skip to content

Commit 9c8a9c2

Browse files
committed
Make sure all redefined locals are written back to stack
1 parent 32ead17 commit 9c8a9c2

7 files changed

Lines changed: 108 additions & 7 deletions

File tree

Include/internal/pycore_freelist.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ _Py_freelists_GET(void)
5151
static inline int
5252
_PyFreeList_Push(struct _Py_freelist *fl, void *obj, Py_ssize_t maxsize)
5353
{
54+
assert((((uintptr_t)obj) & 3) == 0);
5455
if (fl->size < maxsize && fl->size >= 0) {
5556
FT_ATOMIC_STORE_PTR_RELAXED(*(void **)obj, fl->freelist);
5657
fl->freelist = obj;
@@ -74,6 +75,7 @@ static inline void *
7475
_PyFreeList_PopNoStats(struct _Py_freelist *fl)
7576
{
7677
void *obj = fl->freelist;
78+
assert((((uintptr_t)obj) & 3) == 0);
7779
if (obj != NULL) {
7880
assert(fl->size > 0);
7981
fl->freelist = *(void **)obj;

Include/internal/pycore_stackref.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ PyStackRef_Borrow(_PyStackRef ref)
598598
#endif
599599

600600
extern PyObject *
601-
_Py_StackRef_BoxAndReturnObject(_PyStackRef ref);
601+
_Py_StackRef_BoxInt(_PyStackRef ref);
602602

603603
static inline PyObject *
604604
PyStackRef_AsPyObjectSteal(_PyStackRef ref)
@@ -607,7 +607,7 @@ PyStackRef_AsPyObjectSteal(_PyStackRef ref)
607607
return BITS_TO_PTR(ref);
608608
}
609609
else if (PyStackRef_IsTaggedInt(ref)) {
610-
return _Py_StackRef_BoxAndReturnObject(ref);
610+
return _Py_StackRef_BoxInt(ref);
611611
}
612612
else {
613613
return Py_NewRef(BITS_TO_PTR_MASKED(ref));
@@ -818,8 +818,9 @@ static inline PyObject *
818818
PyStackRef_AsPyObjectBorrowed(_PyStackRef *ptr)
819819
{
820820
if (PyStackRef_IsTaggedInt(*ptr)) {
821-
PyObject *res = _Py_StackRef_BoxAndReturnObject(*ptr);
821+
PyObject *res = _Py_StackRef_BoxInt(*ptr);
822822
*ptr = _PyStackRef_FromPyObjectStealUnchecked(res);
823+
assert(Py_REFCNT(res) > 0);
823824
return res;
824825
}
825826
PyObject *cleared = ((PyObject *)(ptr->bits & (~Py_TAG_BITS)));
@@ -840,7 +841,7 @@ static inline PyObject *
840841
PyStackRef_AsPyObjectNew(_PyStackRef ref)
841842
{
842843
if (PyStackRef_IsTaggedInt(ref)) {
843-
return _Py_StackRef_BoxAndReturnObject(ref);
844+
return _Py_StackRef_BoxInt(ref);
844845
}
845846
return Py_NewRef(PyStackRef_AsPyObjectBorrowNonInt(ref));
846847

Objects/object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1935,7 +1935,7 @@ _PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name,
19351935
_PyThreadState_PushCStackRef(tstate, &cref);
19361936

19371937
_PyType_LookupStackRefAndVersion(tp, name, &cref.ref);
1938-
descr = PyStackRef_AsPyObjectBorrowNonInt(cref.ref);
1938+
descr = PyStackRef_AsPyObjectBorrowed(&cref.ref);
19391939

19401940
if (descr != NULL) {
19411941
f = Py_TYPE(descr)->tp_descr_set;

Python/executor_cases.c.h

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

0 commit comments

Comments
 (0)