public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Add global stdio streams support for reent small.
@ 2018-03-01 23:06 Jeff Johnston
0 siblings, 0 replies; only message in thread
From: Jeff Johnston @ 2018-03-01 23:06 UTC (permalink / raw)
To: newlib-cvs
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=b7520b14d5fe175d9bc60266700fb7b988600a84
commit b7520b14d5fe175d9bc60266700fb7b988600a84
Author: Our Air Quality <info@ourairquality.org>
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 <assert.h>
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 <sys/lock.h>
#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 \
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-03-01 23:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-01 23:06 [newlib-cygwin] Add global stdio streams support for reent small Jeff Johnston
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).