summaryrefslogtreecommitdiff
path: root/src/xine-utils/xineutils.h
diff options
context:
space:
mode:
authorStephen Torri <storri@users.sourceforge.net>2003-02-28 02:51:47 +0000
committerStephen Torri <storri@users.sourceforge.net>2003-02-28 02:51:47 +0000
commit49327f43ca2196122a60314e67eeee929efea873 (patch)
tree1b9ce1d2b141d0e411e422df265f6d57183906e1 /src/xine-utils/xineutils.h
parent7eb769e2d3c1abb16e53d87af5f8633967e7f6ce (diff)
downloadxine-lib-49327f43ca2196122a60314e67eeee929efea873.tar.gz
xine-lib-49327f43ca2196122a60314e67eeee929efea873.tar.bz2
Xine assert() replacement:
All assert() function calls, with exceptions of libdvdread and libdvdnav, have been replaced with XINE_ASSERT. Functionally XINE_ASSERT behaves just likes its predecesor but its adding the ability to print out a stack trace at the point where the assertion fails. So here are a few examples. assert (0); This use of assert was found in a couple locations most favorably being the default case of a switch statement. This was the only thing there. So if the switch statement was unable to find a match it would have defaulted to this and the user and the developers would be stuck wonder who died and where. So it has been replaced with XINE_ASSERT(0, "We have reach this point and don't have a default case"); It may seem a bit none descriptive but there is more going on behind the scene. In addition to checking a condition is true/false, in this case '0', the XINE_ASSERT prints out: <filename>:<function name>:<line number> - assertion '<assertion expression>' failed. <description> An example of this might be: input_dvd.c:open_plugin:1178 - assertion '0' failed. xine_malloc failed!!! You have run out of memory XINE_ASSERT and its helper function, print_trace, are found in src/xine-utils/xineutils.h CVS patchset: 4301 CVS date: 2003/02/28 02:51:47
Diffstat (limited to 'src/xine-utils/xineutils.h')
-rw-r--r--src/xine-utils/xineutils.h43
1 files changed, 42 insertions, 1 deletions
diff --git a/src/xine-utils/xineutils.h b/src/xine-utils/xineutils.h
index 0656a5f1f..d1e2d1981 100644
--- a/src/xine-utils/xineutils.h
+++ b/src/xine-utils/xineutils.h
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: xineutils.h,v 1.33 2003/02/02 06:07:20 tmmm Exp $
+ * $Id: xineutils.h,v 1.34 2003/02/28 02:51:52 storri Exp $
*
*/
#ifndef XINEUTILS_H
@@ -30,12 +30,19 @@ extern "C" {
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
+#include <stdarg.h>
#include <inttypes.h>
#include <pthread.h>
#include "attributes.h"
#include "compat.h"
#include "xmlparser.h"
#include "xine_buffer.h"
+#include "configfile.h"
+#include "config.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <execinfo.h>
#ifdef __SUNPRO_C
#define inline
@@ -784,6 +791,40 @@ extern int v_g_table[256];
extern int v_b_table[256];
+ /* Code Taken from GNU C Library manual */
+/* Obtain a backtrace and print it to stdout. */
+static void
+print_trace (void)
+{
+ void *array[10];
+ size_t size;
+ char **strings;
+ size_t i;
+
+ size = backtrace (array, 10);
+ strings = backtrace_symbols (array, size);
+
+ printf ("Obtained %zd stack frames.\n", size);
+
+ for (i = 0; i < size; i++) {
+ printf ("%s\n", strings[i]);
+ }
+ free (strings);
+}
+
+/**
+ * Provide assert like feature with better description of failure
+ * Thanks to Mark Thomas
+ */
+#define XINE_ASSERT(exp, desc, args...) \
+ if (!(exp)) { \
+ printf("%s:%s:%d: assertion `" #exp "' failed. " desc "\n\n", \
+ __FILE__, __FUNCTION__, __LINE__, ##args); \
+ print_trace(); \
+ abort(); \
+ }
+
+
/******** double chained lists with builtin iterator *******/
typedef struct xine_node_s {