Skip to content

Commit

Permalink
Put GNUC attribute wrappers into util/Gcc.h: PRINTF and NORETURN
Browse files Browse the repository at this point in the history
  • Loading branch information
stbuehler committed Jun 1, 2012
1 parent d0e4677 commit 24dd542
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
2 changes: 2 additions & 0 deletions exception/AbortHandler.h
Expand Up @@ -20,6 +20,8 @@
#include <stdio.h>

/** Internal callback, please use AbortHandler_INSTANCE instead. */
static void AbortHandler_callback(char* message, int code, struct ExceptionHandler* handler)
Gcc_NORETURN;
static void AbortHandler_callback(char* message, int code, struct ExceptionHandler* handler)
{
fprintf(stderr, "Error: %s (code: %d)\n", message, code);
Expand Down
2 changes: 1 addition & 1 deletion memory/BufferAllocator.c
Expand Up @@ -44,7 +44,7 @@ struct BufferAllocator_context {
struct Job onOOM;
};


static void failure(const char* message) Gcc_NORETURN;
static void failure(const char* message)
{
fprintf(stderr, "Fatal error: %s\n", message);
Expand Down
1 change: 1 addition & 0 deletions memory/MallocAllocator.c
Expand Up @@ -81,6 +81,7 @@ struct FirstContext
size_t spaceAvailable;
};

static void failure(const char* message) Gcc_NORETURN;
static void failure(const char* message)
{
fprintf(stderr, "Fatal error: %s\n", message);
Expand Down
32 changes: 32 additions & 0 deletions util/Gcc.h
@@ -0,0 +1,32 @@
/* vim: set expandtab ts=4 sw=4: */
/*
* You may redistribute this program and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef Gcc_H
#define Gcc_H

#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4))

#define Gcc_PRINTF( format_idx, arg_idx ) \
__attribute__((__format__ (__printf__, format_idx, arg_idx)))
#define Gcc_NORETURN \
__attribute__((__noreturn__))

#else

#define Gcc_PRINTF( format_idx, arg_idx )
#define Gcc_NORETURN

#endif

#endif
11 changes: 2 additions & 9 deletions util/Log.h
Expand Up @@ -16,6 +16,7 @@
#define Log_H

#include "io/Writer.h"
#include "util/Gcc.h"

#include <stdarg.h>
#include <stdint.h>
Expand All @@ -33,17 +34,9 @@ struct Log
};


#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4))
#define Log_GNUC_PRINTF( format_idx, arg_idx ) \
__attribute__((__format__ (__printf__, format_idx, arg_idx)))
#else
#define Log_GNUC_PRINTF( format_idx, arg_idx )
#endif

static inline void Log_logInternal(struct Log* log, const char* logLevel, const char* file,
unsigned int line, const char* format, ...)
Log_GNUC_PRINTF(5, 6);
#undef Log_GNUC_PRINTF
Gcc_PRINTF(5, 6);

static inline void Log_logInternal(struct Log* log, const char* logLevel, const char* file,
unsigned int line, const char* format, ...)
Expand Down

0 comments on commit 24dd542

Please sign in to comment.