From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 134E63858D1E for ; Fri, 2 Jun 2023 06:10:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 134E63858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685686253; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rH1eUt7PZr59TJughrHOoTXqd3pHJ3G2w2xC0TPIqMA=; b=NTaqjv1zwHFW/05iiKq9K+PbcmV3x//pcTWlDoXKaC2bLPT4SVPhC7ilZzIxxevfB6kmKo V0kT/XjVWi2ftSk4fyaunvM5L8KMMn4U/D6mNdPaB33mkMNxhNV80+HpqK7wfIRFP4+JxJ M1S3QGi14mYBh6w6Ona6iW4DP8wQtLQ= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-550-JYvD8ImsPN2jVUhzITmUrw-1; Fri, 02 Jun 2023 02:10:52 -0400 X-MC-Unique: JYvD8ImsPN2jVUhzITmUrw-1 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-513ede5a2afso1177306a12.1 for ; Thu, 01 Jun 2023 23:10:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685686251; x=1688278251; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rH1eUt7PZr59TJughrHOoTXqd3pHJ3G2w2xC0TPIqMA=; b=lx0xHKMoXpnAPNo4NTzi8LHoRHBMLvWdTZueAXsUQ2JsVrS9sj+QF9ecLZrzEC8GQm oiF/C1oG/JGj1SgfSd7bnomrs6NJeyyLLGk2h/sa4Sw62+ZY+eD0QC99NL8EbMR541gc zKLgdcPl5XXaSaFtAzQQmpM0WHKl9C0r41Wvc4dSzAaiQcnB7Ay3B2cjUD9o/9qcxPPs Kr7aFTEOrJM6MZgC2P31HnCBKps5w7y62nSTcoMyq+JYq/iwOcL0cpxcxkrM5NujLyQT 94YqxZjCLxhHfJIhN6yPGfCfzCOlwdQ0riyOOCS9ZcdZpz1JWR1AdwRBqFy77woGNKvK AekA== X-Gm-Message-State: AC+VfDymqa7u8WxG9TCE7u2cg1iFfNpD1mnDmef97W4ijAMlYyJed7JI wqY8bHF24ChkEsxlPE4wm4AAuSovCKQGYyNyWKmKfOCQz0wqnUQKQ8miZxoDTB0Iz0HLjh88aVo iqUqcAtw3eMQo6pFMOrLyfnWMyRQvVOuQVVPeQlGLzuaY X-Received: by 2002:a17:907:168c:b0:973:dd61:d427 with SMTP id hc12-20020a170907168c00b00973dd61d427mr7032352ejc.66.1685686250829; Thu, 01 Jun 2023 23:10:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ76NIRInV3K3D5Y17ZEP+iAeKiBhb75o8/w/JkYnksKO1733FgmimFAbKJE2id/GLeqweUur+R/7I9WGnvFS70= X-Received: by 2002:a17:907:168c:b0:973:dd61:d427 with SMTP id hc12-20020a170907168c00b00973dd61d427mr7032334ejc.66.1685686250464; Thu, 01 Jun 2023 23:10:50 -0700 (PDT) MIME-Version: 1.0 References: <20230601155556.104745-1-fberat@redhat.com> In-Reply-To: From: Frederic Berat Date: Fri, 2 Jun 2023 08:10:39 +0200 Message-ID: Subject: Re: [PATCH] Move {read,write}_all functions to a dedicated header To: Siddhesh Poyarekar Cc: libc-alpha@sourceware.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,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 Thu, Jun 1, 2023 at 7:08=E2=80=AFPM Siddhesh Poyarekar wrote: > > On 2023-06-01 11:55, Fr=C3=A9d=C3=A9ric B=C3=A9rat 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.10474= 5-1-fberat@redhat.com/ > Arf, I will take note for later :( > > > > 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 =3D buffer; > > - const char *end =3D p + length; > > - while (p < end) > > - { > > - ssize_t ret =3D 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 =3D=3D 0) > > - error (EXIT_FAILURE, 0, > > - gettext ("write returned 0 after writing %td bytes of %zu"= ), > > - p - (const char *) buffer, length); > > - p +=3D 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. > What's the rule for that ? It's a bit confusing since there isn't a copyright header in most of the headers in "include", so I assumed it didn't need it. > > @@ -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 =3D buffer; > > + const char *end =3D p + length; > > + while (p < end) > > + { > > + ssize_t ret =3D 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 =3D=3D 0) > > + error (EXIT_FAILURE, 0, > > + gettext ("write returned 0 after writing %td bytes of %zu"= ), > > + p - (const char *) buffer, length); > > + p +=3D ret; > > + } > > +} > > + > > +static inline void > > +read_all (int fd, void *buffer, size_t length) > > +{ > > + char *p =3D buffer; > > + char *end =3D p + length; > > + while (p < end) > > + { > > + ssize_t ret =3D 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 +=3D 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? > Nothing breaks if I keep these headers. I actually removed them because they were added in the patch that introduced write_all/read_all. Since I moved write/read_all in the header, I removed the headers that were introduced with them, but I admit I didn't check if they were actually missing before that. > > #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 =3D buffer; > > - const char *end =3D p + length; > > - while (p < end) > > - { > > - ssize_t ret =3D 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 =3D=3D 0) > > - error (EXIT_FAILURE, 0, > > - gettext ("write returned 0 after writing %td bytes of %zu"= ), > > - p - (const char *) buffer, length); > > - p +=3D 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 =3D 0; > > > > > > -static void > > -read_all (int fd, void *buffer, size_t length) > > -{ > > - char *p =3D buffer; > > - char *end =3D p + length; > > - while (p < end) > > - { > > - ssize_t ret =3D 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 +=3D ret; > > - } > > -} > > - > > -static void > > -write_all (int fd, const void *buffer, size_t length) > > -{ > > - const char *p =3D buffer; > > - const char *end =3D p + length; > > - while (p < end) > > - { > > - ssize_t ret =3D 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 =3D=3D 0) > > - error (EXIT_FAILURE, 0, > > - gettext ("write returned 0 after writing %td bytes of %zu"= ), > > - p - (const char *) buffer, length); > > - p +=3D ret; > > - } > > -} > > - > > - > > int > > main (int argc, char *argv[]) > > { >