]> Savannah Git Hosting - gnulib.git/commitdiff
dynarray: merge from glibc
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 11 Aug 2021 20:00:57 +0000 (13:00 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 11 Aug 2021 20:01:51 +0000 (13:01 -0700)
This also helps document glibc’s direction in using GCC’s
memory-allocation checking.
* lib/cdefs.h: Omit comments that glibc rejected.
(__returns_nonnull, __attr_access_none, __attr_dealloc)
(__attr_dealloc_free): New macros.
* lib/libc-config.h: Undef the new macros that are defined
unconditionally.
* lib/malloc/dynarray_at_failure.c [_LIBC]: Do not include stdlib.h.
(__libc_dynarray_at_failure) [_LIBC]: Call __libc_fatal,
fixing a bad merge previously.

ChangeLog
lib/cdefs.h
lib/libc-config.h
lib/malloc/dynarray_at_failure.c

index 8482276384d3b2d807dd51c12ec79c17797386b5..037fa7da4fe6c779f8f6c51f8e87271c3cdc4e96 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2021-08-11  Paul Eggert  <eggert@cs.ucla.edu>
+
+       dynarray: merge from glibc
+       This also helps document glibc’s direction in using GCC’s
+       memory-allocation checking.
+       * lib/cdefs.h: Omit comments that glibc rejected.
+       (__returns_nonnull, __attr_access_none, __attr_dealloc)
+       (__attr_dealloc_free): New macros.
+       * lib/libc-config.h: Undef the new macros that are defined
+       unconditionally.
+       * lib/malloc/dynarray_at_failure.c [_LIBC]: Do not include stdlib.h.
+       (__libc_dynarray_at_failure) [_LIBC]: Call __libc_fatal,
+       fixing a bad merge previously.
+
 2021-08-08  Bruno Haible  <bruno@clisp.org>
 
        canonicalize-lgpl: Fix conflict with z/OS <sys/stat.h>.
index b883b25666aa300ff199a791670f9ddc56d7d3f4..4dac9d264d28d6ddf8d3ccd99a9d91a3ca410338 100644 (file)
 
 #if __GNUC_PREREQ (2,7) || __glibc_has_attribute (__unused__)
 # define __attribute_maybe_unused__ __attribute__ ((__unused__))
-/* Once the next version of the C standard comes out, we can
-   do something like the following here:
-   #elif defined __STDC_VERSION__ && 202???L <= __STDC_VERSION__
-   # define __attribute_maybe_unused__ [[__maybe_unused__]]   */
 #else
 # define __attribute_maybe_unused__ /* Ignore */
 #endif
 # define __nonnull(params) __attribute_nonnull__ (params)
 #endif
 
+/* The returns_nonnull function attribute marks the return type of the function
+   as always being non-null.  */
+#ifndef __returns_nonnull
+# if __GNUC_PREREQ (4, 9) || __glibc_has_attribute (__returns_nonnull__)
+# define __returns_nonnull __attribute__ ((__returns_nonnull__))
+# else
+# define __returns_nonnull
+# endif
+#endif
+
 /* If fortification mode, we warn about unused results of certain
    function calls which can lead to problems.  */
 #if __GNUC_PREREQ (3,4) || __glibc_has_attribute (__warn_unused_result__)
@@ -598,9 +604,26 @@ _Static_assert (0, "IEEE 128-bits long double requires redirection on this platf
    array according to access mode, or at least one element when
    size-index is not provided:
      access (access-mode, <ref-index> [, <size-index>])  */
-#define __attr_access(x) __attribute__ ((__access__ x))
+#  define __attr_access(x) __attribute__ ((__access__ x))
+#  if __GNUC_PREREQ (11, 0)
+#    define __attr_access_none(argno) __attribute__ ((__access__ (__none__, argno)))
+#  else
+#    define __attr_access_none(argno)
+#  endif
 #else
 #  define __attr_access(x)
+#  define __attr_access_none(argno)
+#endif
+
+#if __GNUC_PREREQ (11, 0)
+/* Designates dealloc as a function to call to deallocate objects
+   allocated by the declared function.  */
+# define __attr_dealloc(dealloc, argno) \
+    __attribute__ ((__malloc__ (dealloc, argno)))
+# define __attr_dealloc_free __attr_dealloc (__builtin_free, 1)
+#else
+# define __attr_dealloc(dealloc, argno)
+# define __attr_dealloc_free
 #endif
 
 /* Specify that a function such as setjmp or vfork may return
index f68749fc7435317747b0b855e687f01329211753..886c11f37f1915b08972f14d16146aed357aaacb 100644 (file)
 # undef __THROW
 # undef __THROWNL
 # undef __attr_access
+# undef __attr_access_none
+# undef __attr_dealloc
+# undef __attr_dealloc_free
 # undef __attribute__
 # undef __attribute_alloc_size__
 # undef __attribute_artificial__
index 4f840db7c5edcf1072b452b2c1dfa3cd22b6a655..8dd68507870457bccca19c87b24a8bbc98781a0f 100644 (file)
 
 #ifndef _LIBC
 # include <libc-config.h>
+# include <stdlib.h>
 #endif
 
 #include <dynarray.h>
 #include <stdio.h>
-#include <stdlib.h>
 
 void
 __libc_dynarray_at_failure (size_t size, size_t index)
@@ -32,6 +32,7 @@ __libc_dynarray_at_failure (size_t size, size_t index)
   __snprintf (buf, sizeof (buf), "Fatal glibc error: "
               "array index %zu not less than array length %zu\n",
               index, size);
+  __libc_fatal (buf);
 #else
  abort ();
 #endif