public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Matthew Joyce <matthew.joyce@embedded-brains.de>
To: newlib@sourceware.org
Subject: [PATCH 10/11] Add global __sglue object for all configurations
Date: Tue, 10 May 2022 10:09:26 +0200	[thread overview]
Message-ID: <20220510080927.28839-11-matthew.joyce@embedded-brains.de> (raw)
In-Reply-To: <20220510080927.28839-1-matthew.joyce@embedded-brains.de>

From: Matt Joyce <matthew.joyce@embedded-brains.de>

Added a new global __sglue object for all configurations.
Decouples the global file object list from the _GLOBAL_REENT
structure by using this new object instead of the __sglue member
of _GLOBAL_REENT in __sfp() and _fwalk_sglue().
---
 newlib/libc/include/sys/reent.h |  2 ++
 newlib/libc/stdio/fcloseall.c   |  2 +-
 newlib/libc/stdio/fflush.c      |  2 +-
 newlib/libc/stdio/findfp.c      | 15 +++++++++------
 newlib/libc/stdio/refill.c      |  2 +-
 winsup/cygwin/syscalls.cc       |  2 +-
 6 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h
index 4b0d68610..708ec16e2 100644
--- a/newlib/libc/include/sys/reent.h
+++ b/newlib/libc/include/sys/reent.h
@@ -304,6 +304,8 @@ struct _glue
   __FILE *_iobs;
 };
 
+extern struct _glue __sglue;
+
 /*
  * rand48 family support
  *
diff --git a/newlib/libc/stdio/fcloseall.c b/newlib/libc/stdio/fcloseall.c
index 4d4e3554b..f14c28d34 100644
--- a/newlib/libc/stdio/fcloseall.c
+++ b/newlib/libc/stdio/fcloseall.c
@@ -67,7 +67,7 @@ _fcloseall_r (struct _reent *ptr)
 int
 fcloseall (void)
 {
-  return _fcloseall_r (_GLOBAL_REENT);
+  return _fwalk_sglue (_GLOBAL_REENT, _fclose_r, &__sglue);
 }
 
 #endif
diff --git a/newlib/libc/stdio/fflush.c b/newlib/libc/stdio/fflush.c
index 6e946da7b..bbec4a19b 100644
--- a/newlib/libc/stdio/fflush.c
+++ b/newlib/libc/stdio/fflush.c
@@ -286,7 +286,7 @@ int
 fflush (register FILE * fp)
 {
   if (fp == NULL)
-    return _fwalk_sglue (_GLOBAL_REENT, _fflush_r, &_GLOBAL_REENT->__sglue);
+    return _fwalk_sglue (_GLOBAL_REENT, _fflush_r, &__sglue);
 
   return _fflush_r (_REENT, fp);
 }
diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c
index 221052bd4..453103e77 100644
--- a/newlib/libc/stdio/findfp.c
+++ b/newlib/libc/stdio/findfp.c
@@ -39,6 +39,13 @@ const struct __sFILE_fake __sf_fake_stderr =
 
 #ifdef _REENT_GLOBAL_STDIO_STREAMS
 __FILE __sf[3];
+struct _glue __sglue = {NULL, 3, &__sf[0]};
+#else
+#ifndef _REENT_SMALL
+struct _glue __sglue = {NULL, 3, &_GLOBAL_REENT->__sf[0]};
+#else
+struct _glue __sglue = {NULL, 0, NULL};
+#endif
 #endif
 
 #ifdef _STDIO_BSD_SEMANTICS
@@ -158,7 +165,7 @@ sfmoreglue (struct _reent *d, int n)
 static void
 stdio_atexit (void)
 {
-  (void) _fwalk_sglue (_GLOBAL_REENT, CLEANUP_FILE, &_GLOBAL_REENT->__sglue);
+  (void) _fwalk_sglue (_GLOBAL_REENT, CLEANUP_FILE, &__sglue);
 }
 
 /*
@@ -175,15 +182,11 @@ __sfp (struct _reent *d)
   _newlib_sfp_lock_start ();
 
   if (__stdio_atexit == NULL) {
-#ifdef _REENT_GLOBAL_STDIO_STREAMS
-    _GLOBAL_REENT->__sglue._niobs = 3;
-    _GLOBAL_REENT->__sglue._iobs = &__sf[0];
-#endif
     __sinit (_GLOBAL_REENT);
     __stdio_atexit = stdio_atexit;
   }
 
-  for (g = &_GLOBAL_REENT->__sglue;; g = g->_next)
+  for (g = &__sglue;; g = g->_next)
     {
       for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++)
 	if (fp->_flags == 0)
diff --git a/newlib/libc/stdio/refill.c b/newlib/libc/stdio/refill.c
index 4084d7250..8516d8576 100644
--- a/newlib/libc/stdio/refill.c
+++ b/newlib/libc/stdio/refill.c
@@ -105,7 +105,7 @@ __srefill_r (struct _reent * ptr,
       /* Ignore this file in _fwalk_sglue to avoid potential deadlock. */
       short orig_flags = fp->_flags;
       fp->_flags = 1;
