This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Use local variable for _REENT


On 04/27/2013 11:54 AM, Joel Sherrill wrote:
This is certainly the portable and IMO most clear way to
do this.


I agree and have checked in the patch.

But if we assume GCC (are we allowed to do that in newlib),
would the function attribute "const" on __getreent() accomplish
the goal?

This requires two assumptions:

(1) GCC to work right all the time. :)
(2) Similar feature/optimization required for other compilers.

Honestly, I don't mind this change. It is very much in line
with how RTEMS is coded.  Explicitly do things only once,
cache them in a local variable, and don't assume the compiler
will magically know only the first time is needed.

--joel

On 4/26/2013 3:21 AM, Sebastian Huber wrote:
If we use __DYNAMIC_REENT__, then a global function __getreent() will be
used to obtain the current reent pointer.  The compiler cannot optimize
these calls away.  Use a local variable to prevent multiple calls to
__getreent() in one context.

newlib/ChangeLog
2013-04-26  Sebastian Huber <sebastian.huber@embedded-brains.de>

         * libc/stdio/local.h (CHECK_INIT): Evaluate argument only once.
         (CHECK_STD_INIT): Likewise.
         * libc/stdio/fgetc.c (fgetc): Use local variable for _REENT.
         * libc/stdio/fgetwc.c (fwgetc): Likewise.
         * libc/stdio/fgetws.c (fgetws): Likewise.
         * libc/stdio/fputc.c (fputc): Likewise.
         * libc/stdio/fputwc.c (fputwc): Likewise.
         * libc/stdio/fputws.c (fputws): Likewise.
         * libc/stdio/getc.c (getc): Likewise.
         * libc/stdio/getchar.c (_getchar_r): Likewise.
         * libc/stdio/putc.c (putc): Likewise.
         * libc/stdio/putchar.c (putchar): Likewise.
         * libc/stdio/scanf.c (scanf): Likewise.
         * libc/stdio/setvbuf.c (setvbuf): Likewise.
         * libc/stdio/ungetwc.c (ungetwc): Likewise.
         * libc/stdio/vfscanf.c (VFSCANF): Likewise.
         * libc/stdio/vfwscanf.c (VFWSCANF): Likewise.
         * libc/stdio/viprintf.c (viprintf): Likewise.
         * libc/stdio/viscanf.c (viscanf): Likewise.
         * libc/stdio/vprintf.c (vprintf): Likewise.
         * libc/stdio/vscanf.c (vscanf): Likewise.
         * libc/stdio/vwprintf.c (vwprintf): Likewise.
         * libc/stdio/vwscanf.c (vwscanf): Likewise.
         * libc/stdio/wscanf.c (wscanf): Likewise.
         * libc/stdlib/ecvtbuf.c (fcvtbuf): Likewise.
         (fcvtbuf): Likewise.
         (ecvtbuf): Likewise.
         (ecvtbuf): Likewise.
         * libc/stdlib/mblen.c (mblen): Likewise.
         * libc/stdlib/mbrlen.c (mbrlen): Likewise.
         * libc/stdlib/mbrtowc.c (mbrtowc): Likewise.
         * libc/stdlib/mbtowc.c (mbtowc): Likewise.
         * libc/stdlib/rand.c (srand): Likewise.
         (rand): Likewise.
         * libc/stdlib/wcrtomb.c (wcrtomb): Likewise.
         * libc/stdlib/wctob.c (wctob): Likewise.
         * libc/stdlib/wctomb.c (wctomb): Likewise.
         * libc/string/strtok.c (strtok): Likewise.
         * libc/time/asctime.c (asctime): Likewise.
         * libc/time/gmtime.c (gmtime): Likewise.
         * libc/time/lcltime.c (lcltime): Likewise.
---
  newlib/libc/stdio/fgetc.c    |    6 +++-
  newlib/libc/stdio/fgetwc.c   |    6 +++-
  newlib/libc/stdio/fgetws.c   |    6 +++-
  newlib/libc/stdio/fputc.c    |    6 +++-
  newlib/libc/stdio/fputwc.c   |    6 +++-
  newlib/libc/stdio/fputws.c   |    6 +++-
  newlib/libc/stdio/getc.c     |    6 +++-
  newlib/libc/stdio/getchar.c  |    6 +++-
  newlib/libc/stdio/local.h    |   45
++++++++++++++++++++++-------------------
  newlib/libc/stdio/putc.c     |    6 +++-
  newlib/libc/stdio/putchar.c  |    6 +++-
  newlib/libc/stdio/scanf.c    |    5 ++-
  newlib/libc/stdio/setvbuf.c  |    9 ++++---
  newlib/libc/stdio/ungetwc.c  |    6 +++-
  newlib/libc/stdio/vfscanf.c  |    6 +++-
  newlib/libc/stdio/vfwscanf.c |    6 +++-
  newlib/libc/stdio/viprintf.c |    6 +++-
  newlib/libc/stdio/viscanf.c  |    6 +++-
  newlib/libc/stdio/vprintf.c  |    6 +++-
  newlib/libc/stdio/vscanf.c   |    6 +++-
  newlib/libc/stdio/vwprintf.c |    6 +++-
  newlib/libc/stdio/vwscanf.c  |    6 +++-
  newlib/libc/stdio/wscanf.c   |    5 ++-
  newlib/libc/stdlib/ecvtbuf.c |   28 ++++++++++++++------------
  newlib/libc/stdlib/mblen.c   |    7 +++--
  newlib/libc/stdlib/mbrlen.c  |    6 +++-
  newlib/libc/stdlib/mbrtowc.c |   11 +++++----
  newlib/libc/stdlib/mbtowc.c  |    7 +++--
  newlib/libc/stdlib/rand.c    |   16 +++++++++-----
  newlib/libc/stdlib/wcrtomb.c |   11 +++++----
  newlib/libc/stdlib/wctob.c   |    6 +++-
  newlib/libc/stdlib/wctomb.c  |    8 ++++--
  newlib/libc/string/strtok.c  |    6 +++-
  newlib/libc/time/asctime.c   |    6 +++-
  newlib/libc/time/gmtime.c    |    6 +++-
  newlib/libc/time/lcltime.c   |    6 +++-
  36 files changed, 185 insertions(+), 117 deletions(-)

