@@ -86,6 +86,9 @@ static void print_python_error(const char * script)
86
86
{
87
87
PyObject * pyType = NULL , * pyValue = NULL , * pyTraceback = NULL , * pyString = NULL ;
88
88
PyObject * pyModule = NULL , * pyFunction = NULL , * pyResult = NULL ;
89
+ #if PY_VERSION_HEX >= 0x030B0000
90
+ PyCodeObject * pcode = NULL ;
91
+ #endif
89
92
char * buffer = (char * ) malloc ( 20 * 1024 * sizeof (char ));
90
93
/* Variables for the traceback */
91
94
PyTracebackObject * pyTB = NULL /*, *pyTB2 = NULL*/ ;
@@ -153,10 +156,23 @@ static void print_python_error(const char * script)
153
156
154
157
/* Traceback */
155
158
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" ,
157
172
PyString_AsString (pyTB -> tb_frame -> f_code -> co_filename ),
158
173
pyTB -> tb_lineno ,
159
174
PyString_AsString (pyTB -> tb_frame -> f_code -> co_name ) );
175
+ #endif
160
176
strcat (buffer , (char * )sTemp );
161
177
162
178
pyTB = pyTB -> tb_next ;
0 commit comments