-BEGIN_DECL
-#if 0
-#define __CALLOC_OP(n, s) calloc((n), (s))
- #define __REALLOC_OP(n, s) realloc((n), (s))
-#define CALLOC(n, s) ((__CALLOC_OP ((n)?:(FAILURE("attempt to alloc 0 bytes"), 0), (s)?:(FAILURE("attempt to alloc 0 bytes"), 0)))?:(FAILURE("memory allocation error"), NULL))
- /* #define REALLOC(p, s) ((__REALLOC_OP ((p), (s)?:(FAILURE("attempt to alloc 0 bytes"), 0)))?:(FAILURE("memory reallocation error"), NULL)) */
- #define REALLOC(p, s) (__REALLOC_OP ((p), (s)))
-#endif
+#include "xbt/asserts.h"
+#include "xbt/str.h"
+
+SG_BEGIN_DECL()
+
+/* They live in asserts.h, but need to be declared before this module.
+ double declaration to cut dependency cycle */
+/**
+ * @addtogroup XBT_error
+ *
+ * @{
+ */
+XBT_PUBLIC(void) xbt_abort(void) _XBT_GNUC_NORETURN;
+XBT_PUBLIC(void) xbt_die(const char *msg) _XBT_GNUC_NORETURN;
+/** @} */
+
+/** @addtogroup XBT_syscall
+ * @brief Malloc and associated functions, killing the program on error (with \ref XBT_ex)
+ *
+ * @{
+ */
+
+#if defined(__GNUC__) || defined(DOXYGEN)
+/** @brief Like strdup, but xbt_die() on error */
+static XBT_INLINE char *xbt_strdup(const char *s) {
+ char *res = NULL;
+ if (s) {
+ res=strdup(s);
+ if (!res)
+ xbt_die("memory allocation error (strdup returned NULL)");
+ }
+ return res;
+}
+/** @brief Like malloc, but xbt_die() on error
+ @hideinitializer */
+static XBT_INLINE void *xbt_malloc(int n){
+ void *res=malloc(n);
+ if (!res)
+ xbt_die(bprintf("Memory allocation of %d bytes failed",n));
+ return res;
+}
+
+/** @brief like malloc, but xbt_die() on error and memset data to 0
+ @hideinitializer */
+static XBT_INLINE void *xbt_malloc0(int n) {
+ void *res=calloc(n,1);
+ if (!res)
+ xbt_die(bprintf("Memory callocation of %d bytes failed",n));
+ return res;
+}