From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 106544 invoked by alias); 1 Mar 2018 23:06:47 -0000 Mailing-List: contact newlib-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-cvs-owner@sourceware.org Received: (qmail 106497 invoked by uid 447); 1 Mar 2018 23:06:46 -0000 Date: Thu, 01 Mar 2018 23:06:00 -0000 Message-ID: <20180301230646.106494.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jeff Johnston To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] Add global stdio streams support for reent small. X-Act-Checkin: newlib-cygwin X-Git-Author: Our Air Quality X-Git-Refname: refs/heads/master X-Git-Oldrev: dc3928fc75550422306f9630d34430634767d87a X-Git-Newrev: b7520b14d5fe175d9bc60266700fb7b988600a84 X-SW-Source: 2018-q1/txt/msg00040.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=b7520b14d5fe175d9bc60266700fb7b988600a84 commit b7520b14d5fe175d9bc60266700fb7b988600a84 Author: Our Air Quality Date: Wed Feb 28 23:31:48 2018 +1100 Add global stdio streams support for reent small. Diff: --- newlib/libc/include/sys/reent.h | 45 ++++++++++++++++++++++++++++++++++++++--- newlib/libc/stdio/findfp.c | 16 ++++++++++----- newlib/libc/stdio/local.h | 6 +++--- 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h index 1ef2261..6e55e1c 100644 --- a/newlib/libc/include/sys/reent.h +++ b/newlib/libc/include/sys/reent.h @@ -144,7 +144,7 @@ struct __sbuf { * _ub._base!=NULL) and _up and _ur save the current values of _p and _r. */ -#ifdef _REENT_SMALL +#if defined(_REENT_SMALL) && !defined(_REENT_GLOBAL_STDIO_STREAMS) /* * struct __sFILE_fake is the start of a struct __sFILE, with only the * minimal fields allocated. In __sinit() we really allocate the 3 @@ -174,9 +174,9 @@ extern void __sinit (struct _reent *); __sinit (ptr); \ } \ while (0) -#else +#else /* _REENT_SMALL && !_REENT_GLOBAL_STDIO_STREAMS */ # define _REENT_SMALL_CHECK_INIT(ptr) /* nothing */ -#endif +#endif /* _REENT_SMALL && !_REENT_GLOBAL_STDIO_STREAMS */ struct __sFILE { unsigned char *_p; /* current position in (some) buffer */ @@ -418,6 +418,43 @@ struct _reent char *_signal_buf; /* strsignal */ }; +#ifdef _REENT_GLOBAL_STDIO_STREAMS +extern __FILE __sf[3]; + +# define _REENT_INIT(var) \ + { 0, \ + &__sf[0], \ + &__sf[1], \ + &__sf[2], \ + 0, \ + _NULL, \ + 0, \ + 0, \ + _NULL, \ + _NULL, \ + _NULL, \ + 0, \ + 0, \ + _NULL, \ + _NULL, \ + _NULL, \ + _NULL, \ + _NULL, \ + _REENT_INIT_ATEXIT \ + {_NULL, 0, _NULL}, \ + _NULL, \ + _NULL, \ + _NULL \ + } + +#define _REENT_INIT_PTR_ZEROED(var) \ + { (var)->_stdin = &__sf[0]; \ + (var)->_stdout = &__sf[1]; \ + (var)->_stderr = &__sf[2]; \ + } + +#else /* _REENT_GLOBAL_STDIO_STREAMS */ + extern const struct __sFILE_fake __sf_fake_stdin; extern const struct __sFILE_fake __sf_fake_stdout; extern const struct __sFILE_fake __sf_fake_stderr; @@ -454,6 +491,8 @@ extern const struct __sFILE_fake __sf_fake_stderr; (var)->_stderr = (__FILE *)&__sf_fake_stderr; \ } +#endif /* _REENT_GLOBAL_STDIO_STREAMS */ + /* Only add assert() calls if we are specified to debug. */ #ifdef _REENT_CHECK_DEBUG #include diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c index cf92453..7119c05 100644 --- a/newlib/libc/stdio/findfp.c +++ b/newlib/libc/stdio/findfp.c @@ -26,7 +26,7 @@ #include #include "local.h" -#ifdef _REENT_SMALL +#if defined(_REENT_SMALL) && !defined(_REENT_GLOBAL_STDIO_STREAMS) const struct __sFILE_fake __sf_fake_stdin = {_NULL, 0, 0, 0, 0, {_NULL, 0}, 0, _NULL}; const struct __sFILE_fake __sf_fake_stdout = @@ -73,7 +73,7 @@ std (FILE *ptr, #else /* _STDIO_CLOSE_STD_STREAMS */ ptr->_close = NULL; #endif /* _STDIO_CLOSE_STD_STREAMS */ -#if !defined(__SINGLE_THREAD__) && !defined(_REENT_SMALL) +#if !defined(__SINGLE_THREAD__) && !(defined(_REENT_SMALL) && !defined(_REENT_GLOBAL_STDIO_STREAMS)) __lock_init_recursive (ptr->_lock); /* * #else @@ -260,7 +260,7 @@ __sinit (struct _reent *s) # ifndef _REENT_GLOBAL_STDIO_STREAMS s->__sglue._niobs = 3; s->__sglue._iobs = &s->__sf[0]; -# endif +# endif /* _REENT_GLOBAL_STDIO_STREAMS */ #else s->__sglue._niobs = 0; s->__sglue._iobs = NULL; @@ -269,9 +269,15 @@ __sinit (struct _reent *s) __sinit if it's 0. */ if (s == _GLOBAL_REENT) s->__sdidinit = 1; +# ifndef _REENT_GLOBAL_STDIO_STREAMS s->_stdin = __sfp(s); s->_stdout = __sfp(s); s->_stderr = __sfp(s); +# else /* _REENT_GLOBAL_STDIO_STREAMS */ + s->_stdin = &__sf[0]; + s->_stdout = &__sf[1]; + s->_stderr = &__sf[2]; +# endif /* _REENT_GLOBAL_STDIO_STREAMS */ #endif #ifdef _REENT_GLOBAL_STDIO_STREAMS @@ -282,11 +288,11 @@ __sinit (struct _reent *s) stdout_init (&__sf[1]); stderr_init (&__sf[2]); } -#else +#else /* _REENT_GLOBAL_STDIO_STREAMS */ stdin_init (s->_stdin); stdout_init (s->_stdout); stderr_init (s->_stderr); -#endif +#endif /* _REENT_GLOBAL_STDIO_STREAMS */ s->__sdidinit = 1; diff --git a/newlib/libc/stdio/local.h b/newlib/libc/stdio/local.h index 5f56792..53694aa 100644 --- a/newlib/libc/stdio/local.h +++ b/newlib/libc/stdio/local.h @@ -197,7 +197,7 @@ extern _READ_WRITE_RETURN_TYPE __swrite64 (struct _reent *, void *, /* Called by the main entry point fns to ensure stdio has been initialized. */ -#ifdef _REENT_SMALL +#if defined(_REENT_SMALL) && !defined(_REENT_GLOBAL_STDIO_STREAMS) #define CHECK_INIT(ptr, fp) \ do \ { \ @@ -212,7 +212,7 @@ extern _READ_WRITE_RETURN_TYPE __swrite64 (struct _reent *, void *, (fp) = _stderr_r(_check_init_ptr); \ } \ while (0) -#else /* !_REENT_SMALL */ +#else /* !_REENT_SMALL || _REENT_GLOBAL_STDIO_STREAMS */ #define CHECK_INIT(ptr, fp) \ do \ { \ @@ -221,7 +221,7 @@ extern _READ_WRITE_RETURN_TYPE __swrite64 (struct _reent *, void *, __sinit (_check_init_ptr); \ } \ while (0) -#endif /* !_REENT_SMALL */ +#endif /* !_REENT_SMALL || _REENT_GLOBAL_STDIO_STREAMS */ #define CHECK_STD_INIT(ptr) \ do \