gst-python: gstmodule.c: fix build with 3.11
authorMathieu Duponchelle <mathieu@centricular.com>
Fri, 4 Feb 2022 14:53:45 +0000 (15:53 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Wed, 9 Mar 2022 18:13:25 +0000 (18:13 +0000)
https://docs.python.org/fr/3.10/whatsnew/3.10.html

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1639>

subprojects/gst-python/gi/overrides/gstmodule.c

index 2308eb7..dc8364a 100644 (file)
@@ -685,22 +685,37 @@ pygst_debug_log (PyObject * pyobject, PyObject * string, GstDebugLevel level,
 
   frame = PyEval_GetFrame ();
   {
+#if PY_VERSION_HEX < 0x030a0000
+    PyCodeObject *code = frame->f_code;
+#else
+    PyCodeObject *code = PyFrame_GetCode (frame);
+#endif
     PyObject *utf8;
     const gchar *utf8_str;
 
-    utf8 = PyUnicode_AsUTF8String (frame->f_code->co_name);
+    utf8 = PyUnicode_AsUTF8String (code->co_name);
     utf8_str = PyBytes_AS_STRING (utf8);
 
     function = g_strdup (utf8_str);
     Py_DECREF (utf8);
 
-    utf8 = PyUnicode_AsUTF8String (frame->f_code->co_filename);
+    utf8 = PyUnicode_AsUTF8String (code->co_filename);
     utf8_str = PyBytes_AS_STRING (utf8);
 
     filename = g_strdup (utf8_str);
     Py_DECREF (utf8);
+#if PY_VERSION_HEX < 0x030a0000
+    lineno = PyCode_Addr2Line (frame->f_code, frame->f_lasti);
+#else
+    lineno = PyFrame_GetLineNumber (frame);
+#endif
+
+#if PY_VERSION_HEX >= 0x030a0000
+    Py_DECREF (code);
+#endif
   }
-  lineno = PyCode_Addr2Line (frame->f_code, frame->f_lasti);
+
+
   /* gst_debug_log : category, level, file, function, line, object, format, va_list */
   if (isgstobject)
     object = G_OBJECT (pygobject_get (pyobject));