]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[mod_python3] fix build on Python 3.10+ 2146/head
authorVictor Seva <vseva@sipwise.com>
Tue, 4 Jul 2023 13:25:05 +0000 (15:25 +0200)
committerVictor Seva <linuxmaniac@torreviejawireless.org>
Mon, 10 Jul 2023 17:21:04 +0000 (19:21 +0200)
fix #2145

src/mod/languages/mod_python3/mod_python3.c

index ca05f18710f486aa08d43ae1e776554fd0b4272d..263c2de1d470b54fc88d48112896f0e1569c7dd0 100644 (file)
@@ -86,6 +86,9 @@ static void print_python_error(const char * script)
 {
        PyObject *pyType = NULL, *pyValue = NULL, *pyTraceback = NULL, *pyString = NULL;
        PyObject *pyModule=NULL, *pyFunction = NULL, *pyResult = NULL;
+#if PY_VERSION_HEX >= 0x030B0000
+       PyCodeObject *pcode = NULL;
+#endif
        char * buffer = (char*) malloc( 20 * 1024  * sizeof(char));
        /* Variables for the traceback */
        PyTracebackObject * pyTB = NULL/*, *pyTB2 = NULL*/;
@@ -153,10 +156,23 @@ static void print_python_error(const char * script)
 
                /* Traceback */
                do {
-                       sprintf((char*)sTemp, "\n\tFile: \"%s\", line %i, in %s",
+#if PY_VERSION_HEX >= 0x030B0000
+                       if (pyTB->tb_frame != NULL) {
+                               pcode = PyFrame_GetCode(pyTB->tb_frame);
+                       } else {
+                               pcode = NULL;
+                       }
+
+                       snprintf((char*)sTemp, sizeof(sTemp), "\n\tFile: \"%s\", line %i, in %s",
+                                       (pcode)?PyString_AsString(pcode->co_filename):"",
+                                       pyTB->tb_lineno,
+                                       (pcode)?PyString_AsString(pcode->co_name):"" );
+#else
+                       snprintf((char*)sTemp, sizeof(sTemp), "\n\tFile: \"%s\", line %i, in %s",
                                        PyString_AsString(pyTB->tb_frame->f_code->co_filename),
                                        pyTB->tb_lineno,
                                        PyString_AsString(pyTB->tb_frame->f_code->co_name) );
+#endif
                        strcat(buffer, (char*)sTemp);
 
                        pyTB=pyTB->tb_next;