replaced old panic module by newer error handling module
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Fri, 3 Mar 2006 12:53:22 +0000 (12:53 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Fri, 3 Mar 2006 12:53:22 +0000 (12:53 +0000)
[r7385]

ir/adt/xmalloc.c
ir/adt/xmalloc.h
ir/common/error.c [new file with mode: 0644]
ir/common/error.h [new file with mode: 0644]
ir/common/panic.c [deleted file]
ir/common/panic.h [deleted file]

index 7680c4b..07252a6 100644 (file)
 #endif
 
 #include "xmalloc.h"
-#include "panic.h"
+#include "error.h"
 
-void *
-xmalloc(size_t size) {
-  void *res = malloc (size);
+static NORETURN xnomem(void) {
+  panic("out of memory");
+}
+
+void *xmalloc(size_t size) {
+  void *res = malloc(size);
 
   if (!res) xnomem();
   return res;
@@ -48,24 +51,15 @@ void *xcalloc(size_t num, size_t size) {
   return res;
 }
 
-void *
-xrealloc(void *ptr, size_t size) {
+void *xrealloc(void *ptr, size_t size) {
   /* ANSI blesses realloc (0, x) but SunOS chokes on it */
   void *res = ptr ? realloc (ptr, size) : malloc (size);
 
-  if (!res) xnomem ();
+  if (!res) xnomem();
   return res;
 }
 
-
-char *
-xstrdup(const char *str) {
+char *xstrdup(const char *str) {
   size_t len = strlen (str) + 1;
-  return memcpy ((xmalloc) (len), str, len);
-}
-
-
-void
-xnomem(void) {
-  panic("out of memory");
+  return memcpy((xmalloc) (len), str, len);
 }
index 9d4048c..0400408 100644 (file)
@@ -22,7 +22,6 @@ void *xmalloc(size_t size);
 void *xcalloc(size_t num, size_t size);
 void *xrealloc(void *ptr, size_t size);
 char *xstrdup(const char *str);
-void xnomem(void);
 void free(void *ptr);
 
 #define xfree(ptr)      free(ptr)
diff --git a/ir/common/error.c b/ir/common/error.c
new file mode 100644 (file)
index 0000000..0cc58df
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Project:     libFIRM
+ * File name:   ir/common/error.c
+ * Purpose:     Error handling for libFirm
+ * Author:      Michael Beck
+ * Modified by:
+ * Created:
+ * CVS-ID:      $Id$
+ * Copyright:   (C) 1998-2006 Universität Karlsruhe
+ * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+ */
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdlib.h>
+
+#include <stdio.h>
+#include <stdarg.h>
+#include "error.h"
+
+NORETURN panic(const char *fmt, ...)
+{
+  va_list ap;
+
+  fputs("libFirm panic: ", stderr);
+  va_start(ap, fmt);
+  vfprintf(stderr, fmt, ap);
+  va_end(ap);
+  putc('\n', stderr);
+  exit(EXIT_FAILURE);
+}
diff --git a/ir/common/error.h b/ir/common/error.h
new file mode 100644 (file)
index 0000000..c075da2
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Project:     libFIRM
+ * File name:   ir/common/error.h
+ * Purpose:     Error handling for libFirm
+ * Author:      Michael Beck
+ * Modified by:
+ * Created:
+ * CVS-ID:      $Id$
+ * Copyright:   (C) 1998-2006 Universität Karlsruhe
+ * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+ */
+#ifndef _ERROR_H_
+#define _ERROR_H_
+
+/**
+ * @file error.h
+ *
+ * Error handling for libFirm.
+ *
+ * @author Michael Beck
+ */
+
+/* define a NORETURN attribute */
+#ifndef NORETURN
+# if defined(__GNUC__)
+#  if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 70)
+#   define NORETURN void __attribute__ ((noreturn))
+#  endif /* __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 70) */
+# endif /* defined(__GNUC__) */
+
+# if defined(_MSC_VER)
+#  define NORETURN void __declspec(noreturn)
+# endif /* defined(_MSC_VER) */
+
+/* If not set above, use "void" for DOES_NOT_RETURN. */
+# ifndef NORETURN
+# define NORETURN void
+# endif /* ifndef NORETURN */
+#endif /* ifndef NORETURN */
+
+/**
+ * Prints a panic message to stderr and exits.
+ */
+NORETURN panic(const char *fmt, ...);
+
+# endif /*_ERROR_H_ */
diff --git a/ir/common/panic.c b/ir/common/panic.c
deleted file mode 100644 (file)
index a316e2f..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Project:     libFIRM
- * File name:   ir/common/panic.c
- * Purpose:
- * Author:      Martin Trapp, Christian Schaefer
- * Modified by:
- * Created:
- * CVS-ID:      $Id$
- * Copyright:   (c) 1998-2003 Universität Karlsruhe
- * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
- */
-
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-# include <stdlib.h>
-
-# include <stdio.h>
-# include <stdarg.h>
-# include "panic.h"
-
-
-void
-panic (const char *fmt, ...)
-{
-  va_list ap;
-
-  fputs ("(panic) ", stderr);
-  va_start (ap, fmt);
-  vfprintf (stderr, fmt, ap);
-  va_end (ap);
-  putc ('\n', stderr);
-  exit (1);
-}
diff --git a/ir/common/panic.h b/ir/common/panic.h
deleted file mode 100644 (file)
index 63b68d3..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Project:     libFIRM
- * File name:   ir/common/panic.h
- * Purpose:
- * Author:      Martin Trapp, Christian Schaefer
- * Modified by:
- * Created:
- * CVS-ID:      $Id$
- * Copyright:   (c) 1998-2003 Universität Karlsruhe
- * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
- */
-
-/**
- * @file panic.h
- *
- * @author Martin Trapp, Christian Schaefer
- */
-
-
-# ifndef _PANIC_H_
-# define _PANIC_H_
-
-/**
- * Prints a panic message to stderr and exits.
- */
-void panic (const char *fmt, ...);
-
-# endif /*_PANIC_H_ */