From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.4 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 7302B1F8C6 for ; Wed, 11 Aug 2021 20:02:23 +0000 (UTC) Received: from localhost ([::1]:47338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mDuQg-0001K8-D9 for normalperson@yhbt.net; Wed, 11 Aug 2021 16:02:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57120) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDuQd-0001Jr-H9 for bug-gnulib@gnu.org; Wed, 11 Aug 2021 16:02:19 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:52544) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDuQa-0003rV-SC for bug-gnulib@gnu.org; Wed, 11 Aug 2021 16:02:18 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 34FC51600FA for ; Wed, 11 Aug 2021 13:02:14 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id CnpopvZFBXnO; Wed, 11 Aug 2021 13:02:09 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 3BF67160099; Wed, 11 Aug 2021 13:02:09 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 9g_Dnz5AfCQt; Wed, 11 Aug 2021 13:02:09 -0700 (PDT) Received: from penguin.cs.ucla.edu (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 17CB416005E; Wed, 11 Aug 2021 13:02:09 -0700 (PDT) From: Paul Eggert To: bug-gnulib@gnu.org Subject: [PATCH] dynarray: merge from glibc Date: Wed, 11 Aug 2021 13:02:04 -0700 Message-Id: <20210811200204.60982-1-eggert@cs.ucla.edu> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=131.179.128.68; envelope-from=eggert@cs.ucla.edu; helo=zimbra.cs.ucla.edu X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paul Eggert Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" This also helps document glibc=E2=80=99s direction in using GCC=E2=80=99s 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 | 14 ++++++++++++++ lib/cdefs.h | 33 +++++++++++++++++++++++++++----- lib/libc-config.h | 3 +++ lib/malloc/dynarray_at_failure.c | 3 ++- 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8482276384..037fa7da4f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2021-08-11 Paul Eggert + + dynarray: merge from glibc + This also helps document glibc=E2=80=99s direction in using GCC=E2=80=99= 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 =20 canonicalize-lgpl: Fix conflict with z/OS . diff --git a/lib/cdefs.h b/lib/cdefs.h index b883b25666..4dac9d264d 100644 --- a/lib/cdefs.h +++ b/lib/cdefs.h @@ -261,10 +261,6 @@ =20 #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 <=3D __STDC_VERSION__ - # define __attribute_maybe_unused__ [[__maybe_unused__]] */ #else # define __attribute_maybe_unused__ /* Ignore */ #endif @@ -336,6 +332,16 @@ # define __nonnull(params) __attribute_nonnull__ (params) #endif =20 +/* The returns_nonnull function attribute marks the return type of the f= unction + 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 requir= es redirection on this platf array according to access mode, or at least one element when size-index is not provided: access (access-mode, [, ]) */ -#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 =20 /* Specify that a function such as setjmp or vfork may return diff --git a/lib/libc-config.h b/lib/libc-config.h index f68749fc74..886c11f37f 100644 --- a/lib/libc-config.h +++ b/lib/libc-config.h @@ -117,6 +117,9 @@ # 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__ diff --git a/lib/malloc/dynarray_at_failure.c b/lib/malloc/dynarray_at_fa= ilure.c index 4f840db7c5..8dd6850787 100644 --- a/lib/malloc/dynarray_at_failure.c +++ b/lib/malloc/dynarray_at_failure.c @@ -18,11 +18,11 @@ =20 #ifndef _LIBC # include +# include #endif =20 #include #include -#include =20 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 --=20 2.31.1