@@ -1167,10 +1167,11 @@ dump_traceback(int fd, PyThreadState *tstate, int write_header)
11671167
11681168 The caller is responsible to call PyErr_CheckSignals() to call Python signal
11691169 handlers if signals were received. */
1170- void
1171- _Py_DumpTraceback (int fd , PyThreadState * tstate )
1170+ const char *
1171+ PyUnstable_DumpTraceback (int fd , PyThreadState * tstate )
11721172{
11731173 dump_traceback (fd , tstate , 1 );
1174+ return NULL ;
11741175}
11751176
11761177#if defined(HAVE_PTHREAD_GETNAME_NP ) || defined(HAVE_PTHREAD_GET_NAME_NP )
@@ -1257,18 +1258,26 @@ write_thread_id(int fd, PyThreadState *tstate, int is_current)
12571258 PUTS (fd , " (most recent call first):\n" );
12581259}
12591260
1261+ /* Write an error string and also return it at the same time. */
1262+ static const char *
1263+ dump_error (int fd , const char * msg )
1264+ {
1265+ PUTS (fd , msg );
1266+ return msg ;
1267+ }
1268+
12601269/* Dump the traceback of all Python threads into fd. Use write() to write the
12611270 traceback and retry if write() is interrupted by a signal (failed with
12621271 EINTR), but don't call the Python signal handler.
12631272
12641273 The caller is responsible to call PyErr_CheckSignals() to call Python signal
12651274 handlers if signals were received. */
12661275const char * _Py_NO_SANITIZE_THREAD
1267- _Py_DumpTracebackThreads (int fd , PyInterpreterState * interp ,
1268- PyThreadState * current_tstate )
1276+ PyUnstable_DumpTracebackThreads (int fd , PyInterpreterState * interp ,
1277+ PyThreadState * current_tstate )
12691278{
12701279 if (current_tstate == NULL ) {
1271- /* _Py_DumpTracebackThreads () is called from signal handlers by
1280+ /* PyUnstable_DumpTracebackThreads () is called from signal handlers by
12721281 faulthandler.
12731282
12741283 SIGSEGV, SIGFPE, SIGABRT, SIGBUS and SIGILL are synchronous signals
@@ -1283,15 +1292,15 @@ _Py_DumpTracebackThreads(int fd, PyInterpreterState *interp,
12831292 }
12841293
12851294 if (current_tstate != NULL && tstate_is_freed (current_tstate )) {
1286- return "tstate is freed" ;
1295+ return dump_error ( fd , "tstate is freed" ) ;
12871296 }
12881297
12891298 if (interp == NULL ) {
12901299 if (current_tstate == NULL ) {
12911300 interp = _PyGILState_GetInterpreterStateUnsafe ();
12921301 if (interp == NULL ) {
12931302 /* We need the interpreter state to get Python threads */
1294- return "unable to get the interpreter state" ;
1303+ return dump_error ( fd , "unable to get the interpreter state" ) ;
12951304 }
12961305 }
12971306 else {
@@ -1301,13 +1310,13 @@ _Py_DumpTracebackThreads(int fd, PyInterpreterState *interp,
13011310 assert (interp != NULL );
13021311
13031312 if (interp_is_freed (interp )) {
1304- return "interp is freed" ;
1313+ return dump_error ( fd , "interp is freed" ) ;
13051314 }
13061315
13071316 /* Get the current interpreter from the current thread */
13081317 PyThreadState * tstate = PyInterpreterState_ThreadHead (interp );
13091318 if (tstate == NULL )
1310- return "unable to get the thread head state" ;
1319+ return dump_error ( fd , "unable to get the thread head state" ) ;
13111320
13121321 /* Dump the traceback of each thread */
13131322 unsigned int nthreads = 0 ;
0 commit comments