From 0bb15d22417c0691dafb9e369eea3564e0cfae7b Mon Sep 17 00:00:00 2001 From: agiersch Date: Tue, 22 Feb 2011 13:51:15 +0000 Subject: [PATCH] Make xbt_die() accept a format string with arguments. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9688 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- ChangeLog | 1 + buildtools/Cmake/DefinePackages.cmake | 1 - include/xbt/sysdep.h | 22 ++++++++++++++-- src/xbt/asserts.c | 37 --------------------------- 4 files changed, 21 insertions(+), 40 deletions(-) delete mode 100644 src/xbt/asserts.c diff --git a/ChangeLog b/ChangeLog index a789501d54..8faa2100f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -56,6 +56,7 @@ SimGrid (3.6) unstable; urgency=low http://lists.gforge.inria.fr/pipermail/simgrid-user/2010-December/002206.html * Add new logging macros, with variable number of arguments. Define XBT_USE_DEPRECATED if you want to use the old macros INFO1, INFO2, etc. + * Change xbt_die() to accept a format string with arguments, just like printf. INSTR * New configuration options diff --git a/buildtools/Cmake/DefinePackages.cmake b/buildtools/Cmake/DefinePackages.cmake index 8de508a0a0..b8331bcaad 100644 --- a/buildtools/Cmake/DefinePackages.cmake +++ b/buildtools/Cmake/DefinePackages.cmake @@ -140,7 +140,6 @@ set(XBT_SRC src/gras_modinter.h src/xbt/xbt_virtu.c src/xbt/xbt_os_time.c - src/xbt/asserts.c src/xbt/log.c src/xbt/xbt_log_appender_file.c src/xbt/xbt_log_layout_simple.c diff --git a/include/xbt/sysdep.h b/include/xbt/sysdep.h index 33aefed2a4..282eba888a 100644 --- a/include/xbt/sysdep.h +++ b/include/xbt/sysdep.h @@ -15,6 +15,7 @@ #include #include /* va_list */ +#include "xbt/log.h" #include "xbt/misc.h" #include "xbt/asserts.h" @@ -29,8 +30,25 @@ SG_BEGIN_DECL() * * @{ */ -XBT_PUBLIC(void) xbt_abort(void) _XBT_GNUC_NORETURN; -XBT_PUBLIC(void) xbt_die(const char *msg) _XBT_GNUC_NORETURN; +/** @brief Kill the program in silence */ +#define xbt_abort() abort() + +/** + * @brief Kill the program with an error message + * \param msg + * + * Things are so messed up that the only thing to do now, is to stop the + * program. + * + * The message is handled by a CRITICAL logging request, and may consist of a + * format string with arguments. + */ +#define xbt_die(...) \ + do { \ + XBT_LOG_EXTERNAL_CATEGORY(xbt); \ + XBT_CCRITICAL(xbt, __VA_ARGS__); \ + xbt_abort(); \ + } while (0) /** @} */ /* these ones live in str.h, but redeclare them here so that we do diff --git a/src/xbt/asserts.c b/src/xbt/asserts.c deleted file mode 100644 index ab412adfb1..0000000000 --- a/src/xbt/asserts.c +++ /dev/null @@ -1,37 +0,0 @@ -/* xbt/asserts.h -- assertion mechanism */ - -/* Copyright (c) 2005, 2008, 2009, 2010. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#include /* abort */ -#include "xbt/log.h" -#include "xbt/asserts.h" - -XBT_LOG_EXTERNAL_CATEGORY(xbt); -XBT_LOG_DEFAULT_CATEGORY(xbt); - -/** - * @brief Kill the program with an error message - * \param msg - * - * Things are so messed up that the only thing to do now, is to stop the program. - * - * The message is handled by a CRITICAL logging request - * - * If you want to pass arguments to the format, you can always write xbt_assert1(0,"fmt",args) or - * xbt_die(bprintf("fmt", arg)) - */ -void xbt_die(const char *msg) -{ - XBT_CRITICAL("%s", msg); - xbt_abort(); -} - -/** @brief Kill the program in silence */ -void xbt_abort(void) -{ - abort(); -} -- 2.20.1