-      (void) _fwalk_sglue (_GLOBAL_REENT, lflush, &_GLOBAL_REENT->__sglue);
+      (void) _fwalk_sglue (_GLOBAL_REENT, lflush, &__sglue);
       fp->_flags = orig_flags;
 
       /* Now flush this file without locking it. */
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 5bf6d8fc7..caeb5b095 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -3138,7 +3138,7 @@ cygwin_setmode (int fd, int mode)
 	_my_tls.locals.setmode_mode = O_TEXT;
       else
 	_my_tls.locals.setmode_mode = O_BINARY;
-      _fwalk_sglue (_GLOBAL_REENT, setmode_helper, &_GLOBAL_REENT->__sglue);
+      _fwalk_sglue (_GLOBAL_REENT, setmode_helper, &__sglue);
     }
   return res;
 }
-- 
2.31.1


  parent reply	other threads:[~2022-05-10  8:09 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-10  8:09 [PATCH 00/11] Decouple global file object list from _GLOBAL_REENT Matthew Joyce
2022-05-10  8:09 ` [PATCH 01/11] Remove duplicate stdio initializations Matthew Joyce
2022-05-10  8:09 ` [PATCH 02/11] Remove duplicate sglue initializations Matthew Joyce
2022-05-10  8:09 ` [PATCH 03/11] Declare global __sf[] only once Matthew Joyce
2022-05-10  8:09 ` [PATCH 04/11] Add two __sglue initialization macros Matthew Joyce
2022-05-10  8:09 ` [PATCH 05/11] Remove __sinit_locks / __sinit_recursive_mutex Matthew Joyce
2022-05-10  8:09 ` [PATCH 06/11] Move __sglue initializations to __sfp() Matthew Joyce
2022-05-10  8:09 ` [PATCH 07/11] Add CLEANUP_FILE define Matthew Joyce
2022-05-10  8:09 ` [PATCH 08/11] Add stdio atexit handler Matthew Joyce
2022-05-11 15:23   ` Corinna Vinschen
2022-05-11 16:54     ` Corinna Vinschen
2022-05-11 17:51       ` Sebastian Huber
2022-05-11 17:51     ` Sebastian Huber
2022-05-10  8:09 ` [PATCH 09/11] stdio: Replace _fwalk_reent() with _fwalk_sglue() Matthew Joyce
2022-05-11 15:56   ` Corinna Vinschen
2022-05-11 17:55     ` Sebastian Huber
2022-05-12  7:59       ` Corinna Vinschen
2022-05-10  8:09 ` Matthew Joyce [this message]
2022-05-10  8:09 ` [PATCH 11/11] Remove __sglue member for one configuration Matthew Joyce

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=20220510080927.28839-11-matthew.joyce@embedded-brains.de \
    --to=matthew.joyce@embedded-brains.de \
    --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).