From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/1827 Path: news.gmane.org!not-for-mail From: philomath Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] Add _Noreturn specifier to functions specified as such by ISO C11 Date: Wed, 5 Sep 2012 13:53:11 +0200 Message-ID: <20120905135311.43281a54@gmail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1346845949 17905 80.91.229.3 (5 Sep 2012 11:52:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 5 Sep 2012 11:52:29 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-1828-gllmg-musl=m.gmane.org@lists.openwall.com Wed Sep 05 13:52:31 2012 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1T9E9j-0002OD-2x for gllmg-musl@plane.gmane.org; Wed, 05 Sep 2012 13:52:27 +0200 Original-Received: (qmail 26115 invoked by uid 550); 5 Sep 2012 11:52:23 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 26102 invoked from network); 5 Sep 2012 11:52:23 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:x-mailer:mime-version:content-type :content-transfer-encoding; bh=wi3tuSAgKFamxtY7NU68xeuqFOh8/dGD0Z7VNj5fYu4=; b=lZXIXK1yGh47BlOwuN4LAnO3FLp4Qh13NJ6y7Olr875q0J5Hsd9M2R+VogZi5hzju9 Rg/tOoE9PvNoQjPD076eRobhGXfR+WtN9v6oJPwwl8KxT7D8HjTK9LoluZhHgLFrjiq4 RDc6N8AvmtoxPhKgTP2mCvCv5iYLwBo1/FWInnSm1dFKuZjpGMoLtNlxw+CCFK29rVue TPLdiUMC7h2gGYttLuxRBUgI4RKIhq6WX6B7janDigHnPca5wKfpdFcVbJLrCGjRTHaQ 2CaAM0Yp7lRKI+BqmOem/cH7nHIN14sbeOv36PlFAuHGJlVFcUCsAwn3HmSNE2syw7Bn x6dg== X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.11; x86_64-unknown-linux-gnu) Xref: news.gmane.org gmane.linux.lib.musl.general:1827 Archived-At: 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 int setjmp (jmp_buf); -void longjmp (jmp_buf, int); +_Noreturn void longjmp (jmp_buf, int); #define setjmp setjmp #define longjmp longjmp diff --git a/include/stdlib.h b/include/stdlib.h index 1749cb3..5e28cd2 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -40,12 +40,19 @@ void *realloc (void *, size_t); void free (void *); void *aligned_alloc(size_t alignment, size_t size); -void abort (void); +#if __STDC_VERSION__ < 201112L +# if __GNUC__ +# define _Noreturn __attribute__((__noreturn__)) +# else +# define _Noreturn +# endif +#endif +_Noreturn void abort (void); int atexit (void (*) (void)); -void exit (int); -void _Exit (int); +_Noreturn void exit (int); +_Noreturn void _Exit (int); int at_quick_exit (void (*) (void)); -void quick_exit (int); +_Noreturn void quick_exit (int); char *getenv (const char *); 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 #include "syscall.h" -void _Exit(int ec) +#if __STDC_VERSION__ < 201112L +# if __GNUC__ +# define _Noreturn __attribute__((__noreturn__)) +# else +# define _Noreturn +# endif +#endif + +_Noreturn void _Exit(int ec) { __syscall(SYS_exit_group, ec); __syscall(SYS_exit, ec); diff --git a/src/exit/abort.c b/src/exit/abort.c index c5b9e52..a3fa436 100644 --- a/src/exit/abort.c +++ b/src/exit/abort.c @@ -2,7 +2,15 @@ #include #include "syscall.h" -void abort(void) +#if __STDC_VERSION__ < 201112L +# if __GNUC__ +# define _Noreturn __attribute__((__noreturn__)) +# else +# define _Noreturn +# endif +#endif + +_Noreturn void abort(void) { raise(SIGABRT); raise(SIGKILL); diff --git a/src/exit/exit.c b/src/exit/exit.c index e4aeaf1..0a1c9aa 100644 --- a/src/exit/exit.c +++ b/src/exit/exit.c @@ -14,7 +14,15 @@ weak_alias(dummy, __funcs_on_exit); weak_alias(dummy, __flush_on_exit); weak_alias(dummy, __seek_on_exit); -void exit(int code) +#if __STDC_VERSION__ < 201112L +# if __GNUC__ +# define _Noreturn __attribute__((__noreturn__)) +# else +# define _Noreturn +# endif +#endif + +_Noreturn void exit(int code) { static int lock; diff --git a/src/exit/quick_exit.c b/src/exit/quick_exit.c index 18d5288..936cd7f 100644 --- a/src/exit/quick_exit.c +++ b/src/exit/quick_exit.c @@ -3,10 +3,18 @@ #include "atomic.h" #include "libc.h" +#if __STDC_VERSION__ < 201112L +# if __GNUC__ +# define _Noreturn __attribute__((__noreturn__)) +# else +# define _Noreturn +# endif +#endif + static void dummy() { } weak_alias(dummy, __funcs_on_quick_exit); -void quick_exit(int code) +_Noreturn void quick_exit(int code) { static int lock; while (a_swap(&lock, 1)) __syscall(SYS_pause); -- 1.7.12