From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1921) id 3B9AB3857438; Mon, 11 Sep 2023 08:04:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B9AB3857438 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1694419461; bh=e1hkvS3Lv9sgiZ2u9Czylt8ox8C/Ukc5DKwN6c6i0Mg=; h=From:To:Subject:Date:From; b=bcl+pFgy5ggua4MTbT7ZaMtzzURucKI67bczHF3agZxxjVKa9KxhUM9AVny7VlHHh pH/JdmLcjtKG7M5BNeDEmbl9qP65lInlS3rr+YbyD5x7kGyNDfZLSGVbdPYleOG3Yd yLYwjgi+iIF5jKxnhj4vUr5XiUzI7l4m3rflxBBU= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Sebastian Huber To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] Reentrancy, use _REENT_ERRNO() X-Act-Checkin: newlib-cygwin X-Git-Author: =?utf-8?q?Pekka_Sepp=C3=A4nen?= X-Git-Refname: refs/heads/master X-Git-Oldrev: f5e37b93a02508e79fbeceaa7b45b1febd44b233 X-Git-Newrev: 766f1beb4de3d75f3b6d25dcc9b41dc8b4a002e9 Message-Id: <20230911080421.3B9AB3857438@sourceware.org> Date: Mon, 11 Sep 2023 08:04:21 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D766f1beb4de= 3d75f3b6d25dcc9b41dc8b4a002e9 commit 766f1beb4de3d75f3b6d25dcc9b41dc8b4a002e9 Author: Pekka Sepp=C3=A4nen Date: Wed Aug 30 12:16:26 2023 +0300 Reentrancy, use _REENT_ERRNO() =20 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. Diff: --- 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, =20 if (category < LC_ALL || category >=3D _LC_LAST) { - p->_errno =3D EINVAL; + _REENT_ERRNO(p) =3D EINVAL; return NULL; } =20 @@ -343,7 +343,7 @@ _setlocale_r (struct _reent *p, env =3D __get_locale_env (p, i); if (strlen (env) > ENCODING_LEN) { - p->_errno =3D EINVAL; + _REENT_ERRNO(p) =3D EINVAL; return NULL; } strcpy (new_categories[i], env); @@ -354,7 +354,7 @@ _setlocale_r (struct _reent *p, env =3D __get_locale_env (p, category); if (strlen (env) > ENCODING_LEN) { - p->_errno =3D EINVAL; + _REENT_ERRNO(p) =3D EINVAL; return NULL; } strcpy (new_categories[category], env); @@ -364,7 +364,7 @@ _setlocale_r (struct _reent *p, { if (strlen (locale) > ENCODING_LEN) { - p->_errno =3D EINVAL; + _REENT_ERRNO(p) =3D EINVAL; return NULL; } strcpy (new_categories[category], locale); @@ -375,7 +375,7 @@ _setlocale_r (struct _reent *p, { if (strlen (locale) > ENCODING_LEN) { - p->_errno =3D EINVAL; + _REENT_ERRNO(p) =3D EINVAL; return NULL; } for (i =3D 1; i < _LC_LAST; ++i) @@ -387,7 +387,7 @@ _setlocale_r (struct _reent *p, ; if (!r[1]) { - p->_errno =3D EINVAL; + _REENT_ERRNO(p) =3D EINVAL; return NULL; /* Hmm, just slashes... */ } do @@ -396,7 +396,7 @@ _setlocale_r (struct _reent *p, break; /* Too many slashes... */ if ((len =3D r - locale) > ENCODING_LEN) { - p->_errno =3D EINVAL; + _REENT_ERRNO(p) =3D 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]) =3D= =3D NULL) { - saverr =3D p->_errno; + saverr =3D _REENT_ERRNO(p); for (j =3D 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 =3D saverr; + _REENT_ERRNO(p) =3D 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, cons= t char *locale, /* Check for invalid mask values and valid locale ptr. */ if ((category_mask & ~LC_VALID_MASK) || !locale) { - p->_errno =3D EINVAL; + _REENT_ERRNO(p) =3D 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, cons= t char *locale, : locale; if (strlen (cat) > ENCODING_LEN) { - p->_errno =3D EINVAL; + _REENT_ERRNO(p) =3D EINVAL; return NULL; } strcpy (new_categories[i], cat); @@ -172,7 +172,7 @@ _newlocale_r (struct _reent *p, int category_mask, cons= t char *locale, /* Otherwise load locale data. */ else if (!__loadlocale (&tmp_locale, i, new_categories[i])) { - p->_errno =3D ENOENT; + _REENT_ERRNO(p) =3D 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 =20 -#define RERRNO reent_ptr->_errno +#define RERRNO _REENT_ERRNO(reent_ptr) #define RCALL reent_ptr, #define RONECALL reent_ptr =20 diff --git a/newlib/libc/stdlib/nano-mallocr.c b/newlib/libc/stdlib/nano-ma= llocr.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) =20 -#define RERRNO reent_ptr->_errno +#define RERRNO _REENT_ERRNO(reent_ptr) =20 #define nano_malloc _malloc_r #define nano_free _free_r