#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;
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);
}
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)
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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_ */
+++ /dev/null
-/*
- * 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);
-}
+++ /dev/null
-/*
- * 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_ */