diff options
author | Zack Weinberg <zackw@panix.com> | 2017-06-08 15:39:03 -0400 |
---|---|---|
committer | Zack Weinberg <zackw@panix.com> | 2017-06-08 15:39:03 -0400 |
commit | 5046dbb4a7eba5eccfd258f92f4735c9ffc8d069 (patch) | |
tree | 4470480d904b65cf14ca524f96f79eca818c3eaf /REORG.TODO/assert | |
parent | 199fc19d3aaaf57944ef036e15904febe877fc93 (diff) | |
download | glibc-zack/build-layout-experiment.zip glibc-zack/build-layout-experiment.tar.gz glibc-zack/build-layout-experiment.tar.bz2 |
Prepare for radical source tree reorganization.zack/build-layout-experiment
All top-level files and directories are moved into a temporary storage
directory, REORG.TODO, except for files that will certainly still
exist in their current form at top level when we're done (COPYING,
COPYING.LIB, LICENSES, NEWS, README), all old ChangeLog files (which
are moved to the new directory OldChangeLogs, instead), and the
generated file INSTALL (which is just deleted; in the new order, there
will be no generated files checked into version control).
Diffstat (limited to 'REORG.TODO/assert')
-rw-r--r-- | REORG.TODO/assert/Depend | 2 | ||||
-rw-r--r-- | REORG.TODO/assert/Makefile | 30 | ||||
-rw-r--r-- | REORG.TODO/assert/Versions | 10 | ||||
-rw-r--r-- | REORG.TODO/assert/__assert.c | 26 | ||||
-rw-r--r-- | REORG.TODO/assert/assert-perr.c | 38 | ||||
-rw-r--r-- | REORG.TODO/assert/assert.c | 104 | ||||
-rw-r--r-- | REORG.TODO/assert/assert.h | 131 | ||||
-rw-r--r-- | REORG.TODO/assert/test-assert-perr.c | 86 | ||||
-rw-r--r-- | REORG.TODO/assert/test-assert.c | 88 |
9 files changed, 515 insertions, 0 deletions
diff --git a/REORG.TODO/assert/Depend b/REORG.TODO/assert/Depend new file mode 100644 index 0000000..981111e --- /dev/null +++ b/REORG.TODO/assert/Depend @@ -0,0 +1,2 @@ +iconvdata +localedata diff --git a/REORG.TODO/assert/Makefile b/REORG.TODO/assert/Makefile new file mode 100644 index 0000000..1c3be9b --- /dev/null +++ b/REORG.TODO/assert/Makefile @@ -0,0 +1,30 @@ +# Copyright (C) 1991-2017 Free Software Foundation, Inc. +# This file is part of the GNU C Library. + +# The GNU C Library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. + +# The GNU C Library 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 +# Lesser General Public License for more details. + +# You should have received a copy of the GNU Lesser General Public +# License along with the GNU C Library; if not, see +# <http://www.gnu.org/licenses/>. + +# +# Sub-makefile for assert portion of the library. +# +subdir := assert + +include ../Makeconfig + +headers := assert.h + +routines := assert assert-perr __assert +tests := test-assert test-assert-perr + +include ../Rules diff --git a/REORG.TODO/assert/Versions b/REORG.TODO/assert/Versions new file mode 100644 index 0000000..9e1a5f2 --- /dev/null +++ b/REORG.TODO/assert/Versions @@ -0,0 +1,10 @@ +libc { + GLIBC_2.0 { + # functions used in inline functions or macros + __assert_fail; __assert_perror_fail; + } + GLIBC_2.2 { + # just for standard compliance + __assert; + } +} diff --git a/REORG.TODO/assert/__assert.c b/REORG.TODO/assert/__assert.c new file mode 100644 index 0000000..4528783 --- /dev/null +++ b/REORG.TODO/assert/__assert.c @@ -0,0 +1,26 @@ +/* Copyright (C) 2000-2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +/* We have to see the prototype. */ +#undef NDEBUG +#include <assert.h> + +void +__assert (const char *assertion, const char *file, int line) +{ + __assert_fail (assertion, file, line, (const char *) 0); +} diff --git a/REORG.TODO/assert/assert-perr.c b/REORG.TODO/assert/assert-perr.c new file mode 100644 index 0000000..49ef68f --- /dev/null +++ b/REORG.TODO/assert/assert-perr.c @@ -0,0 +1,38 @@ +/* Copyright (C) 1994-2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <assert.h> +#include <libintl.h> +#include <string.h> + + +/* This function, when passed an error number, a filename, and a line + number, prints a message on the standard error stream of the form: + a.c:10: foobar: Unexpected error: Computer bought the farm + It then aborts program execution via a call to `abort'. */ +void +__assert_perror_fail (int errnum, + const char *file, unsigned int line, + const char *function) +{ + char errbuf[1024]; + + char *e = __strerror_r (errnum, errbuf, sizeof errbuf); + __assert_fail_base (_("%s%s%s:%u: %s%sUnexpected error: %s.\n"), + e, file, line, function); +} +libc_hidden_def (__assert_perror_fail) diff --git a/REORG.TODO/assert/assert.c b/REORG.TODO/assert/assert.c new file mode 100644 index 0000000..57d9644 --- /dev/null +++ b/REORG.TODO/assert/assert.c @@ -0,0 +1,104 @@ +/* Copyright (C) 1991-2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <assert.h> +#include <atomic.h> +#include <ldsodefs.h> +#include <libintl.h> +#include <stdio.h> +#include <stdlib.h> +#include <sysdep.h> +#include <unistd.h> +#include <sys/mman.h> + + +extern const char *__progname; + +#include <wchar.h> +#include <libio/iolibio.h> +#define fflush(s) _IO_fflush (s) + +/* This function, when passed a string containing an asserted + expression, a filename, and a line number, prints a message + on the standard error stream of the form: + a.c:10: foobar: Assertion `a == b' failed. + It then aborts program execution via a call to `abort'. */ + +#ifdef FATAL_PREPARE_INCLUDE +# include FATAL_PREPARE_INCLUDE +#endif + + +void +__assert_fail_base (const char *fmt, const char *assertion, const char *file, + unsigned int line, const char *function) +{ + char *str; + +#ifdef FATAL_PREPARE + FATAL_PREPARE; +#endif + + int total; + if (__asprintf (&str, fmt, + __progname, __progname[0] ? ": " : "", + file, line, + function ? function : "", function ? ": " : "", + assertion, &total) >= 0) + { + /* Print the message. */ + (void) __fxprintf (NULL, "%s", str); + (void) fflush (stderr); + + total = (total + 1 + GLRO(dl_pagesize) - 1) & ~(GLRO(dl_pagesize) - 1); + struct abort_msg_s *buf = __mmap (NULL, total, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_PRIVATE, -1, 0); + if (__glibc_likely (buf != MAP_FAILED)) + { + buf->size = total; + strcpy (buf->msg, str); + + /* We have to free the old buffer since the application might + catch the SIGABRT signal. */ + struct abort_msg_s *old = atomic_exchange_acq (&__abort_msg, buf); + + if (old != NULL) + __munmap (old, old->size); + } + + free (str); + } + else + { + /* At least print a minimal message. */ + static const char errstr[] = "Unexpected error.\n"; + __libc_write (STDERR_FILENO, errstr, sizeof (errstr) - 1); + } + + abort (); +} + + +#undef __assert_fail +void +__assert_fail (const char *assertion, const char *file, unsigned int line, + const char *function) +{ + __assert_fail_base (_("%s%s%s:%u: %s%sAssertion `%s' failed.\n%n"), + assertion, file, line, function); +} +hidden_def(__assert_fail) diff --git a/REORG.TODO/assert/assert.h b/REORG.TODO/assert/assert.h new file mode 100644 index 0000000..22f0195 --- /dev/null +++ b/REORG.TODO/assert/assert.h @@ -0,0 +1,131 @@ +/* Copyright (C) 1991-2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +/* + * ISO C99 Standard: 7.2 Diagnostics <assert.h> + */ + +#ifdef _ASSERT_H + +# undef _ASSERT_H +# undef assert +# undef __ASSERT_VOID_CAST + +# ifdef __USE_GNU +# undef assert_perror +# endif + +#endif /* assert.h */ + +#define _ASSERT_H 1 +#include <features.h> + +#if defined __cplusplus && __GNUC_PREREQ (2,95) +# define __ASSERT_VOID_CAST static_cast<void> +#else +# define __ASSERT_VOID_CAST (void) +#endif + +/* void assert (int expression); + + If NDEBUG is defined, do nothing. + If not, and EXPRESSION is zero, print an error message and abort. */ + +#ifdef NDEBUG + +# define assert(expr) (__ASSERT_VOID_CAST (0)) + +/* void assert_perror (int errnum); + + If NDEBUG is defined, do nothing. If not, and ERRNUM is not zero, print an + error message with the error text for ERRNUM and abort. + (This is a GNU extension.) */ + +# ifdef __USE_GNU +# define assert_perror(errnum) (__ASSERT_VOID_CAST (0)) +# endif + +#else /* Not NDEBUG. */ + +__BEGIN_DECLS + +/* This prints an "Assertion failed" message and aborts. */ +extern void __assert_fail (const char *__assertion, const char *__file, + unsigned int __line, const char *__function) + __THROW __attribute__ ((__noreturn__)); + +/* Likewise, but prints the error text for ERRNUM. */ +extern void __assert_perror_fail (int __errnum, const char *__file, + unsigned int __line, const char *__function) + __THROW __attribute__ ((__noreturn__)); + + +/* The following is not at all used here but needed for standard + compliance. */ +extern void __assert (const char *__assertion, const char *__file, int __line) + __THROW __attribute__ ((__noreturn__)); + + +__END_DECLS + +/* When possible, define assert so that it does not add extra + parentheses around EXPR. Otherwise, those added parentheses would + suppress warnings we'd expect to be detected by gcc's -Wparentheses. */ +# if !defined __GNUC__ || defined __STRICT_ANSI__ +# define assert(expr) \ + ((expr) \ + ? __ASSERT_VOID_CAST (0) \ + : __assert_fail (#expr, __FILE__, __LINE__, __ASSERT_FUNCTION)) +# else +# define assert(expr) \ + ({ \ + if (expr) \ + ; /* empty */ \ + else \ + __assert_fail (#expr, __FILE__, __LINE__, __ASSERT_FUNCTION); \ + }) +# endif + +# ifdef __USE_GNU +# define assert_perror(errnum) \ + (!(errnum) \ + ? __ASSERT_VOID_CAST (0) \ + : __assert_perror_fail ((errnum), __FILE__, __LINE__, __ASSERT_FUNCTION)) +# endif + +/* Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__' + which contains the name of the function currently being defined. + This is broken in G++ before version 2.6. + C9x has a similar variable called __func__, but prefer the GCC one since + it demangles C++ function names. */ +# if defined __cplusplus ? __GNUC_PREREQ (2, 6) : __GNUC_PREREQ (2, 4) +# define __ASSERT_FUNCTION __PRETTY_FUNCTION__ +# else +# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L +# define __ASSERT_FUNCTION __func__ +# else +# define __ASSERT_FUNCTION ((const char *) 0) +# endif +# endif + +#endif /* NDEBUG. */ + + +#if defined __USE_ISOC11 && !defined __cplusplus +# undef static_assert +# define static_assert _Static_assert +#endif diff --git a/REORG.TODO/assert/test-assert-perr.c b/REORG.TODO/assert/test-assert-perr.c new file mode 100644 index 0000000..8496db6 --- /dev/null +++ b/REORG.TODO/assert/test-assert-perr.c @@ -0,0 +1,86 @@ +/* Test assert_perror(). + * + * This is hairier than you'd think, involving games with + * stdio and signals. + * + */ + +#include <signal.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <setjmp.h> + +jmp_buf rec; +char buf[160]; + +static void +sigabrt (int unused) +{ + longjmp (rec, 1); /* recover control */ +} + +#undef NDEBUG +#include <assert.h> +static void +assert1 (void) +{ + assert_perror (1); +} + +static void +assert2 (void) +{ + assert_perror (0); +} + +#define NDEBUG +#include <assert.h> +static void +assert3 (void) +{ + assert_perror (2); +} + +int +main(void) +{ + volatile int failed = 1; /* safety in presence of longjmp() */ + + fclose (stderr); + stderr = tmpfile (); + if (!stderr) + abort (); + + signal (SIGABRT, sigabrt); + + if (!setjmp (rec)) + assert1 (); + else + failed = 0; /* should happen */ + + if (!setjmp (rec)) + assert2 (); + else + failed = 1; /* should not happen */ + + if (!setjmp (rec)) + assert3 (); + else + failed = 1; /* should not happen */ + + rewind (stderr); + fgets (buf, 160, stderr); + if (!strstr(buf, strerror (1))) + failed = 1; + + fgets (buf, 160, stderr); + if (strstr (buf, strerror (0))) + failed = 1; + + fgets (buf, 160, stderr); + if (strstr (buf, strerror (2))) + failed = 1; + + return failed; +} diff --git a/REORG.TODO/assert/test-assert.c b/REORG.TODO/assert/test-assert.c new file mode 100644 index 0000000..26b58d4 --- /dev/null +++ b/REORG.TODO/assert/test-assert.c @@ -0,0 +1,88 @@ +/* Test assert(). + * + * This is hairier than you'd think, involving games with + * stdio and signals. + * + */ + +#include <signal.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <setjmp.h> + +jmp_buf rec; +char buf[160]; + +static void +sigabrt (int unused) +{ + longjmp (rec, 1); /* recover control */ +} + +#undef NDEBUG +#include <assert.h> +static void +assert1 (void) +{ + assert (1 == 2); +} + +static void +assert2 (void) +{ + assert (1 == 1); +} + + +#define NDEBUG +#include <assert.h> +static void +assert3 (void) +{ + assert (2 == 3); +} + +int +main (void) +{ + + volatile int failed = 1; + + fclose (stderr); + stderr = tmpfile (); + if(!stderr) + abort (); + + signal (SIGABRT, sigabrt); + + if (!setjmp (rec)) + assert1 (); + else + failed = 0; /* should happen */ + + if (!setjmp (rec)) + assert2 (); + else + failed = 1; /* should not happen */ + + if (!setjmp (rec)) + assert3 (); + else + failed = 1; /* should not happen */ + + rewind (stderr); + fgets (buf, 160, stderr); + if (!strstr (buf, "1 == 2")) + failed = 1; + + fgets (buf, 160, stderr); + if (strstr (buf, "1 == 1")) + failed = 1; + + fgets (buf, 160, stderr); + if (strstr (buf, "2 == 3")) + failed = 1; + + return failed; +} |