Skip to content

Commit 224eb22

Browse files
authoredJul 11, 2023
Merge pull request signalwire#2146 from linuxmaniac/vseva/mod_python3
[mod_python3] Fix build on Python 3.10+
2 parents 48e1812 + 2cf57c4 commit 224eb22

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed
 

‎src/mod/languages/mod_python3/mod_python3.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ static void print_python_error(const char * script)
8686
{
8787
PyObject *pyType = NULL, *pyValue = NULL, *pyTraceback = NULL, *pyString = NULL;
8888
PyObject *pyModule=NULL, *pyFunction = NULL, *pyResult = NULL;
89+
#if PY_VERSION_HEX >= 0x030B0000
90+
PyCodeObject *pcode = NULL;
91+
#endif
8992
char * buffer = (char*) malloc( 20 * 1024 * sizeof(char));
9093
/* Variables for the traceback */
9194
PyTracebackObject * pyTB = NULL/*, *pyTB2 = NULL*/;
@@ -153,10 +156,23 @@ static void print_python_error(const char * script)
153156

154157
/* Traceback */
155158
do {
156-
sprintf((char*)sTemp, "\n\tFile: \"%s\", line %i, in %s",
159+
#if PY_VERSION_HEX >= 0x030B0000
160+
if (pyTB->tb_frame != NULL) {
161+
pcode = PyFrame_GetCode(pyTB->tb_frame);
162+
} else {
163+
pcode = NULL;
164+
}
165+
166+
snprintf((char*)sTemp, sizeof(sTemp), "\n\tFile: \"%s\", line %i, in %s",
167+
(pcode)?PyString_AsString(pcode->co_filename):"",
168+
pyTB->tb_lineno,
169+
(pcode)?PyString_AsString(pcode->co_name):"" );
170+
#else
171+
snprintf((char*)sTemp, sizeof(sTemp), "\n\tFile: \"%s\", line %i, in %s",
157172
PyString_AsString(pyTB->tb_frame->f_code->co_filename),
158173
pyTB->tb_lineno,
159174
PyString_AsString(pyTB->tb_frame->f_code->co_name) );
175+
#endif
160176
strcat(buffer, (char*)sTemp);
161177

162178
pyTB=pyTB->tb_next;

0 commit comments

Comments
 (0)