Skip to contentSkip to conversation

increase portability of NORETURN declarations

PATCH In review Erik Faye-Lund 2 participants 5 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 increase portability of NORETURN declarations

Some compilers (including at least MSVC) supports NORETURN on function declarations, but only before the function-name.

This patch makes it possible to define NORETURN to something meaningful for those compilers.

---
 git-compat-util.h |    8 ++++----
 index-pack.c      |    4 ++--
 usage.c           |    6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)
git-compat-util.h +4 -4
index 9f941e4..33dd4f3 100644
@@ -177,13 +177,13 @@ extern char *gitbasename(char *);
 #endif
 
 /* General helper functions */
-extern void usage(const char *err) NORETURN;
-extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
-extern void die_errno(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
+extern NORETURN void usage(const char *err);
+extern NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2)));
+extern NORETURN void die_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
 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(void (*routine)(const char *err, va_list params) NORETURN);
+extern void set_die_routine(NORETURN 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);
index-pack.c +2 -2
index 340074f..b4f8278 100644
@@ -206,8 +206,8 @@ static void parse_pack_header(void)
 	use(sizeof(struct pack_header));
 }
 
-static void bad_object(unsigned long offset, const char *format,
-		       ...) NORETURN __attribute__((format (printf, 2, 3)));
+static NORETURN void bad_object(unsigned long offset, const char *format,
+		       ...) __attribute__((format (printf, 2, 3)));
 
 static void bad_object(unsigned long offset, const char *format, ...)
 {
usage.c +3 -3
index b6aea45..0555ce6 100644
@@ -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 void (*usage_routine)(const char *err) NORETURN = usage_builtin;
-static void (*die_routine)(const char *err, va_list params) NORETURN = die_builtin;
+static NORETURN void (*usage_routine)(const char *err) = usage_builtin;
+static NORETURN 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(void (*routine)(const char *err, va_list params) NORETURN)
+void set_die_routine(NORETURN void (*routine)(const char *err, va_list params))
 {
 	die_routine = routine;
 }
Signature · 1 line
1.6.4.msysgit.0.17.g82372.dirty
#1 lore raw

PATCH 2/2 add NORETURN_PTR for function pointers

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.

---
 git-compat-util.h |    4 +++-
 usage.c           |    6 +++---
 2 files changed, 6 insertions(+), 4 deletions(-)
git-compat-util.h +3 -1
index 33dd4f3..ac7cc66 100644
@@ -169,8 +169,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
@@ -183,7 +185,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);
usage.c +3 -3
index 0555ce6..c488f3a 100644
@@ -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;
 }
Signature · 1 line
1.6.4.msysgit.0.17.g82372.dirty
#2 lore raw

Re: [PATCH 2/2] add NORETURN_PTR for function pointers

Quoted 6 lines · Erik Faye-Lund

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.

Thanks, this version and (your 1/2) both look sane to me. The only thing missing are some Makefile knobs to tweak this, but I will assume that will come as part of a later MSVC-compatibility series.

Shawn, this can go straight to 'next', if not 'master'. The changes should be a no-op for most platforms. The only danger would be if there is some platform that doesn't like their NORETURN magic at the front of the function declaration. But we only define it by default for __GNUC__, so I suspect we're safe.

In my tree as ef/msvc-noreturn.

-Peff

#3 lore raw

Re: [PATCH 2/2] add NORETURN_PTR for function pointers

Quoted 3 lines · Jeff King

Thanks, this version and (your 1/2) both look sane to me. The only thing missing are some Makefile knobs to tweak this, but I will assume that will come as part of a later MSVC-compatibility series.

Thanks for reviewing :)

I sent an additional patch to the msysgit mailing-list that defines NORETURN for MSVC, but I think it's better to keep it out of git.git for a little while. There's no Makefile-knobs, it checks for _MSC_VER (similar to what's done for GCC).

Signature · 3 lines
Erik "kusma" Faye-Lund
[email protected]
(+47) 986 59 656
#4 lore raw

Re: [PATCH 2/2] add NORETURN_PTR for function pointers

Quoted 11 lines · Erik Faye-Lund
Quoted 3 lines · Jeff King

Thanks, this version and (your 1/2) both look sane to me. The only thing missing are some Makefile knobs to tweak this, but I will assume that will come as part of a later MSVC-compatibility series.

Thanks for reviewing :)

I sent an additional patch to the msysgit mailing-list that defines NORETURN for MSVC, but I think it's better to keep it out of git.git for a little while. There's no Makefile-knobs, it checks for _MSC_VER (similar to what's done for GCC).

That sounds good. Thanks.

-Peff