From c5a94f197857c1acd79c82226c97fc18390574cc Mon Sep 17 00:00:00 2001 From: Florian Krohm Date: Wed, 10 Dec 2014 16:08:09 +0000 Subject: [PATCH] New function vfatal which should be used for user messages to indicate a situation that can legitimately occur but that we cannot handle today. The function does not return. git-svn-id: svn://svn.valgrind.org/vex/trunk@3037 --- VEX/priv/main_util.c | 27 ++++++++++++++++++++++++--- VEX/priv/main_util.h | 3 +++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/VEX/priv/main_util.c b/VEX/priv/main_util.c index 2031b8869e..ce93ba516c 100644 --- a/VEX/priv/main_util.c +++ b/VEX/priv/main_util.c @@ -263,6 +263,7 @@ void vex_assert_fail ( const HChar* expr, (*vex_failure_exit)(); } +/* To be used in assert-like (i.e. should never ever happen) situations */ __attribute__ ((noreturn)) void vpanic ( const HChar* str ) { @@ -543,11 +544,9 @@ static void add_to_myprintf_buf ( HChar c ) } } -UInt vex_printf ( const HChar* format, ... ) +static UInt vex_vprintf ( const HChar* format, va_list vargs ) { UInt ret; - va_list vargs; - va_start(vargs,format); n_myprintf_buf = 0; myprintf_buf[n_myprintf_buf] = 0; @@ -557,11 +556,33 @@ UInt vex_printf ( const HChar* format, ... ) (*vex_log_bytes)( myprintf_buf, n_myprintf_buf ); } + return ret; +} + +UInt vex_printf ( const HChar* format, ... ) +{ + UInt ret; + va_list vargs; + va_start(vargs, format); + ret = vex_vprintf(format, vargs); va_end(vargs); return ret; } +/* Use this function to communicate to users that a (legitimate) situation + occured that we cannot handle (yet). */ +__attribute__ ((noreturn)) +void vfatal ( const HChar* format, ... ) +{ + va_list vargs; + va_start(vargs, format); + vex_vprintf( format, vargs ); + va_end(vargs); + vex_printf("Cannot continue. Good-bye\n\n"); + + (*vex_failure_exit)(); +} /* A general replacement for sprintf(). */ diff --git a/VEX/priv/main_util.h b/VEX/priv/main_util.h index 7573a20639..85f13a420d 100644 --- a/VEX/priv/main_util.h +++ b/VEX/priv/main_util.h @@ -62,6 +62,9 @@ extern void vex_assert_fail ( const HChar* expr, const HChar* file, __attribute__ ((__noreturn__)) extern void vpanic ( const HChar* str ); +__attribute__ ((__noreturn__)) __attribute__ ((format (printf, 1, 2))) +extern void vfatal ( const HChar* format, ... ); + /* Printing */ -- 2.47.2