From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id F14DA385695D for ; Tue, 21 Jun 2022 12:49:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F14DA385695D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy02.your-server.de ([78.47.166.47]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1o3dK8-0003Zj-At for newlib@sourceware.org; Tue, 21 Jun 2022 14:49:40 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy02.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o3dK8-000Llh-Hz for newlib@sourceware.org; Tue, 21 Jun 2022 14:49:40 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 4337D480136 for ; Tue, 21 Jun 2022 14:49:35 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id tM5wWssxHWzB for ; Tue, 21 Jun 2022 14:49:35 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id DDAB74801DC for ; Tue, 21 Jun 2022 14:49:34 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 6UpfIfWcz2Eb for ; Tue, 21 Jun 2022 14:49:34 +0200 (CEST) Received: from zimbra.eb.localhost (unknown [192.168.96.242]) by mail.embedded-brains.de (Postfix) with ESMTPSA id A394F4800AD for ; Tue, 21 Jun 2022 14:49:34 +0200 (CEST) From: Sebastian Huber To: newlib@sourceware.org Subject: [PATCH 11/14] Add _REENT_CVTBUF(ptr) Date: Tue, 21 Jun 2022 14:49:28 +0200 Message-Id: <20220621124931.36450-12-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220621124931.36450-1-sebastian.huber@embedded-brains.de> References: <20220621124931.36450-1-sebastian.huber@embedded-brains.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.103.6/26579/Tue Jun 21 10:15:30 2022) X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, 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 X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2022 12:49:43 -0000 From: Matt Joyce Add a _REENT_CVTBUF() macro to encapsulate access to the _cvtbuf member of struct reent. This will help to replace the struct member with a thread-local storage object in a follow up patch. --- newlib/libc/include/sys/reent.h | 1 + newlib/libc/reent/reent.c | 4 ++-- newlib/libc/stdlib/ecvtbuf.c | 12 ++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/re= ent.h index 8c88fae20..ef05dd8c9 100644 --- a/newlib/libc/include/sys/reent.h +++ b/newlib/libc/include/sys/reent.h @@ -719,6 +719,7 @@ struct _reent #endif /* !_REENT_SMALL */ =20 #define _REENT_CLEANUP(_ptr) ((_ptr)->__cleanup) +#define _REENT_CVTBUF(_ptr) ((_ptr)->_cvtbuf) #define _REENT_CVTLEN(_ptr) ((_ptr)->_cvtlen) #define _REENT_EMERGENCY(_ptr) ((_ptr)->_emergency) #define _REENT_ERRNO(_ptr) ((_ptr)->_errno) diff --git a/newlib/libc/reent/reent.c b/newlib/libc/reent/reent.c index 16ac04e22..2cfec5363 100644 --- a/newlib/libc/reent/reent.c +++ b/newlib/libc/reent/reent.c @@ -78,8 +78,8 @@ _reclaim_reent (struct _reent *ptr) _free_r (ptr, ptr->_misc); #endif =20 - if (ptr->_cvtbuf) - _free_r (ptr, ptr->_cvtbuf); + if (_REENT_CVTBUF(ptr)) + _free_r (ptr, _REENT_CVTBUF(ptr)); /* We should free _sig_func to avoid a memory leak, but how to do it safely considering that a signal may be delivered immediately after the free? diff --git a/newlib/libc/stdlib/ecvtbuf.c b/newlib/libc/stdlib/ecvtbuf.c index 0e776ab65..05f315108 100644 --- a/newlib/libc/stdlib/ecvtbuf.c +++ b/newlib/libc/stdlib/ecvtbuf.c @@ -232,14 +232,14 @@ fcvtbuf (double invalue, { if (_REENT_CVTLEN(reent) <=3D ndigit + 35) { - if ((fcvt_buf =3D (char *) _realloc_r (reent, reent->_cvtbuf, + if ((fcvt_buf =3D (char *) _realloc_r (reent, _REENT_CVTBUF(reent), ndigit + 36)) =3D=3D NULL) return NULL; _REENT_CVTLEN(reent) =3D ndigit + 36; - reent->_cvtbuf =3D fcvt_buf; + _REENT_CVTBUF(reent) =3D fcvt_buf; } =20 - fcvt_buf =3D reent->_cvtbuf ; + fcvt_buf =3D _REENT_CVTBUF(reent) ; } =20 save =3D fcvt_buf; @@ -281,14 +281,14 @@ ecvtbuf (double invalue, { if (_REENT_CVTLEN(reent) <=3D ndigit) { - if ((fcvt_buf =3D (char *) _realloc_r (reent, reent->_cvtbuf, + if ((fcvt_buf =3D (char *) _realloc_r (reent, _REENT_CVTBUF(reent), ndigit + 1)) =3D=3D NULL) return NULL; _REENT_CVTLEN(reent) =3D ndigit + 1; - reent->_cvtbuf =3D fcvt_buf; + _REENT_CVTBUF(reent) =3D fcvt_buf; } =20 - fcvt_buf =3D reent->_cvtbuf ; + fcvt_buf =3D _REENT_CVTBUF(reent) ; } =20 save =3D fcvt_buf; --=20 2.35.3