Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20120905141824.GS27715@brightrain.aerifal.cx>
Date: Wed, 5 Sep 2012 10:18:24 -0400
From: Rich Felker <dalias@...ifal.cx>
To: musl@...ts.openwall.com
Subject: Re: [PATCH] Add _Noreturn specifier to functions specified as
 such by ISO C11

On Wed, Sep 05, 2012 at 01:53:11PM +0200, philomath wrote:
> Since the _Noreturn identifier is not in the user's namespace, we can use it
> directly.  in case it's not a keyword (i.e. pre-C11), it is defined as
> __attribute__((__noreturn__)) on GCC (where it is implemented since version
> 2.95), and empty elsewhere.
> 
> There are some more interfaces and functions that could make use of this
> specifier, here are only those specified in the C11 standard.
> 
> ---
>  include/setjmp.h      | 10 ++++--
>  include/stdlib.h      | 15 ++++++---
>  src/exit/_Exit.c      | 10 +++++-
>  src/exit/abort.c      | 10 +++++-
>  src/exit/exit.c       | 10 +++++-
>  src/exit/quick_exit.c | 10 +++++-
>  6 files changed, 30 insertions(+), 9 deletions(-)
> 
> diff --git a/include/setjmp.h b/include/setjmp.h
> index 7dc7276..6db4786 100644
> --- a/include/setjmp.h
> +++ b/include/setjmp.h
> @@ -27,9 +27,15 @@ int _setjmp (jmp_buf);
>  void _longjmp (jmp_buf, int);
>  #endif
>  
> -
> +#if __STDC_VERSION__ < 201112L
> +# if __GNUC__
> +#  define _Noreturn __attribute__((__noreturn__))
> +# else
> +#  define _Noreturn
> +# endif
> +#endif

Is there a way you can make the logic work without nested #ifs? If
not, please at least use consistent style (no spaces after #) with the
rest of the headers, but I'd prefer if we could nesting altogether.
Perhaps..

#if __STDC_VERSION__ >= 201112L
#elif defined(__GNUC__)
#define _Noreturn __attribute__((__noreturn__))
#else
#define _Noreturn
#endif

> diff --git a/src/exit/_Exit.c b/src/exit/_Exit.c
> index 6ceb143..ea85e4a 100644
> --- a/src/exit/_Exit.c
> +++ b/src/exit/_Exit.c
> @@ -1,7 +1,15 @@
>  #include <stdlib.h>
>  #include "syscall.h"
>  
> -void _Exit(int ec)
> +#if __STDC_VERSION__ < 201112L
> +# if __GNUC__
> +#  define _Noreturn __attribute__((__noreturn__))
> +# else
> +#  define _Noreturn
> +# endif
> +#endif

Why is this duplicated in the source files? The headers already
handled it, so _Noreturn is already defined if needed; it can just be
used as if this were always C11 code.

BTW, this brings up the point that we should be checking for support
for -std=c11 or -std=c1x and using those if available, and only
falling back to -std=c99 if not.

Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.