Blame 0007-Fix-IS_SUSPENDED-call-to-use-PyFrame_GetGenerator-gi.patch

cba2e0f
From caadf3fbbdc89528c1f4833c6cbb153a9de4fd0c Mon Sep 17 00:00:00 2001
cba2e0f
From: =?UTF-8?q?S=C3=BCmer=20Cip?= <sumer.cip@platform.sh>
cba2e0f
Date: Thu, 18 Aug 2022 15:14:08 +0300
cba2e0f
Subject: [PATCH 07/11] Fix IS_SUSPENDED() call to use
cba2e0f
 PyFrame_GetGenerator()->gi_frame_state
cba2e0f
cba2e0f
---
cba2e0f
 yappi/_yappi.c | 19 ++++++++++---------
cba2e0f
 1 file changed, 10 insertions(+), 9 deletions(-)
cba2e0f
cba2e0f
diff --git a/yappi/_yappi.c b/yappi/_yappi.c
cba2e0f
index 641cc84..88236ee 100644
cba2e0f
--- a/yappi/_yappi.c
cba2e0f
+++ b/yappi/_yappi.c
cba2e0f
@@ -25,10 +25,6 @@
cba2e0f
 #include "mem.h"
cba2e0f
 #include "tls.h"
cba2e0f
 
cba2e0f
-#if PY_VERSION_HEX > 0x030b0000
cba2e0f
-#include "internal/pycore_code.h"
cba2e0f
-#endif
cba2e0f
-
cba2e0f
 #define SUPPRESS_WARNING(a) (void)a
cba2e0f
 
cba2e0f
 #ifdef IS_PY3K
cba2e0f
@@ -227,12 +223,17 @@ static void _DebugPrintObjects(unsigned int arg_count, ...)
cba2e0f
 }
cba2e0f
 
cba2e0f
 int 
cba2e0f
-IS_SUSPENDED(PyFrameObject *frame)
cba2e0f
-{
cba2e0f
-#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 11
cba2e0f
+IS_SUSPENDED(PyFrameObject *frame) {
cba2e0f
+#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION == 11
cba2e0f
+    PyGenObject *gen = (PyGenObject *)PyFrame_GetGenerator(frame);
cba2e0f
+    if (gen == NULL) {
cba2e0f
+        return 0;
cba2e0f
+    }
cba2e0f
+
cba2e0f
+    // -1 is FRAME_SUSPENDED. See internal/pycore_frame.h
cba2e0f
+    // TODO: Remove these after 3.12 make necessary public APIs.
cba2e0f
     // See https://discuss.python.org/t/python-3-11-frame-structure-and-various-changes/17895
cba2e0f
-    // TODO: _PyFrame_GetGenerator(frame)->gi_frame_state ???
cba2e0f
-    return 1;
cba2e0f
+    return gen->gi_frame_state == -1;
cba2e0f
 #elif PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION == 10
cba2e0f
     return (frame->f_state == FRAME_SUSPENDED);
cba2e0f
 #else
cba2e0f
-- 
cba2e0f
2.34.1
cba2e0f