Skip to content

Commit

Permalink
add NORETURN_PTR for function pointers
Browse files Browse the repository at this point in the history
Some compilers (including at least MSVC and ARM RVDS) supports
NORETURN on function declarations, but not on function pointers.

This patch makes it possible to define NORETURN for these compilers,
by splitting the NORETURN macro into two - one for function
declarations and one for function pointers.

Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
  • Loading branch information
Erik Faye-Lund authored and Jeff King committed Oct 1, 2009
1 parent a4f3131 commit 18660bc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion git-compat-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,10 @@ extern char *gitbasename(char *);

#ifdef __GNUC__
#define NORETURN __attribute__((__noreturn__))
#define NORETURN_PTR __attribute__((__noreturn__))
#else
#define NORETURN
#define NORETURN_PTR
#ifndef __attribute__
#define __attribute__(x)
#endif
Expand All @@ -192,7 +194,7 @@ extern NORETURN void die_errno(const char *err, ...) __attribute__((format (prin
extern int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));

extern void set_die_routine(NORETURN void (*routine)(const char *err, va_list params));
extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params));

extern int prefixcmp(const char *str, const char *prefix);
extern time_t tm_to_time_t(const struct tm *tm);
Expand Down
6 changes: 3 additions & 3 deletions usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ static void warn_builtin(const char *warn, va_list params)

/* If we are in a dlopen()ed .so write to a global variable would segfault
* (ugh), so keep things static. */
static NORETURN void (*usage_routine)(const char *err) = usage_builtin;
static NORETURN void (*die_routine)(const char *err, va_list params) = die_builtin;
static NORETURN_PTR void (*usage_routine)(const char *err) = usage_builtin;
static NORETURN_PTR void (*die_routine)(const char *err, va_list params) = die_builtin;
static void (*error_routine)(const char *err, va_list params) = error_builtin;
static void (*warn_routine)(const char *err, va_list params) = warn_builtin;

void set_die_routine(NORETURN void (*routine)(const char *err, va_list params))
void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params))
{
die_routine = routine;
}
Expand Down

0 comments on commit 18660bc

Please sign in to comment.