From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.kapsi.fi (mail.kapsi.fi [IPv6:2001:67c:1be8::25]) by sourceware.org (Postfix) with ESMTPS id 145FC38582A3 for ; Wed, 30 Aug 2023 09:16:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 145FC38582A3 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sourceware.mail.kapsi.fi Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kapsi.fi DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kapsi.fi; s=20161220; h=Subject:Content-Transfer-Encoding:Content-Type:Message-ID:To: From:Date:MIME-Version:Sender:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=VJqxbeYU/nlpuGUe7nJ/ZMCNkfhju4sjLFpnwE2MW8k=; b=klppmzbv3csvUMzyZccaRIEWJZ KUpzCczt0o/pgBknbneM0KibN8DR9v3uft4GkD87mkdlSl6FGYiHrobhXfmhSoQ34jpKf/K7TZfuv 9QOq4PLF+WMJBRe4alpEe/IsI51A0QsPqWUQmHwcsfsBGFgcwQNRQSZTpv9QEXZR774sd8Rob7yOI 7wNurlEe95O18aWf479Blf3NkXnbKIXkoF+ZmIXW6ZwgxwqFTqFRQw+PHIv5KebQkg+7jZ+H8NEV4 3ag51wL/ojK1j1WVHPArzRQTmVwqc1LuZ4rcRG43/vGslj9exJtZTevvXNQY0XN1TAbKDvCAyCF8+ ZAD1jICg==; Received: from [2001:67c:1be8::200] (helo=roundcube.kapsi.fi) by mail.kapsi.fi with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1qbHJL-00D1CJ-11 for newlib@sourceware.org; Wed, 30 Aug 2023 12:16:27 +0300 MIME-Version: 1.0 Date: Wed, 30 Aug 2023 12:16:26 +0300 From: =?UTF-8?Q?Pekka_Sepp=C3=A4nen?= To: newlib@sourceware.org Message-ID: X-Sender: pexu@sourceware.mail.kapsi.fi Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 2001:67c:1be8::200 X-SA-Exim-Mail-From: pexu@sourceware.mail.kapsi.fi X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-Spam-Level: X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH 1/3] Reentrancy, use _REENT_ERRNO() X-SA-Exim-Version: 4.2.1 (built Wed, 06 Jul 2022 17:57:39 +0000) X-SA-Exim-Scanned: Yes (on mail.kapsi.fi) List-Id: Use _REENT_ERRNO() macro to access errno. This encapsulation is required, as errno might be either _errno member of struct _reent, _tls_errno or any such implementation detail. --- newlib/libc/locale/locale.c | 18 +++++++++--------- newlib/libc/locale/newlocale.c | 6 +++--- newlib/libc/stdlib/_mallocr.c | 2 +- newlib/libc/stdlib/nano-mallocr.c | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/newlib/libc/locale/locale.c b/newlib/libc/locale/locale.c index 3772106e3..b16ec1511 100644 --- a/newlib/libc/locale/locale.c +++ b/newlib/libc/locale/locale.c @@ -317,7 +317,7 @@ _setlocale_r (struct _reent *p, if (category < LC_ALL || category >= _LC_LAST) { - p->_errno = EINVAL; + _REENT_ERRNO(p) = EINVAL; return NULL; } @@ -343,7 +343,7 @@ _setlocale_r (struct _reent *p, env = __get_locale_env (p, i); if (strlen (env) > ENCODING_LEN) { - p->_errno = EINVAL; + _REENT_ERRNO(p) = EINVAL; return NULL; } strcpy (new_categories[i], env); @@ -354,7 +354,7 @@ _setlocale_r (struct _reent *p, env = __get_locale_env (p, category); if (strlen (env) > ENCODING_LEN) { - p->_errno = EINVAL; + _REENT_ERRNO(p) = EINVAL; return NULL; } strcpy (new_categories[category], env); @@ -364,7 +364,7 @@ _setlocale_r (struct _reent *p, { if (strlen (locale) > ENCODING_LEN) { - p->_errno = EINVAL; + _REENT_ERRNO(p) = EINVAL; return NULL; } strcpy (new_categories[category], locale); @@ -375,7 +375,7 @@ _setlocale_r (struct _reent *p, { if (strlen (locale) > ENCODING_LEN) { - p->_errno = EINVAL; + _REENT_ERRNO(p) = EINVAL; return NULL; } for (i = 1; i < _LC_LAST; ++i) @@ -387,7 +387,7 @@ _setlocale_r (struct _reent *p, ; if (!r[1]) { - p->_errno = EINVAL; + _REENT_ERRNO(p) = EINVAL; return NULL; /* Hmm, just slashes... */ } do @@ -396,7 +396,7 @@ _setlocale_r (struct _reent *p, break; /* Too many slashes... */ if ((len = r - locale) > ENCODING_LEN) { - p->_errno = EINVAL; + _REENT_ERRNO(p) = EINVAL; return NULL; } strlcpy (new_categories[i], locale, len + 1); @@ -429,7 +429,7 @@ _setlocale_r (struct _reent *p, strcpy (saved_categories[i], __get_global_locale ()->categories[i]); if (__loadlocale (__get_global_locale (), i, new_categories[i]) == NULL) { - saverr = p->_errno; + saverr = _REENT_ERRNO(p); for (j = 1; j < i; j++) { strcpy (new_categories[j], saved_categories[j]); @@ -440,7 +440,7 @@ _setlocale_r (struct _reent *p, __loadlocale (__get_global_locale (), j, new_categories[j]); } } - p->_errno = saverr; + _REENT_ERRNO(p) = saverr; return NULL; } } diff --git a/newlib/libc/locale/newlocale.c b/newlib/libc/locale/newlocale.c index 278f78ed2..92f9e0a9c 100644 --- a/newlib/libc/locale/newlocale.c +++ b/newlib/libc/locale/newlocale.c @@ -103,7 +103,7 @@ _newlocale_r (struct _reent *p, int category_mask, const char *locale, /* Check for invalid mask values and valid locale ptr. */ if ((category_mask & ~LC_VALID_MASK) || !locale) { - p->_errno = EINVAL; + _REENT_ERRNO(p) = EINVAL; return NULL; } /* If the new locale is supposed to be all default locale, just return @@ -125,7 +125,7 @@ _newlocale_r (struct _reent *p, int category_mask, const char *locale, : locale; if (strlen (cat) > ENCODING_LEN) { - p->_errno = EINVAL; + _REENT_ERRNO(p) = EINVAL; return NULL; } strcpy (new_categories[i], cat); @@ -172,7 +172,7 @@ _newlocale_r (struct _reent *p, int category_mask, const char *locale, /* Otherwise load locale data. */ else if (!__loadlocale (&tmp_locale, i, new_categories[i])) { - p->_errno = ENOENT; + _REENT_ERRNO(p) = ENOENT; goto error; } } diff --git a/newlib/libc/stdlib/_mallocr.c b/newlib/libc/stdlib/_mallocr.c index 1997b6db1..c73982c18 100644 --- a/newlib/libc/stdlib/_mallocr.c +++ b/newlib/libc/stdlib/_mallocr.c @@ -346,7 +346,7 @@ extern void __malloc_unlock(); #define RDECL struct _reent *reent_ptr; #endif -#define RERRNO reent_ptr->_errno +#define RERRNO _REENT_ERRNO(reent_ptr) #define RCALL reent_ptr, #define RONECALL reent_ptr diff --git a/newlib/libc/stdlib/nano-mallocr.c b/newlib/libc/stdlib/nano-mallocr.c index 41e69abb0..030be44ad 100644 --- a/newlib/libc/stdlib/nano-mallocr.c +++ b/newlib/libc/stdlib/nano-mallocr.c @@ -64,7 +64,7 @@ #define MALLOC_LOCK __malloc_lock(reent_ptr) #define MALLOC_UNLOCK __malloc_unlock(reent_ptr) -#define RERRNO reent_ptr->_errno +#define RERRNO _REENT_ERRNO(reent_ptr) #define nano_malloc _malloc_r #define nano_free _free_r -- 2.34.1