]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-119866: Don't clear frame->stackpointer on release builds (GH-131750)
authorBrandt Bucher <brandtbucher@microsoft.com>
Wed, 26 Mar 2025 19:00:16 +0000 (12:00 -0700)
committerGitHub <noreply@github.com>
Wed, 26 Mar 2025 19:00:16 +0000 (19:00 +0000)
Include/internal/pycore_interpframe.h

index 097da4edee1aafa5aa6ba3825d018db17aa841b2..1d373d55ab2de8b48f3b08f3599eaf2c5b4fc776 100644 (file)
@@ -163,15 +163,17 @@ _PyFrame_GetLocalsArray(_PyInterpreterFrame *frame)
     return frame->localsplus;
 }
 
-/* Fetches the stack pointer, and sets stackpointer to NULL.
-   Having stackpointer == NULL ensures that invalid
-   values are not visible to the cycle GC. */
+// Fetches the stack pointer, and (on debug builds) sets stackpointer to NULL.
+// Having stackpointer == NULL makes it easier to catch missing stack pointer
+// spills/restores (which could expose invalid values to the GC) using asserts.
 static inline _PyStackRef*
 _PyFrame_GetStackPointer(_PyInterpreterFrame *frame)
 {
     assert(frame->stackpointer != NULL);
     _PyStackRef *sp = frame->stackpointer;
+#ifndef NDEBUG
     frame->stackpointer = NULL;
+#endif
     return sp;
 }