[vlc-commits] android/thread: rework THREAD_ASSERT

Thomas Guillem git at videolan.org
Fri Mar 10 17:40:11 CET 2017


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri Mar 10 17:37:07 2017 +0100| [9a2debd67b428d9398c0497612e76c163f3bdd10] | committer: Thomas Guillem

android/thread: rework THREAD_ASSERT

Don't depend on android liblog. Print the error message on stderr. This message
can be lost, but the most important part is the full backtrace produced by the
failing assert.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9a2debd67b428d9398c0497612e76c163f3bdd10
---

 src/android/thread.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/src/android/thread.c b/src/android/thread.c
index b2ba655..af74a64 100644
--- a/src/android/thread.c
+++ b/src/android/thread.c
@@ -42,8 +42,6 @@
 #include <pthread.h>
 #include <sched.h>
 
-#include <android/log.h>
-
 #if !defined(HAVE_PTHREAD_CONDATTR_SETCLOCK) && !defined(HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC_NP)
 #error no pthread monotonic clock support
 #endif
@@ -52,8 +50,8 @@
 
 #ifndef NDEBUG
 static void
-vlc_thread_fatal (const char *action, int error,
-                  const char *function, const char *file, unsigned line)
+vlc_thread_fatal_print (const char *action, int error,
+                        const char *function, const char *file, unsigned line)
 {
     char buf[1000];
     const char *msg;
@@ -71,17 +69,18 @@ vlc_thread_fatal (const char *action, int error,
             break;
     }
 
-    __android_log_print(ANDROID_LOG_ERROR, "vlc",
-        "LibVLC fatal error %s (%d) in thread %lu "
-        "at %s:%u in %s\n Error message: %s\n",
-        action, error, vlc_thread_id (), file, line, function, msg);
-
-    abort ();
+    fprintf(stderr, "LibVLC fatal error %s (%d) in thread %lu "
+            "at %s:%u in %s\n Error message: %s\n",
+            action, error, vlc_thread_id (), file, line, function, msg);
+    fflush (stderr);
 }
 
-# define VLC_THREAD_ASSERT( action ) \
-    if (unlikely(val)) \
-        vlc_thread_fatal (action, val, __func__, __FILE__, __LINE__)
+# define VLC_THREAD_ASSERT( action ) do { \
+    if (unlikely(val)) { \
+        vlc_thread_fatal_print (action, val, __func__, __FILE__, __LINE__); \
+        assert (!action); \
+    } \
+} while(0)
 #else
 # define VLC_THREAD_ASSERT( action ) ((void)val)
 #endif



More information about the vlc-commits mailing list