diff options
author | Jeff Johnston <jjohnstn@redhat.com> | 2013-04-29 21:06:23 +0000 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2013-04-29 21:06:23 +0000 |
commit | b334e6660a405d2d63166ad9e4560421e6810cdc (patch) | |
tree | 08690339ed7959e88c00c4ac33406843dbc3ad62 /newlib/libc/stdio | |
parent | 2a55aa79a9fcef6b8d1bd0264ed91d0c6420d783 (diff) | |
download | cygnal-b334e6660a405d2d63166ad9e4560421e6810cdc.tar.gz cygnal-b334e6660a405d2d63166ad9e4560421e6810cdc.tar.bz2 cygnal-b334e6660a405d2d63166ad9e4560421e6810cdc.zip |
2013-04-29 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.
Diffstat (limited to 'newlib/libc/stdio')
-rw-r--r-- | newlib/libc/stdio/fgetc.c | 6 | ||||
-rw-r--r-- | newlib/libc/stdio/fgetwc.c | 6 | ||||
-rw-r--r-- | newlib/libc/stdio/fgetws.c | 6 | ||||
-rw-r--r-- | newlib/libc/stdio/fputc.c | 6 | ||||
-rw-r--r-- | newlib/libc/stdio/fputwc.c | 6 | ||||
-rw-r--r-- | newlib/libc/stdio/fputws.c | 6 | ||||
-rw-r--r-- | newlib/libc/stdio/getc.c | 6 | ||||
-rw-r--r-- | newlib/libc/stdio/getchar.c | 6 | ||||
-rw-r--r-- | newlib/libc/stdio/local.h | 45 | ||||
-rw-r--r-- | newlib/libc/stdio/putc.c | 6 | ||||
-rw-r--r-- | newlib/libc/stdio/putchar.c | 6 | ||||
-rw-r--r-- | newlib/libc/stdio/scanf.c | 5 | ||||
-rw-r--r-- | newlib/libc/stdio/setvbuf.c | 9 | ||||
-rw-r--r-- | newlib/libc/stdio/ungetwc.c | 6 | ||||
-rw-r--r-- | newlib/libc/stdio/vfscanf.c | 6 | ||||
-rw-r--r-- | newlib/libc/stdio/vfwscanf.c | 6 | ||||
-rw-r--r-- | newlib/libc/stdio/viprintf.c | 6 | ||||
-rw-r--r-- | newlib/libc/stdio/viscanf.c | 6 | ||||
-rw-r--r-- | newlib/libc/stdio/vprintf.c | 6 | ||||
-rw-r--r-- | newlib/libc/stdio/vscanf.c | 6 | ||||
-rw-r--r-- | newlib/libc/stdio/vwprintf.c | 6 | ||||
-rw-r--r-- | newlib/libc/stdio/vwscanf.c | 6 | ||||
-rw-r--r-- | newlib/libc/stdio/wscanf.c | 5 |
23 files changed, 111 insertions, 67 deletions
diff --git a/newlib/libc/stdio/fgetc.c b/newlib/libc/stdio/fgetc.c index 99d8330fe..20492d24b 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 0eaaecb2f..14c554786 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 3cf45a976..b5d8851e1 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 6af79d470..f380717d1 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 74e7a452c..5ec85d1ab 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 0893b3c33..a28a5551b 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 355b19131..7951cdc93 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 da2f5dfaf..7f3ceac62 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 ec5efab49..54854b49d 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 1115bf40d..2b1fd1bf3 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 06bcbb46e..bb27dc4e6 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 68fd8fb65..19c85be4f 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 63f1f80db..41bdff6b6 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 ee0d7fc75..a69449eb2 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 e967719b7..ae94cea3f 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 5d2388df8..3379b5e19 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 3717f3a08..fec92fa8a 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 a60c32ff0..9a7d0c5f2 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 69edc87ae..375656972 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 e559b77a8..210774b05 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 ce28fdabb..de95346a0 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 3c60fbb73..d0b535170 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 abe8dc07a..9fee3c176 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; } |