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

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