public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
From: Sebastian Huber <sh@sourceware.org>
To: newlib-cvs@sourceware.org
Subject: [newlib-cygwin] Fix stdio exit handling
Date: Tue, 17 May 2022 16:30:48 +0000 (GMT)	[thread overview]
Message-ID: <20220517163048.76D1F3858D3C@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=e826fbb2ae884257479165476acbc8d8be7d0081

commit e826fbb2ae884257479165476acbc8d8be7d0081
Author: Sebastian Huber <sebastian.huber@embedded-brains.de>
Date:   Tue May 17 11:52:24 2022 +0200

    Fix stdio exit handling
    
    Make sure that the stdio exit handler is set in all stdio initialization paths.
    
    The bug was introduced by commit 26747c47bc0a1137e02e0377306d721cc3478855.

Diff:
---
 newlib/libc/stdio/findfp.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c
index 19952d4e0..118637a18 100644
--- a/newlib/libc/stdio/findfp.c
+++ b/newlib/libc/stdio/findfp.c
@@ -168,6 +168,19 @@ stdio_exit_handler (void)
   (void) _fwalk_sglue (_GLOBAL_REENT, CLEANUP_FILE, &__sglue);
 }
 
+static void
+global_stdio_init (void)
+{
+  if (__stdio_exit_handler == NULL) {
+    __stdio_exit_handler = stdio_exit_handler;
+#ifdef _REENT_GLOBAL_STDIO_STREAMS
+    stdin_init (&__sf[0]);
+    stdout_init (&__sf[1]);
+    stderr_init (&__sf[2]);
+#endif
+  }
+}
+
 /*
  * Find a free FILE for fopen et al.
  */
@@ -180,11 +193,7 @@ __sfp (struct _reent *d)
   struct _glue *g;
 
   _newlib_sfp_lock_start ();
-
-  if (__stdio_exit_handler == NULL) {
-    __sinit (_GLOBAL_REENT);
-    __stdio_exit_handler = stdio_exit_handler;
-  }
+  global_stdio_init ();
 
   for (g = &__sglue;; g = g->_next)
     {
@@ -273,13 +282,9 @@ __sinit (struct _reent *s)
 # endif /* _REENT_GLOBAL_STDIO_STREAMS */
 #endif
 
-#ifdef _REENT_GLOBAL_STDIO_STREAMS
-  if (__sf[0]._cookie == NULL) {
-    stdin_init (&__sf[0]);
-    stdout_init (&__sf[1]);
-    stderr_init (&__sf[2]);
-  }
-#else /* _REENT_GLOBAL_STDIO_STREAMS */
+  global_stdio_init ();
+
+#ifndef _REENT_GLOBAL_STDIO_STREAMS
   stdin_init (s->_stdin);
   stdout_init (s->_stdout);
   stderr_init (s->_stderr);


                 reply	other threads:[~2022-05-17 16:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220517163048.76D1F3858D3C@sourceware.org \
    --to=sh@sourceware.org \
    --cc=newlib-cvs@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).