]> granicus.if.org Git - python/commitdiff
faulthandler: fix compilating without threads
authorVictor Stinner <victor.stinner@haypocalc.com>
Thu, 7 Apr 2011 09:50:25 +0000 (11:50 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Thu, 7 Apr 2011 09:50:25 +0000 (11:50 +0200)
Lib/test/test_faulthandler.py
Modules/faulthandler.c

index 59a0a6d8dadd2524bc5b650f0b59e9ad8342b144..bfe662eb021a9252249aef7578e4a74594d8d327 100644 (file)
@@ -8,6 +8,12 @@ from test import support, script_helper
 import tempfile
 import unittest
 
+try:
+    import threading
+    HAVE_THREADS = True
+except ImportError:
+    HAVE_THREADS = False
+
 TIMEOUT = 0.5
 
 try:
@@ -279,6 +285,7 @@ funcA()
         with temporary_filename() as filename:
             self.check_dump_traceback(filename)
 
+    @unittest.skipIf(not HAVE_THREADS, 'need threads')
     def check_dump_traceback_threads(self, filename):
         """
         Call explicitly dump_traceback(all_threads=True) and check the output.
index cfbfda6192d696a9af63a6212bdc795498a27cb2..76cadf382c541ca92e2257f9a57bbb673e671070 100644 (file)
@@ -250,6 +250,7 @@ faulthandler_fatal_error(int signum)
     PUTS(fd, handler->name);
     PUTS(fd, "\n\n");
 
+#ifdef WITH_THREAD
     /* SIGSEGV, SIGFPE, SIGABRT, SIGBUS and SIGILL are synchronous signals and
        so are delivered to the thread that caused the fault. Get the Python
        thread state of the current thread.
@@ -259,6 +260,9 @@ faulthandler_fatal_error(int signum)
        used. Read the thread local storage (TLS) instead: call
        PyGILState_GetThisThreadState(). */
     tstate = PyGILState_GetThisThreadState();
+#else
+    tstate = PyThreadState_Get();
+#endif
     if (tstate == NULL)
         return;
 
@@ -540,10 +544,14 @@ faulthandler_user(int signum)
     if (!user->enabled)
         return;
 
+#ifdef WITH_THREAD
     /* PyThreadState_Get() doesn't give the state of the current thread if
        the thread doesn't hold the GIL. Read the thread local storage (TLS)
        instead: call PyGILState_GetThisThreadState(). */
     tstate = PyGILState_GetThisThreadState();
+#else
+    tstate = PyThreadState_Get();
+#endif
 
     if (user->all_threads)
         _Py_DumpTracebackThreads(user->fd, user->interp, tstate);