From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from bird.elm.relay.mailchannels.net (bird.elm.relay.mailchannels.net [23.83.212.17]) by sourceware.org (Postfix) with ESMTPS id 9EE3D385840D for ; Thu, 1 Jun 2023 17:08:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9EE3D385840D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gotplt.org 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 13BB4500A43; Thu, 1 Jun 2023 17:07:59 +0000 (UTC) Received: from pdx1-sub0-mail-a202.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id A20B75003E6; Thu, 1 Jun 2023 17:07:58 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1685639278; a=rsa-sha256; cv=none; b=R8AdOFKNq20Kszla/tKuAQoTaQHkl52AF5v0UQc0eovBLaCPYIPSSUCWflCucHcneJEpb1 vC2ZaffJN33dTsWfnxSRlXdbqmU/VJMg36vOl4MW7t7bvozbEcWLUiK8cv7tWQH68bXtBx iosOMHGmdrnFnhfN7NNozrEzsl71MbGde77gvah0SXt6Ih43VkakN0WnqGoUvxIfwlY4Mk KOnVaN9OBapcW7EKqwRIYlRcjyZTnD3hr6G8fEwaJI4dEXlW3KhfM+5GO+ybLa5FaGcGQF hQZ8Omhw9N58qcqZd2yGu3DB6RY1w4njlFPOE6c4P1insaR1Y67ld+upeXfy1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1685639278; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=KgDrcX+yRxZSJqJlzrH9znXEyJkFyPkMR8ErbpS1IFk=; b=onzsasGWYvW3wIwBKX8xTe8C4yXRMTtPYKDPE8d3PNlqQSTS9+MUagD1wIGGeEuB1T3HsK spbWy3s/w3NZJD7W35RAUkMkBsElX4oiWmBQWDutdhuwu8NDz7zmOE4XGprsEj7pt6urQS HbiPBSNlgr5lt5Af8Zmn/7mePtnBhtBIX58M4iPLsF0Hwu0u8eCcolseXDabB9rewnk8qx 4TMRyK31W9KrbjEM3CWJoTfwEvFQJ3KiKo7834zdWqb0ckKxjvdaM6nE/gcI9PlevCZ4Jy +3ksWF9MmjMf/X/N8I5QC6fKtT9Av1TUVe8zypIR+6TQpZef1B7J4Q7VFk24Jw== ARC-Authentication-Results: i=1; rspamd-58dcc7d645-cs75d; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Reign-Bottle: 54bd460d24e69f50_1685639278901_254740530 X-MC-Loop-Signature: 1685639278901:329273025 X-MC-Ingress-Time: 1685639278901 Received: from pdx1-sub0-mail-a202.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.115.252.243 (trex/6.8.1); Thu, 01 Jun 2023 17:07:58 +0000 Received: from [192.168.0.182] (bras-vprn-toroon4834w-lp130-02-142-113-138-85.dsl.bell.ca [142.113.138.85]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a202.dreamhost.com (Postfix) with ESMTPSA id 4QXCHy242DzL8; Thu, 1 Jun 2023 10:07:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1685639278; bh=KgDrcX+yRxZSJqJlzrH9znXEyJkFyPkMR8ErbpS1IFk=; h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding; b=s/5w9OtpViiej6nze3vi4xVOsfIMywEVMOJTIRHbKHJNP8DqZyuonnrqc+pSsYY+R 7znXWOpqt0AlL9zXV1sBtLP7KSHt57WGjHwF+9fIDe4yiUpxqvkX/RmDBM6ZT+KqP+ UCqHFi1uaSVLrKpkN+L0EYh7ZTG9AkiLefgqobrOLF04pmJepg9jsG/Z3V7xgOgkTm mSUsyCEf68AQPByd5Su0lPeoTCLJgeyBB6pHVSE7jDGfQPSkKoU7gPB7L673FHIDZY 7zmtZjK+pRcXr5FXT2CjJtpm5jTNPP8z2h3mhXLUWBl0+WeXITV4ZC0tuHyHA8sdQJ TEeniXADQP3mw== Message-ID: Date: Thu, 1 Jun 2023 13:07:57 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH] Move {read,write}_all functions to a dedicated header Content-Language: en-US To: =?UTF-8?B?RnLDqWTDqXJpYyBCw6lyYXQ=?= , libc-alpha@sourceware.org References: <20230601155556.104745-1-fberat@redhat.com> From: Siddhesh Poyarekar In-Reply-To: <20230601155556.104745-1-fberat@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3037.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2023-06-01 11:55, Frédéric Bérat wrote: > Since these functions are used in both catgets/gencat.c and > malloc/memusage{,stat}.c, it make sense to move them into a dedicated > header where they can be inlined. > --- > catgets/gencat.c | 22 +------------------- > include/unistd_ext.h | 48 +++++++++++++++++++++++++++++++++++++++++++ > malloc/memusage.c | 25 +--------------------- > malloc/memusagestat.c | 40 +----------------------------------- > 4 files changed, 51 insertions(+), 84 deletions(-) > create mode 100644 include/unistd_ext.h This should ideally have been sent in with the rest of the series, otherwise it simply breaks pre-commit CI testing: https://patchwork.sourceware.org/project/glibc/patch/20230601155556.104745-1-fberat@redhat.com/ > > diff --git a/catgets/gencat.c b/catgets/gencat.c > index 826596c2e4..9cacc801b5 100644 > --- a/catgets/gencat.c > +++ b/catgets/gencat.c > @@ -37,6 +37,7 @@ > #include > #include > #include > +#include > #include > > #include "version.h" > @@ -838,27 +839,6 @@ invalid character: message ignored")); > return current; > } > > -static void > -write_all (int fd, const void *buffer, size_t length) > -{ > - const char *p = buffer; > - const char *end = p + length; > - while (p < end) > - { > - ssize_t ret = write (fd, p, end - p); > - if (ret < 0) > - error (EXIT_FAILURE, errno, > - gettext ("write of %zu bytes failed after %td: %m"), > - length, p - (const char *) buffer); > - > - if (ret == 0) > - error (EXIT_FAILURE, 0, > - gettext ("write returned 0 after writing %td bytes of %zu"), > - p - (const char *) buffer, length); > - p += ret; > - } > -} > - > static void > write_out (struct catalog *catalog, const char *output_name, > const char *header_name) > diff --git a/include/unistd_ext.h b/include/unistd_ext.h > new file mode 100644 > index 0000000000..b6ce067efb > --- /dev/null > +++ b/include/unistd_ext.h This needs a copyright header. > @@ -0,0 +1,48 @@ > +#ifndef _UNISTD_EXT_H > +#define _UNISTD_EXT_H > + > +#include > +#include > +#include > +#include > + > +/* Helpers used in catgets/gencat.c and malloc/memusage*.c */ > +static inline void > +write_all (int fd, const void *buffer, size_t length) > +{ > + const char *p = buffer; > + const char *end = p + length; > + while (p < end) > + { > + ssize_t ret = write (fd, p, end - p); > + if (ret < 0) > + error (EXIT_FAILURE, errno, > + gettext ("write of %zu bytes failed after %td: %m"), > + length, p - (const char *) buffer); > + > + if (ret == 0) > + error (EXIT_FAILURE, 0, > + gettext ("write returned 0 after writing %td bytes of %zu"), > + p - (const char *) buffer, length); > + p += ret; > + } > +} > + > +static inline void > +read_all (int fd, void *buffer, size_t length) > +{ > + char *p = buffer; > + char *end = p + length; > + while (p < end) > + { > + ssize_t ret = read (fd, p, end - p); > + if (ret < 0) > + error (EXIT_FAILURE, errno, > + gettext ("read of %zu bytes failed after %td: %m"), > + length, p - (char *) buffer); > + > + p += ret; > + } > +} > + > +#endif > diff --git a/malloc/memusage.c b/malloc/memusage.c > index 53a3630651..1c6930188c 100644 > --- a/malloc/memusage.c > +++ b/malloc/memusage.c > @@ -18,10 +18,7 @@ > > #include > #include > -#include > -#include > #include > -#include You shouldn't remove these headers because gettext gets used despite the unistd_ext.h usage, resulting in an implicit, transitive dependency. Does it break anything if you don't remove these includes? > #include > #include > #include > @@ -30,6 +27,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -145,27 +143,6 @@ peak_atomic_max (_Atomic size_t *peak, size_t val) > while (! atomic_compare_exchange_weak (peak, &v, val)); > } > > -static void > -write_all (int fd, const void *buffer, size_t length) > -{ > - const char *p = buffer; > - const char *end = p + length; > - while (p < end) > - { > - ssize_t ret = write (fd, p, end - p); > - if (ret < 0) > - error (EXIT_FAILURE, errno, > - gettext ("write of %zu bytes failed after %td: %m"), > - length, p - (const char *) buffer); > - > - if (ret == 0) > - error (EXIT_FAILURE, 0, > - gettext ("write returned 0 after writing %td bytes of %zu"), > - p - (const char *) buffer, length); > - p += ret; > - } > -} > - > /* Update the global data after a successful function call. */ > static void > update_data (struct header *result, size_t len, size_t old_len) > diff --git a/malloc/memusagestat.c b/malloc/memusagestat.c > index cc066d4af9..837b613c2b 100644 > --- a/malloc/memusagestat.c > +++ b/malloc/memusagestat.c > @@ -29,6 +29,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -114,45 +115,6 @@ static int time_based; > static int also_total = 0; > > > -static void > -read_all (int fd, void *buffer, size_t length) > -{ > - char *p = buffer; > - char *end = p + length; > - while (p < end) > - { > - ssize_t ret = read (fd, p, end - p); > - if (ret < 0) > - error (EXIT_FAILURE, errno, > - gettext ("read of %zu bytes failed after %td: %m"), > - length, p - (char *) buffer); > - > - p += ret; > - } > -} > - > -static void > -write_all (int fd, const void *buffer, size_t length) > -{ > - const char *p = buffer; > - const char *end = p + length; > - while (p < end) > - { > - ssize_t ret = write (fd, p, end - p); > - if (ret < 0) > - error (EXIT_FAILURE, errno, > - gettext ("write of %zu bytes failed after %td: %m"), > - length, p - (const char *) buffer); > - > - if (ret == 0) > - error (EXIT_FAILURE, 0, > - gettext ("write returned 0 after writing %td bytes of %zu"), > - p - (const char *) buffer, length); > - p += ret; > - } > -} > - > - > int > main (int argc, char *argv[]) > {