diff --git a/newlib/libc/stdio/fgetc.c b/newlib/libc/stdio/fgetc.c
index 99d8330..20492d2 100644
--- a/newlib/libc/stdio/fgetc.c
+++ b/newlib/libc/stdio/fgetc.c
@@ -92,9 +92,11 @@ _DEFUN(fgetc, (fp),
  {
  #if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
    int result;
-  CHECK_INIT(_REENT, fp);
+  struct _reent *reent = _REENT;
+
+  CHECK_INIT(reent, fp);
    _newlib_flockfile_start (fp);
-  result = __sgetc_r (_REENT, fp);
+  result = __sgetc_r (reent, fp);
    _newlib_flockfile_end (fp);
    return result;
  #else
diff --git a/newlib/libc/stdio/fgetwc.c b/newlib/libc/stdio/fgetwc.c
index 0eaaecb..14c5547 100644
--- a/newlib/libc/stdio/fgetwc.c
+++ b/newlib/libc/stdio/fgetwc.c
@@ -175,6 +175,8 @@ wint_t
  _DEFUN(fgetwc, (fp),
         FILE *fp)
  {
-  CHECK_INIT(_REENT, fp);
-  return _fgetwc_r (_REENT, fp);
+  struct _reent *reent = _REENT;
+
+  CHECK_INIT(reent, fp);
+  return _fgetwc_r (reent, fp);
  }
diff --git a/newlib/libc/stdio/fgetws.c b/newlib/libc/stdio/fgetws.c
index 3cf45a9..b5d8851 100644
--- a/newlib/libc/stdio/fgetws.c
+++ b/newlib/libc/stdio/fgetws.c
@@ -160,6 +160,8 @@ _DEFUN(fgetws, (ws, n, fp),
         int n _AND
         FILE *fp)
  {
-  CHECK_INIT (_REENT, fp);
-  return _fgetws_r (_REENT, ws, n, fp);
+  struct _reent *reent = _REENT;
+
+  CHECK_INIT (reent, fp);
+  return _fgetws_r (reent, ws, n, fp);
  }
diff --git a/newlib/libc/stdio/fputc.c b/newlib/libc/stdio/fputc.c
index 6af79d4..f380717 100644
--- a/newlib/libc/stdio/fputc.c
+++ b/newlib/libc/stdio/fputc.c
@@ -97,9 +97,11 @@ _DEFUN(fputc, (ch, file),
  {
  #if !defined(__OPTIMIZE_SIZE__) && !defined(PREFER_SIZE_OVER_SPEED)
    int result;
-  CHECK_INIT(_REENT, file);
+  struct _reent *reent = _REENT;
+
+  CHECK_INIT(reent, file);
     _newlib_flockfile_start (file);
-  result = _putc_r (_REENT, ch, file);
+  result = _putc_r (reent, ch, file);
    _newlib_flockfile_end (file);
    return result;
  #else
diff --git a/newlib/libc/stdio/fputwc.c b/newlib/libc/stdio/fputwc.c
index 74e7a45..5ec85d1 100644
--- a/newlib/libc/stdio/fputwc.c
+++ b/newlib/libc/stdio/fputwc.c
@@ -172,6 +172,8 @@ _DEFUN(fputwc, (wc, fp),
         wchar_t wc _AND
         FILE *fp)
  {
-  CHECK_INIT(_REENT, fp);
-  return _fputwc_r (_REENT, wc, fp);
+  struct _reent *reent = _REENT;
+
+  CHECK_INIT(reent, fp);
+  return _fputwc_r (reent, wc, fp);
  }
diff --git a/newlib/libc/stdio/fputws.c b/newlib/libc/stdio/fputws.c
index 0893b3c..a28a555 100644
--- a/newlib/libc/stdio/fputws.c
+++ b/newlib/libc/stdio/fputws.c
@@ -145,6 +145,8 @@ _DEFUN(fputws, (ws, fp),
         const wchar_t *ws _AND
         FILE *fp)
  {
-  CHECK_INIT (_REENT, fp);
-  return _fputws_r (_REENT, ws, fp);
+  struct _reent *reent = _REENT;
+
+  CHECK_INIT (reent, fp);
+  return _fputws_r (reent, ws, fp);
  }
diff --git a/newlib/libc/stdio/getc.c b/newlib/libc/stdio/getc.c
index 355b191..7951cdc 100644
--- a/newlib/libc/stdio/getc.c
+++ b/newlib/libc/stdio/getc.c
@@ -105,9 +105,11 @@ _DEFUN(getc, (fp),
         register FILE *fp)
  {
    int result;
-  CHECK_INIT (_REENT, fp);
+  struct _reent *reent = _REENT;
+
+  CHECK_INIT (reent, fp);
    _newlib_flockfile_start (fp);
-  result = __sgetc_r (_REENT, fp);
+  result = __sgetc_r (reent, fp);
    _newlib_flockfile_end (fp);
    return result;
  }
diff --git a/newlib/libc/stdio/getchar.c b/newlib/libc/stdio/getchar.c
index da2f5df..7f3ceac 100644
--- a/newlib/libc/stdio/getchar.c
+++ b/newlib/libc/stdio/getchar.c
@@ -91,9 +91,11 @@ _DEFUN(_getchar_r, (reent),
  int
  _DEFUN_VOID(getchar)
  {
+  struct _reent *reent = _REENT;
+
    /* CHECK_INIT is called (eventually) by __srefill_r.  */
-  _REENT_SMALL_CHECK_INIT (_REENT);
-  return _getc_r (_REENT, _stdin_r (_REENT));
+  _REENT_SMALL_CHECK_INIT (reent);
+  return _getc_r (reent, _stdin_r (reent));
  }

  #endif
diff --git a/newlib/libc/stdio/local.h b/newlib/libc/stdio/local.h
index ec5efab..54854b4 100644
--- a/newlib/libc/stdio/local.h
+++ b/newlib/libc/stdio/local.h
@@ -175,34 +175,37 @@ extern _READ_WRITE_RETURN_TYPE
_EXFUN(__swrite64,(struct _reent *, void *,

  #ifdef _REENT_SMALL
  #define CHECK_INIT(ptr, fp) \
-  do                                           \
-    {                                          \
-      if ((ptr) && !(ptr)->__sdidinit)         \
-       __sinit (ptr);                          \
-      if ((fp) == (FILE *)&__sf_fake_stdin)    \
-       (fp) = _stdin_r(ptr);                   \
-      else if ((fp) == (FILE *)&__sf_fake_stdout) \
-       (fp) = _stdout_r(ptr);                  \
-      else if ((fp) == (FILE *)&__sf_fake_stderr) \
-       (fp) = _stderr_r(ptr);                  \
-    }                                          \
+  do                                                           \
+    {                                                          \
+      struct _reent *_check_init_ptr = (ptr);                  \
+      if ((_check_init_ptr) && !(_check_init_ptr)->__sdidinit) \
+       __sinit (_check_init_ptr);                              \
+      if ((fp) == (FILE *)&__sf_fake_stdin)                    \
+       (fp) = _stdin_r(_check_init_ptr);                       \
+      else if ((fp) == (FILE *)&__sf_fake_stdout)              \
+       (fp) = _stdout_r(_check_init_ptr);                      \
+      else if ((fp) == (FILE *)&__sf_fake_stderr)              \
+       (fp) = _stderr_r(_check_init_ptr);                      \
+    }                                                          \
    while (0)
  #else /* !_REENT_SMALL   */
  #define CHECK_INIT(ptr, fp) \
-  do                                           \
-    {                                          \
-      if ((ptr) && !(ptr)->__sdidinit)         \
-       __sinit (ptr);                          \
-    }                                          \
+  do                                                           \
+    {                                                          \
+      struct _reent *_check_init_ptr = (ptr);                  \
+      if ((_check_init_ptr) && !(_check_init_ptr)->__sdidinit) \
+       __sinit (_check_init_ptr);                              \
+    }                                                          \
    while (0)
  #endif /* !_REENT_SMALL  */

  #define CHECK_STD_INIT(ptr) \
-  do                                           \
-    {                                          \
-      if ((ptr) && !(ptr)->__sdidinit)         \
-       __sinit (ptr);                          \
-    }                                          \
+  do                                                           \
+    {                                                          \
+      struct _reent *_check_init_ptr = (ptr);                  \
+      if ((_check_init_ptr) && !(_check_init_ptr)->__sdidinit) \
+       __sinit (_check_init_ptr);                              \
+    }                                                          \
    while (0)

  /* Return true and set errno and stream error flag iff the given FILE
diff --git a/newlib/libc/stdio/putc.c b/newlib/libc/stdio/putc.c
index 1115bf4..2b1fd1b 100644
--- a/newlib/libc/stdio/putc.c
+++ b/newlib/libc/stdio/putc.c
@@ -111,9 +111,11 @@ _DEFUN(putc, (c, fp),
  {
  #if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
    int result;
-  CHECK_INIT (_REENT, fp);
+  struct _reent *reent = _REENT;
+
+  CHECK_INIT (reent, fp);
    _newlib_flockfile_start (fp);
-  result = __sputc_r (_REENT, c, fp);
+  result = __sputc_r (reent, c, fp);
    _newlib_flockfile_end (fp);
    return result;
  #else
diff --git a/newlib/libc/stdio/putchar.c b/newlib/libc/stdio/putchar.c
index 06bcbb4..bb27dc4 100644
--- a/newlib/libc/stdio/putchar.c
+++ b/newlib/libc/stdio/putchar.c
@@ -90,8 +90,10 @@ int
  _DEFUN(putchar, (c),
         int c)
  {
-  _REENT_SMALL_CHECK_INIT (_REENT);
-  return _putc_r (_REENT, c, _stdout_r (_REENT));
+  struct _reent *reent = _REENT;
+
+  _REENT_SMALL_CHECK_INIT (reent);
+  return _putc_r (reent, c, _stdout_r (reent));
  }

  #endif
diff --git a/newlib/libc/stdio/scanf.c b/newlib/libc/stdio/scanf.c
index 68fd8fb..19c85be 100644
--- a/newlib/libc/stdio/scanf.c
+++ b/newlib/libc/stdio/scanf.c
@@ -38,14 +38,15 @@ scanf(fmt, va_alist)
  {
    int ret;
    va_list ap;
+  struct _reent *reent = _REENT;

-  _REENT_SMALL_CHECK_INIT (_REENT);
+  _REENT_SMALL_CHECK_INIT (reent);
  #ifdef _HAVE_STDC
    va_start (ap, fmt);
  #else
    va_start (ap);
  #endif
-  ret = _vfscanf_r (_REENT, _stdin_r (_REENT), fmt, ap);
+  ret = _vfscanf_r (reent, _stdin_r (reent), fmt, ap);
    va_end (ap);
    return ret;
  }
diff --git a/newlib/libc/stdio/setvbuf.c b/newlib/libc/stdio/setvbuf.c
index 63f1f80..41bdff6 100644
--- a/newlib/libc/stdio/setvbuf.c
+++ b/newlib/libc/stdio/setvbuf.c
@@ -103,8 +103,9 @@ _DEFUN(setvbuf, (fp, buf, mode, size),
         register size_t size)
  {
    int ret = 0;
+  struct _reent *reent = _REENT;

-  CHECK_INIT (_REENT, fp);
+  CHECK_INIT (reent, fp);

    _newlib_flockfile_start (fp);

@@ -126,11 +127,11 @@ _DEFUN(setvbuf, (fp, buf, mode, size),
     * non buffer flags, and clear malloc flag.
     */

-  _fflush_r (_REENT, fp);
+  _fflush_r (reent, fp);
    fp->_r = 0;
    fp->_lbfsize = 0;
    if (fp->_flags & __SMBF)
-    _free_r (_REENT, (_PTR) fp->_bf._base);
+    _free_r (reent, (_PTR) fp->_bf._base);
    fp->_flags &= ~(__SLBF | __SNBF | __SMBF);

    if (mode == _IONBF)
@@ -180,7 +181,7 @@ nbf:

      case _IOFBF:
        /* no flag */
-      _REENT->__cleanup = _cleanup_r;
+      reent->__cleanup = _cleanup_r;
        fp->_bf._base = fp->_p = (unsigned char *) buf;
        fp->_bf._size = size;
        break;
diff --git a/newlib/libc/stdio/ungetwc.c b/newlib/libc/stdio/ungetwc.c
index ee0d7fc..a69449e 100644
--- a/newlib/libc/stdio/ungetwc.c
+++ b/newlib/libc/stdio/ungetwc.c
@@ -110,6 +110,8 @@ _DEFUN(ungetwc, (wint_t wc, FILE *fp),
         wint_t wc _AND
         FILE *fp)
  {
-  CHECK_INIT (_REENT, fp);
-  return _ungetwc_r (_REENT, wc, fp);
+  struct _reent *reent = _REENT;
+
+  CHECK_INIT (reent, fp);
+  return _ungetwc_r (reent, wc, fp);
  }
diff --git a/newlib/libc/stdio/vfscanf.c b/newlib/libc/stdio/vfscanf.c
index e967719..ae94cea 100644
--- a/newlib/libc/stdio/vfscanf.c
+++ b/newlib/libc/stdio/vfscanf.c
@@ -266,8 +266,10 @@ _DEFUN(VFSCANF, (fp, fmt, ap),
         _CONST char *fmt _AND
         va_list ap)
  {
-  CHECK_INIT(_REENT, fp);
-  return __SVFSCANF_R (_REENT, fp, fmt, ap);
+  struct _reent *reent = _REENT;
+
+  CHECK_INIT(reent, fp);
+  return __SVFSCANF_R (reent, fp, fmt, ap);
  }

  int
diff --git a/newlib/libc/stdio/vfwscanf.c b/newlib/libc/stdio/vfwscanf.c
index 5d2388d..3379b5e 100644
--- a/newlib/libc/stdio/vfwscanf.c
+++ b/newlib/libc/stdio/vfwscanf.c
@@ -258,8 +258,10 @@ _DEFUN(VFWSCANF, (fp, fmt, ap),
         _CONST wchar_t *fmt _AND
         va_list ap)
  {
-  CHECK_INIT(_REENT, fp);
-  return __SVFWSCANF_R (_REENT, fp, fmt, ap);
+  struct _reent *reent = _REENT;
+
+  CHECK_INIT(reent, fp);
+  return __SVFWSCANF_R (reent, fp, fmt, ap);
  }

  int
diff --git a/newlib/libc/stdio/viprintf.c b/newlib/libc/stdio/viprintf.c
index 3717f3a..fec92fa 100644
--- a/newlib/libc/stdio/viprintf.c
+++ b/newlib/libc/stdio/viprintf.c
@@ -109,8 +109,10 @@ _DEFUN(viprintf, (fmt, ap),
         _CONST char *fmt _AND
         va_list ap)
  {
-  _REENT_SMALL_CHECK_INIT (_REENT);
-  return _vfiprintf_r (_REENT, _stdout_r (_REENT), fmt, ap);
+  struct _reent *reent = _REENT;
+
+  _REENT_SMALL_CHECK_INIT (reent);
+  return _vfiprintf_r (reent, _stdout_r (reent), fmt, ap);
  }

  #endif /* !_REENT_ONLY */
diff --git a/newlib/libc/stdio/viscanf.c b/newlib/libc/stdio/viscanf.c
index a60c32f..9a7d0c5 100644
--- a/newlib/libc/stdio/viscanf.c
+++ b/newlib/libc/stdio/viscanf.c
@@ -127,8 +127,10 @@ _DEFUN(viscanf, (fmt, ap),
         _CONST char *fmt _AND
         va_list ap)
  {
-  _REENT_SMALL_CHECK_INIT (_REENT);
-  return __svfiscanf_r (_REENT, _stdin_r (_REENT), fmt, ap);
+  struct _reent *reent = _REENT;
+
+  _REENT_SMALL_CHECK_INIT (reent);
+  return __svfiscanf_r (reent, _stdin_r (reent), fmt, ap);
  }

  #endif /* !_REENT_ONLY */
diff --git a/newlib/libc/stdio/vprintf.c b/newlib/libc/stdio/vprintf.c
index 69edc87..3756569 100644
--- a/newlib/libc/stdio/vprintf.c
+++ b/newlib/libc/stdio/vprintf.c
@@ -33,8 +33,10 @@ _DEFUN(vprintf, (fmt, ap),
         _CONST char *fmt _AND
         va_list ap)
  {
-  _REENT_SMALL_CHECK_INIT (_REENT);
-  return _vfprintf_r (_REENT, _stdout_r (_REENT), fmt, ap);
+  struct _reent *reent = _REENT;
+
+  _REENT_SMALL_CHECK_INIT (reent);
+  return _vfprintf_r (reent, _stdout_r (reent), fmt, ap);
  }

  #endif /* !_REENT_ONLY */
diff --git a/newlib/libc/stdio/vscanf.c b/newlib/libc/stdio/vscanf.c
index e559b77..210774b 100644
--- a/newlib/libc/stdio/vscanf.c
+++ b/newlib/libc/stdio/vscanf.c
@@ -34,8 +34,10 @@ _DEFUN(vscanf, (fmt, ap),
         _CONST char *fmt _AND
         va_list ap)
  {
-  _REENT_SMALL_CHECK_INIT (_REENT);
-  return __svfscanf_r (_REENT, _stdin_r (_REENT), fmt, ap);
+  struct _reent *reent = _REENT;
+
+  _REENT_SMALL_CHECK_INIT (reent);
+  return __svfscanf_r (reent, _stdin_r (reent), fmt, ap);
  }

  #endif /* !_REENT_ONLY */
diff --git a/newlib/libc/stdio/vwprintf.c b/newlib/libc/stdio/vwprintf.c
index ce28fda..de95346 100644
--- a/newlib/libc/stdio/vwprintf.c
+++ b/newlib/libc/stdio/vwprintf.c
@@ -30,8 +30,10 @@ _DEFUN(vwprintf, (fmt, ap),
         _CONST wchar_t *fmt _AND
         va_list ap)
  {
-  _REENT_SMALL_CHECK_INIT (_REENT);
-  return _vfwprintf_r (_REENT, _stdout_r (_REENT), fmt, ap);
+  struct _reent *reent = _REENT;
+
+  _REENT_SMALL_CHECK_INIT (reent);
+  return _vfwprintf_r (reent, _stdout_r (reent), fmt, ap);
  }

  #endif /* !_REENT_ONLY */
diff --git a/newlib/libc/stdio/vwscanf.c b/newlib/libc/stdio/vwscanf.c
index 3c60fbb..d0b5351 100644
--- a/newlib/libc/stdio/vwscanf.c
+++ b/newlib/libc/stdio/vwscanf.c
@@ -33,8 +33,10 @@
  int
  vwscanf (_CONST wchar_t *fmt, va_list ap)
  {
-  _REENT_SMALL_CHECK_INIT (_REENT);
-  return __svfwscanf_r (_REENT, _stdin_r (_REENT), fmt, ap);
+  struct _reent *reent = _REENT;
+
+  _REENT_SMALL_CHECK_INIT (reent);
+  return __svfwscanf_r (reent, _stdin_r (reent), fmt, ap);
  }

  #endif /* !_REENT_ONLY */
diff --git a/newlib/libc/stdio/wscanf.c b/newlib/libc/stdio/wscanf.c
index abe8dc0..9fee3c1 100644
--- a/newlib/libc/stdio/wscanf.c
+++ b/newlib/libc/stdio/wscanf.c
@@ -29,10 +29,11 @@ wscanf(_CONST wchar_t *fmt, ...)
  {
    int ret;
    va_list ap;
+  struct _reent *reent = _REENT;

-  _REENT_SMALL_CHECK_INIT (_REENT);
+  _REENT_SMALL_CHECK_INIT (reent);
    va_start (ap, fmt);
-  ret = _vfwscanf_r (_REENT, _stdin_r (_REENT), fmt, ap);
+  ret = _vfwscanf_r (reent, _stdin_r (reent), fmt, ap);
    va_end (ap);
    return ret;
  }
diff --git a/newlib/libc/stdlib/ecvtbuf.c b/newlib/libc/stdlib/ecvtbuf.c
index 2b9b9eb..feaa33f 100644
--- a/newlib/libc/stdlib/ecvtbuf.c
+++ b/newlib/libc/stdlib/ecvtbuf.c
@@ -233,6 +233,7 @@ _DEFUN (fcvtbuf, (invalue, ndigit, decpt, sign,
fcvt_buf),
         int *sign _AND
         char *fcvt_buf)
  {
+  struct _reent *reent = _REENT;
    char *save;
    char *p;
    char *end;
@@ -240,27 +241,27 @@ _DEFUN (fcvtbuf, (invalue, ndigit, decpt, sign,
fcvt_buf),

    if (fcvt_buf == NULL)
      {
-      if (_REENT->_cvtlen <= ndigit + 35)
+      if (reent->_cvtlen <= ndigit + 35)
         {
-         if ((fcvt_buf = (char *) _realloc_r (_REENT, _REENT->_cvtbuf,
+         if ((fcvt_buf = (char *) _realloc_r (reent, reent->_cvtbuf,
                                                ndigit + 36)) == NULL)
             return NULL;
-         _REENT->_cvtlen = ndigit + 36;
-         _REENT->_cvtbuf = fcvt_buf;
+         reent->_cvtlen = ndigit + 36;
+         reent->_cvtbuf = fcvt_buf;
         }

-      fcvt_buf = _REENT->_cvtbuf ;
+      fcvt_buf = reent->_cvtbuf ;
      }

    save = fcvt_buf;

    if (invalue < 1.0 && invalue > -1.0)
      {
-      p = _dtoa_r (_REENT, invalue, 2, ndigit, decpt, sign, &end);
+      p = _dtoa_r (reent, invalue, 2, ndigit, decpt, sign, &end);
      }
    else
      {
-      p = _dtoa_r (_REENT, invalue, 3, ndigit, decpt, sign, &end);
+      p = _dtoa_r (reent, invalue, 3, ndigit, decpt, sign, &end);
      }

    /* Now copy */
@@ -289,6 +290,7 @@ _DEFUN (ecvtbuf, (invalue, ndigit, decpt, sign,
fcvt_buf),
         int *sign _AND
         char *fcvt_buf)
  {
+  struct _reent *reent = _REENT;
    char *save;
    char *p;
    char *end;
@@ -296,21 +298,21 @@ _DEFUN (ecvtbuf, (invalue, ndigit, decpt, sign,
fcvt_buf),

    if (fcvt_buf == NULL)
      {
-      if (_REENT->_cvtlen <= ndigit)
+      if (reent->_cvtlen <= ndigit)
         {
-         if ((fcvt_buf = (char *) _realloc_r (_REENT, _REENT->_cvtbuf,
+         if ((fcvt_buf = (char *) _realloc_r (reent, reent->_cvtbuf,
                                                ndigit + 1)) == NULL)
             return NULL;
-         _REENT->_cvtlen = ndigit + 1;
-         _REENT->_cvtbuf = fcvt_buf;
+         reent->_cvtlen = ndigit + 1;
+         reent->_cvtbuf = fcvt_buf;
         }

-      fcvt_buf = _REENT->_cvtbuf ;
+      fcvt_buf = reent->_cvtbuf ;
      }

    save = fcvt_buf;

-  p = _dtoa_r (_REENT, invalue, 2, ndigit, decpt, sign, &end);
+  p = _dtoa_r (reent, invalue, 2, ndigit, decpt, sign, &end);

    /* Now copy */

diff --git a/newlib/libc/stdlib/mblen.c b/newlib/libc/stdlib/mblen.c
index ace2388..4d9ac38 100644
--- a/newlib/libc/stdlib/mblen.c
+++ b/newlib/libc/stdlib/mblen.c
@@ -55,11 +55,12 @@ _DEFUN (mblen, (s, n),
  {
  #ifdef _MB_CAPABLE
    int retval = 0;
+  struct _reent *reent = _REENT;
    mbstate_t *state;

-  _REENT_CHECK_MISC(_REENT);
-  state = &(_REENT_MBLEN_STATE(_REENT));
-  retval = __mbtowc (_REENT, NULL, s, n, __locale_charset (), state);
+  _REENT_CHECK_MISC(reent);
+  state = &(_REENT_MBLEN_STATE(reent));
+  retval = __mbtowc (reent, NULL, s, n, __locale_charset (), state);
    if (retval < 0)
      {
        state->__count = 0;
diff --git a/newlib/libc/stdlib/mbrlen.c b/newlib/libc/stdlib/mbrlen.c
index ac9aa32..4319875 100644
--- a/newlib/libc/stdlib/mbrlen.c
+++ b/newlib/libc/stdlib/mbrlen.c
@@ -11,8 +11,10 @@ mbrlen(const char *s, size_t n, mbstate_t *ps)
  #ifdef _MB_CAPABLE
    if (ps == NULL)
      {
-      _REENT_CHECK_MISC(_REENT);
-      ps = &(_REENT_MBRLEN_STATE(_REENT));
+      struct _reent *reent = _REENT;
+
+      _REENT_CHECK_MISC(reent);
+      ps = &(_REENT_MBRLEN_STATE(reent));
      }
  #endif

diff --git a/newlib/libc/stdlib/mbrtowc.c b/newlib/libc/stdlib/mbrtowc.c
index e191e11..0a8c23a 100644
--- a/newlib/libc/stdlib/mbrtowc.c
+++ b/newlib/libc/stdlib/mbrtowc.c
@@ -52,24 +52,25 @@ _DEFUN (mbrtowc, (pwc, s, n, ps),
    return _mbrtowc_r (_REENT, pwc, s, n, ps);
  #else
    int retval = 0;
+  struct _reent *reent = _REENT;

  #ifdef _MB_CAPABLE
    if (ps == NULL)
      {
-      _REENT_CHECK_MISC(_REENT);
-      ps = &(_REENT_MBRTOWC_STATE(_REENT));
+      _REENT_CHECK_MISC(reent);
+      ps = &(_REENT_MBRTOWC_STATE(reent));
      }
  #endif

    if (s == NULL)
-    retval = __mbtowc (_REENT, NULL, "", 1, __locale_charset (), ps);
+    retval = __mbtowc (reent, NULL, "", 1, __locale_charset (), ps);
    else
-    retval = __mbtowc (_REENT, pwc, s, n, __locale_charset (), ps);
+    retval = __mbtowc (reent, pwc, s, n, __locale_charset (), ps);

    if (retval == -1)
      {
        ps->__count = 0;
-      _REENT->_errno = EILSEQ;
+      reent->_errno = EILSEQ;
        return (size_t)(-1);
      }
    else
diff --git a/newlib/libc/stdlib/mbtowc.c b/newlib/libc/stdlib/mbtowc.c
index 83b6a0e..8da309e 100644
--- a/newlib/libc/stdlib/mbtowc.c
+++ b/newlib/libc/stdlib/mbtowc.c
@@ -64,12 +64,13 @@ _DEFUN (mbtowc, (pwc, s, n),
  {
  #ifdef _MB_CAPABLE
    int retval = 0;
+  struct _reent *reent = _REENT;
    mbstate_t *ps;

-  _REENT_CHECK_MISC(_REENT);
-  ps = &(_REENT_MBTOWC_STATE(_REENT));
+  _REENT_CHECK_MISC(reent);
+  ps = &(_REENT_MBTOWC_STATE(reent));

-  retval = __mbtowc (_REENT, pwc, s, n, __locale_charset (), ps);
+  retval = __mbtowc (reent, pwc, s, n, __locale_charset (), ps);

    if (retval < 0)
      {
diff --git a/newlib/libc/stdlib/rand.c b/newlib/libc/stdlib/rand.c
index 131e5cf..42acde4 100644
--- a/newlib/libc/stdlib/rand.c
+++ b/newlib/libc/stdlib/rand.c
@@ -72,20 +72,24 @@ on two different systems.
  void
  _DEFUN (srand, (seed), unsigned int seed)
  {
-  _REENT_CHECK_RAND48(_REENT);
-  _REENT_RAND_NEXT(_REENT) = seed;
+  struct _reent *reent = _REENT;
+
+  _REENT_CHECK_RAND48(reent);
+  _REENT_RAND_NEXT(reent) = seed;
  }

  int
  _DEFUN_VOID (rand)
  {
+  struct _reent *reent = _REENT;
+
    /* This multiplier was obtained from Knuth, D.E., "The Art of
       Computer Programming," Vol 2, Seminumerical Algorithms, Third
       Edition, Addison-Wesley, 1998, p. 106 (line 26) & p. 108 */
-  _REENT_CHECK_RAND48(_REENT);
-  _REENT_RAND_NEXT(_REENT) =
-     _REENT_RAND_NEXT(_REENT) * __extension__ 6364136223846793005LL + 1;
-  return (int)((_REENT_RAND_NEXT(_REENT) >> 32) & RAND_MAX);
+  _REENT_CHECK_RAND48(reent);
+  _REENT_RAND_NEXT(reent) =
+     _REENT_RAND_NEXT(reent) * __extension__ 6364136223846793005LL + 1;
+  return (int)((_REENT_RAND_NEXT(reent) >> 32) & RAND_MAX);
  }

  #endif /* _REENT_ONLY */
diff --git a/newlib/libc/stdlib/wcrtomb.c b/newlib/libc/stdlib/wcrtomb.c
index 60e0d89..b634c23 100644
--- a/newlib/libc/stdlib/wcrtomb.c
+++ b/newlib/libc/stdlib/wcrtomb.c
@@ -50,25 +50,26 @@ _DEFUN (wcrtomb, (s, wc, ps),
    return _wcrtomb_r (_REENT, s, wc, ps);
  #else
    int retval = 0;
+  struct _reent *reent = _REENT;
    char buf[10];

  #ifdef _MB_CAPABLE
    if (ps == NULL)
      {
-      _REENT_CHECK_MISC(_REENT);
-      ps = &(_REENT_WCRTOMB_STATE(_REENT));
+      _REENT_CHECK_MISC(reent);
+      ps = &(_REENT_WCRTOMB_STATE(reent));
      }
  #endif

    if (s == NULL)
-    retval = __wctomb (_REENT, buf, L'\0', __locale_charset (), ps);
+    retval = __wctomb (reent, buf, L'\0', __locale_charset (), ps);
    else
-    retval = __wctomb (_REENT, s, wc, __locale_charset (), ps);
+    retval = __wctomb (reent, s, wc, __locale_charset (), ps);

    if (retval == -1)
      {
        ps->__count = 0;
-      _REENT->_errno = EILSEQ;
+      reent->_errno = EILSEQ;
        return (size_t)(-1);
      }
    else
diff --git a/newlib/libc/stdlib/wctob.c b/newlib/libc/stdlib/wctob.c
index d97c01f..eebaec8 100644
--- a/newlib/libc/stdlib/wctob.c
+++ b/newlib/libc/stdlib/wctob.c
@@ -8,6 +8,7 @@
  int
  wctob (wint_t wc)
  {
+  struct _reent *reent;
    mbstate_t mbs;
    unsigned char pmb[MB_LEN_MAX];

@@ -17,8 +18,9 @@ wctob (wint_t wc)
    /* Put mbs in initial state. */
    memset (&mbs, '\0', sizeof (mbs));

-  _REENT_CHECK_MISC(_REENT);
+  reent = _REENT;
+  _REENT_CHECK_MISC(reent);

-  return __wctomb (_REENT, (char *) pmb, wc, __locale_charset (),
&mbs) == 1
+  return __wctomb (reent, (char *) pmb, wc, __locale_charset (),
&mbs) == 1
           ? (int) pmb[0] : EOF;
  }
diff --git a/newlib/libc/stdlib/wctomb.c b/newlib/libc/stdlib/wctomb.c
index 9e82eaa..8d4ceb8 100644
--- a/newlib/libc/stdlib/wctomb.c
+++ b/newlib/libc/stdlib/wctomb.c
@@ -57,10 +57,12 @@ _DEFUN (wctomb, (s, wchar),
          wchar_t wchar)
  {
  #ifdef _MB_CAPABLE
-        _REENT_CHECK_MISC(_REENT);
+       struct _reent *reent = _REENT;

-        return __wctomb (_REENT, s, wchar, __locale_charset (),
-                        &(_REENT_WCTOMB_STATE(_REENT)));
+        _REENT_CHECK_MISC(reent);
+
+        return __wctomb (reent, s, wchar, __locale_charset (),
+                        &(_REENT_WCTOMB_STATE(reent)));
  #else /* not _MB_CAPABLE */
          if (s == NULL)
                  return 0;
diff --git a/newlib/libc/string/strtok.c b/newlib/libc/string/strtok.c
index 7640fb7..01bb090 100644
--- a/newlib/libc/string/strtok.c
+++ b/newlib/libc/string/strtok.c
@@ -95,7 +95,9 @@ _DEFUN (strtok, (s, delim),
         register char *s _AND
         register const char *delim)
  {
-       _REENT_CHECK_MISC(_REENT);
-       return __strtok_r (s, delim, &(_REENT_STRTOK_LAST(_REENT)), 1);
+       struct _reent *reent = _REENT;
+
+       _REENT_CHECK_MISC(reent);
+       return __strtok_r (s, delim, &(_REENT_STRTOK_LAST(reent)), 1);
  }
  #endif
diff --git a/newlib/libc/time/asctime.c b/newlib/libc/time/asctime.c
index 4c46408..024310b 100644
--- a/newlib/libc/time/asctime.c
+++ b/newlib/libc/time/asctime.c
@@ -57,8 +57,10 @@ char *
  _DEFUN (asctime, (tim_p),
         _CONST struct tm *tim_p)
  {
-  _REENT_CHECK_ASCTIME_BUF(_REENT);
-  return asctime_r (tim_p, _REENT_ASCTIME_BUF(_REENT));
+  struct _reent *reent = _REENT;
+
+  _REENT_CHECK_ASCTIME_BUF(reent);
+  return asctime_r (tim_p, _REENT_ASCTIME_BUF(reent));
  }

  #endif
diff --git a/newlib/libc/time/gmtime.c b/newlib/libc/time/gmtime.c
index 4d3dfff..141d203 100644
--- a/newlib/libc/time/gmtime.c
+++ b/newlib/libc/time/gmtime.c
@@ -61,8 +61,10 @@ struct tm *
  _DEFUN (gmtime, (tim_p),
         _CONST time_t * tim_p)
  {
-  _REENT_CHECK_TM(_REENT);
-  return gmtime_r (tim_p, (struct tm *)_REENT_TM(_REENT));
+  struct _reent *reent = _REENT;
+
+  _REENT_CHECK_TM(reent);
+  return gmtime_r (tim_p, (struct tm *)_REENT_TM(reent));
  }

  #endif
diff --git a/newlib/libc/time/lcltime.c b/newlib/libc/time/lcltime.c
index 399ab69..16162bf 100644
--- a/newlib/libc/time/lcltime.c
+++ b/newlib/libc/time/lcltime.c
@@ -53,8 +53,10 @@ struct tm *
  _DEFUN (localtime, (tim_p),
         _CONST time_t * tim_p)
  {
-  _REENT_CHECK_TM(_REENT);
-  return localtime_r (tim_p, (struct tm *)_REENT_TM(_REENT));
+  struct _reent *reent = _REENT;
+
+  _REENT_CHECK_TM(reent);
+  return localtime_r (tim_p, (struct tm *)_REENT_TM(reent));
  }

  #endif
--
1.7.7





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]