summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2021-03-10 15:04:55 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2021-03-10 15:22:29 -0800
commitfc6d7d850bdebfed81e9212910f44edf99dd7743 (patch)
tree760bdff7508b5bcd05fccfc43c633e115689eb93
parentf0d3a4d726d16b77b3fe7fb155b29ab792452a4f (diff)
downloadgnulib-fc6d7d850bdebfed81e9212910f44edf99dd7743.tar.gz
libc-config: port to DragonFlyBSD 5.9
DragonFlyBSD defines __nonnull incompatibly with glibc, so avoid the use of __nonnull in Gnulib code. Problem reported by Gavin Smith in: https://lists.gnu.org/r/bug-gnulib/2021-03/msg00066.html * lib/cdefs.h (__attribute_nonnull__): Rename from __nonnull. All uses in Gnulib changed. There should be no need to change glibc code that is not shared with Gnulib. (__nonnull): New macro, defined in terms of __attribute_nonnull__, and which can be used in glibc code that is not shared with Gnulib.
-rw-r--r--ChangeLog13
-rw-r--r--lib/cdefs.h12
-rw-r--r--lib/libc-config.h6
-rw-r--r--lib/malloc/dynarray-skeleton.c33
4 files changed, 40 insertions, 24 deletions
diff --git a/ChangeLog b/ChangeLog
index cf72e260e0..a5ba8488f5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2021-03-10 Paul Eggert <eggert@cs.ucla.edu>
+
+ libc-config: port to DragonFlyBSD 5.9
+ DragonFlyBSD defines __nonnull incompatibly with glibc,
+ so avoid the use of __nonnull in Gnulib code.
+ Problem reported by Gavin Smith in:
+ https://lists.gnu.org/r/bug-gnulib/2021-03/msg00066.html
+ * lib/cdefs.h (__attribute_nonnull__): Rename from __nonnull.
+ All uses in Gnulib changed. There should be no need to change
+ glibc code that is not shared with Gnulib.
+ (__nonnull): New macro, defined in terms of __attribute_nonnull__,
+ and which can be used in glibc code that is not shared with Gnulib.
+
2021-03-07 Paul Eggert <eggert@cs.ucla.edu>
manywarnings: modernize documentation
diff --git a/lib/cdefs.h b/lib/cdefs.h
index 6f12c79da6..90f97412a9 100644
--- a/lib/cdefs.h
+++ b/lib/cdefs.h
@@ -321,15 +321,15 @@
/* The nonnull function attribute marks pointer parameters that
must not be NULL. */
-#ifndef __nonnull
+#ifndef __attribute_nonnull__
# if __GNUC_PREREQ (3,3) || __glibc_has_attribute (__nonnull__)
-# define __nonnull(params) __attribute__ ((__nonnull__ params))
+# define __attribute_nonnull__(params) __attribute__ ((__nonnull__ params))
# else
-# define __nonnull(params)
+# define __attribute_nonnull__(params)
# endif
-#elif !defined __GLIBC__
-# undef __nonnull
-# define __nonnull(params) _GL_ATTRIBUTE_NONNULL (params)
+#endif
+#ifndef __nonnull
+# define __nonnull(params) __attribute_nonnull__ (params)
#endif
/* If fortification mode, we warn about unused results of certain
diff --git a/lib/libc-config.h b/lib/libc-config.h
index fcdafcb968..f14013f7e8 100644
--- a/lib/libc-config.h
+++ b/lib/libc-config.h
@@ -33,9 +33,9 @@
#include <config.h>
/* On glibc this includes <features.h> and <sys/cdefs.h> and #defines
- _FEATURES_H, __WORDSIZE, and __set_errno. On FreeBSD 11 it
- includes <sys/cdefs.h> which defines __nonnull. Elsewhere it
- is harmless. */
+ _FEATURES_H, __WORDSIZE, and __set_errno. On FreeBSD 11 and
+ DragonFlyBSD 5.9 it includes <sys/cdefs.h> which defines __nonnull.
+ Elsewhere it is harmless. */
#include <errno.h>
/* From glibc <errno.h>. */
diff --git a/lib/malloc/dynarray-skeleton.c b/lib/malloc/dynarray-skeleton.c
index 5b9f37bdd6..48210e3252 100644
--- a/lib/malloc/dynarray-skeleton.c
+++ b/lib/malloc/dynarray-skeleton.c
@@ -192,7 +192,7 @@ DYNARRAY_NAME (free__array__) (struct DYNARRAY_STRUCT *list)
/* Initialize a dynamic array object. This must be called before any
use of the object. */
-__nonnull ((1))
+__attribute_nonnull__ ((1))
static void
DYNARRAY_NAME (init) (struct DYNARRAY_STRUCT *list)
{
@@ -202,7 +202,7 @@ DYNARRAY_NAME (init) (struct DYNARRAY_STRUCT *list)
}
/* Deallocate the dynamic array and its elements. */
-__attribute_maybe_unused__ __nonnull ((1))
+__attribute_maybe_unused__ __attribute_nonnull__ ((1))
static void
DYNARRAY_FREE (struct DYNARRAY_STRUCT *list)
{
@@ -213,7 +213,7 @@ DYNARRAY_FREE (struct DYNARRAY_STRUCT *list)
}
/* Return true if the dynamic array is in an error state. */
-__nonnull ((1))
+__attribute_nonnull__ ((1))
static inline bool
DYNARRAY_NAME (has_failed) (const struct DYNARRAY_STRUCT *list)
{
@@ -222,7 +222,7 @@ DYNARRAY_NAME (has_failed) (const struct DYNARRAY_STRUCT *list)
/* Mark the dynamic array as failed. All elements are deallocated as
a side effect. */
-__nonnull ((1))
+__attribute_nonnull__ ((1))
static void
DYNARRAY_NAME (mark_failed) (struct DYNARRAY_STRUCT *list)
{
@@ -236,7 +236,7 @@ DYNARRAY_NAME (mark_failed) (struct DYNARRAY_STRUCT *list)
/* Return the number of elements which have been added to the dynamic
array. */
-__nonnull ((1))
+__attribute_nonnull__ ((1))
static inline size_t
DYNARRAY_NAME (size) (const struct DYNARRAY_STRUCT *list)
{
@@ -245,7 +245,7 @@ DYNARRAY_NAME (size) (const struct DYNARRAY_STRUCT *list)
/* Return a pointer to the array element at INDEX. Terminate the
process if INDEX is out of bounds. */
-__nonnull ((1))
+__attribute_nonnull__ ((1))
static inline DYNARRAY_ELEMENT *
DYNARRAY_NAME (at) (struct DYNARRAY_STRUCT *list, size_t index)
{
@@ -257,7 +257,7 @@ DYNARRAY_NAME (at) (struct DYNARRAY_STRUCT *list, size_t index)
/* Return a pointer to the first array element, if any. For a
zero-length array, the pointer can be NULL even though the dynamic
array has not entered the failure state. */
-__nonnull ((1))
+__attribute_nonnull__ ((1))
static inline DYNARRAY_ELEMENT *
DYNARRAY_NAME (begin) (struct DYNARRAY_STRUCT *list)
{
@@ -267,7 +267,7 @@ DYNARRAY_NAME (begin) (struct DYNARRAY_STRUCT *list)
/* Return a pointer one element past the last array element. For a
zero-length array, the pointer can be NULL even though the dynamic
array has not entered the failure state. */
-__nonnull ((1))
+__attribute_nonnull__ ((1))
static inline DYNARRAY_ELEMENT *
DYNARRAY_NAME (end) (struct DYNARRAY_STRUCT *list)
{
@@ -294,7 +294,7 @@ DYNARRAY_NAME (add__) (struct DYNARRAY_STRUCT *list, DYNARRAY_ELEMENT item)
/* Add ITEM at the end of the array, enlarging it by one element.
Mark *LIST as failed if the dynamic array allocation size cannot be
increased. */
-__nonnull ((1))
+__attribute_nonnull__ ((1))
static inline void
DYNARRAY_NAME (add) (struct DYNARRAY_STRUCT *list, DYNARRAY_ELEMENT item)
{
@@ -348,7 +348,8 @@ DYNARRAY_NAME (emplace__) (struct DYNARRAY_STRUCT *list)
/* Allocate a place for a new element in *LIST and return a pointer to
it. The pointer can be NULL if the dynamic array cannot be
enlarged due to a memory allocation failure. */
-__attribute_maybe_unused__ __attribute_warn_unused_result__ __nonnull ((1))
+__attribute_maybe_unused__ __attribute_warn_unused_result__
+__attribute_nonnull__ ((1))
static
/* Avoid inlining with the larger initialization code. */
#if !(defined (DYNARRAY_ELEMENT_INIT) || defined (DYNARRAY_ELEMENT_FREE))
@@ -372,7 +373,7 @@ DYNARRAY_NAME (emplace) (struct DYNARRAY_STRUCT *list)
existing size, new elements are added (which can be initialized).
Otherwise, the list is truncated, and elements are freed. Return
false on memory allocation failure (and mark *LIST as failed). */
-__attribute_maybe_unused__ __nonnull ((1))
+__attribute_maybe_unused__ __attribute_nonnull__ ((1))
static bool
DYNARRAY_NAME (resize) (struct DYNARRAY_STRUCT *list, size_t size)
{
@@ -417,7 +418,7 @@ DYNARRAY_NAME (resize) (struct DYNARRAY_STRUCT *list, size_t size)
}
/* Remove the last element of LIST if it is present. */
-__attribute_maybe_unused__ __nonnull ((1))
+__attribute_maybe_unused__ __attribute_nonnull__ ((1))
static void
DYNARRAY_NAME (remove_last) (struct DYNARRAY_STRUCT *list)
{
@@ -434,7 +435,7 @@ DYNARRAY_NAME (remove_last) (struct DYNARRAY_STRUCT *list)
/* Remove all elements from the list. The elements are freed, but the
list itself is not. */
-__attribute_maybe_unused__ __nonnull ((1))
+__attribute_maybe_unused__ __attribute_nonnull__ ((1))
static void
DYNARRAY_NAME (clear) (struct DYNARRAY_STRUCT *list)
{
@@ -452,7 +453,8 @@ DYNARRAY_NAME (clear) (struct DYNARRAY_STRUCT *list)
stored in *RESULT if LIST refers to an empty list. On success, the
pointer in *RESULT is heap-allocated and must be deallocated using
free. */
-__attribute_maybe_unused__ __attribute_warn_unused_result__ __nonnull ((1, 2))
+__attribute_maybe_unused__ __attribute_warn_unused_result__
+__attribute_nonnull__ ((1, 2))
static bool
DYNARRAY_NAME (finalize) (struct DYNARRAY_STRUCT *list,
DYNARRAY_FINAL_TYPE *result)
@@ -483,7 +485,8 @@ DYNARRAY_NAME (finalize) (struct DYNARRAY_STRUCT *list,
have a sentinel at the end). If LENGTHP is not NULL, the array
length is written to *LENGTHP. *LIST is re-initialized and can be
reused. */
-__attribute_maybe_unused__ __attribute_warn_unused_result__ __nonnull ((1))
+__attribute_maybe_unused__ __attribute_warn_unused_result__
+__attribute_nonnull__ ((1))
static DYNARRAY_ELEMENT *
DYNARRAY_NAME (finalize) (struct DYNARRAY_STRUCT *list, size_t *lengthp)
{