From patchwork Wed Jul 28 05:28:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 44495 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 09FFF3835802 for ; Wed, 28 Jul 2021 05:29:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 09FFF3835802 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1627450163; bh=DKS9XL8vcRfqxu2j3sfd2pGecCsX1B/U6/AyZyiXf+M=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=VjL5Q4M/pN4e4MBPBQk4Dm75ZlZgreuLEuTFwokern3hEI7uLpz8+KWv2cA27OUMM WUKBoVQq0tG7w4QqZZaEAtMkDl1zHUV/+v+8e6FBMY1TKqKdIgPiThS5XI3tVw9RTY VirxKgS9DdEVZXjOZoO7RCLW9HOAR+xQbZQD/RuQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bird.elm.relay.mailchannels.net (bird.elm.relay.mailchannels.net [23.83.212.17]) by sourceware.org (Postfix) with ESMTPS id 237743861823 for ; Wed, 28 Jul 2021 05:29:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 237743861823 X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 85D1C48194F; Wed, 28 Jul 2021 05:28:59 +0000 (UTC) Received: from pdx1-sub0-mail-a75.g.dreamhost.com (100-96-27-225.trex-nlb.outbound.svc.cluster.local [100.96.27.225]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id CD143481B31; Wed, 28 Jul 2021 05:28:58 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a75.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.27.225 (trex/6.3.3); Wed, 28 Jul 2021 05:28:59 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Shelf-Arithmetic: 36535d1357661ae1_1627450139079_538286327 X-MC-Loop-Signature: 1627450139079:304179526 X-MC-Ingress-Time: 1627450139078 Received: from pdx1-sub0-mail-a75.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a75.g.dreamhost.com (Postfix) with ESMTP id 8570A8C384; Tue, 27 Jul 2021 22:28:58 -0700 (PDT) Received: from rhbox.redhat.com (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a75.g.dreamhost.com (Postfix) with ESMTPSA id 542958C377; Tue, 27 Jul 2021 22:28:55 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a75 To: libc-alpha@sourceware.org Subject: [PATCH] tests: use xmalloc to allocate implementation array Date: Wed, 28 Jul 2021 10:58:41 +0530 Message-Id: <20210728052841.3889012-1-siddhesh@sourceware.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3494.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Siddhesh Poyarekar via Libc-alpha From: Siddhesh Poyarekar Reply-To: Siddhesh Poyarekar Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The benchmark and tests must fail in case of allocation failure in the implementation array. Also annotate the x* allocators in support.h so that the compiler has more information about them. --- benchtests/bench-string.h | 5 +++-- string/test-string.h | 5 +++-- support/support.h | 25 ++++++++++++++++++------- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/benchtests/bench-string.h b/benchtests/bench-string.h index fd25264417..03de372cff 100644 --- a/benchtests/bench-string.h +++ b/benchtests/bench-string.h @@ -18,6 +18,7 @@ #include #include +#include /* We are compiled under _ISOMAC, so libc-symbols.h does not do this for us. */ @@ -200,8 +201,8 @@ static impl_t *impl_array; skip = impl; \ else \ impl_count++; \ - a = impl_array = malloc ((impl_count + func_count) * \ - sizeof (impl_t)); \ + a = impl_array = xmalloc ((impl_count + func_count) * \ + sizeof (impl_t)); \ for (impl = __start_impls; impl < __stop_impls; ++impl) \ if (impl != skip) \ *a++ = *impl; \ diff --git a/string/test-string.h b/string/test-string.h index febde61040..78b66efe36 100644 --- a/string/test-string.h +++ b/string/test-string.h @@ -18,6 +18,7 @@ . */ #include +#include typedef struct { @@ -146,8 +147,8 @@ static impl_t *impl_array; skip = impl; \ else \ impl_count++; \ - a = impl_array = malloc ((impl_count + func_count) * \ - sizeof (impl_t)); \ + a = impl_array = xmalloc ((impl_count + func_count) * \ + sizeof (impl_t)); \ for (impl = __start_impls; impl < __stop_impls; ++impl) \ if (impl != skip) \ *a++ = *impl; \ diff --git a/support/support.h b/support/support.h index dbd270c78d..dce1ea3509 100644 --- a/support/support.h +++ b/support/support.h @@ -87,14 +87,25 @@ int support_descriptor_supports_holes (int fd); /* Error-checking wrapper functions which terminate the process on error. */ -void *xmalloc (size_t) __attribute__ ((malloc)); -void *xcalloc (size_t n, size_t s) __attribute__ ((malloc)); -void *xrealloc (void *p, size_t n); -void *xposix_memalign (size_t alignment, size_t n); +extern void *xmalloc (size_t n) + __attribute_malloc__ __attribute_alloc_size__ ((1)) __attr_dealloc_free + __returns_nonnull; +extern void *xcalloc (size_t n, size_t s) + __attribute_malloc__ __attribute_alloc_size__ ((1, 2)) __attr_dealloc_free + __returns_nonnull; +extern void *xrealloc (void *o, size_t n) + __attribute_malloc__ __attribute_alloc_size__ ((2)) __attr_dealloc_free + __returns_nonnull; +extern char *xstrdup (const char *) __attribute_malloc__ __attr_dealloc_free + __returns_nonnull; +void *xposix_memalign (size_t alignment, size_t n) + __attribute_malloc__ __attribute_alloc_size__ ((2)) __attr_dealloc_free + __returns_nonnull; char *xasprintf (const char *format, ...) - __attribute__ ((format (printf, 1, 2), malloc)); -char *xstrdup (const char *); -char *xstrndup (const char *, size_t); + __attribute__ ((format (printf, 1, 2), malloc)) __attr_dealloc_free + __returns_nonnull; +char *xstrdup (const char *) __attr_dealloc_free __returns_nonnull; +char *xstrndup (const char *, size_t) __attr_dealloc_free __returns_nonnull; char *xsetlocale (int category, const char *locale); locale_t xnewlocale (int category_mask, const char *locale, locale_t base); char *xuselocale (locale_t newloc);