public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: "Pekka Seppänen" <pexu@sourceware.mail.kapsi.fi>
To: newlib@sourceware.org
Subject: [PATCH 1/3] Reentrancy, use _REENT_ERRNO()
Date: Wed, 30 Aug 2023 12:16:26 +0300	[thread overview]
Message-ID: <e34548957a2ff3c4267765a2538928ad@sourceware.mail.kapsi.fi> (raw)

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

                 reply	other threads:[~2023-08-30  9:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e34548957a2ff3c4267765a2538928ad@sourceware.mail.kapsi.fi \
    --to=pexu@sourceware.mail.kapsi.fi \
    --cc=newlib@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).