public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Corinna Vinschen <vinschen@redhat.com>
To: newlib@sourceware.org
Subject: Re: [PATCH 1/1] Make __sdidinit unused
Date: Thu, 17 Feb 2022 14:53:09 +0100	[thread overview]
Message-ID: <Yg5TRTGQ4dEq0lH6@calimero.vinschen.de> (raw)
In-Reply-To: <20220217130520.27919-2-matthew.joyce@embedded-brains.de>

Hi Matt,

this doesn't build on Cygwin.

On Feb 17 14:05, Matthew Joyce wrote:
> Remove dependency on __sdidinit member of struct _reent to check
> object initialization. Like __sdidinit, the __cleanup member of
> struct _reent is initialized in the __sinit() function. Checking
> initialization against __cleanup serves the same purpose and will
> reduce overhead in the __sfp() function in a follow up patch.
> ---
> [...]
> diff --git a/winsup/cygwin/cygtls.cc b/winsup/cygwin/cygtls.cc
> index 1a2213d1f..239a9d7e1 100644
> --- a/winsup/cygwin/cygtls.cc
> +++ b/winsup/cygwin/cygtls.cc
> @@ -60,8 +60,8 @@ _cygtls::init_thread (void *x, DWORD (*func) (void *, void *))
>  	  local_clib._stdin = _GLOBAL_REENT->_stdin;
>  	  local_clib._stdout = _GLOBAL_REENT->_stdout;
>  	  local_clib._stderr = _GLOBAL_REENT->_stderr;
> -	  local_clib.__sdidinit = _GLOBAL_REENT->__sdidinit ? -1 : 0;
> -	  local_clib.__cleanup = _GLOBAL_REENT->__cleanup;
> +	  local_clib.__cleanup = _GLOBAL_REENT->__cleanup ?
> +	    (void *)(uintptr_t)-1 : NULL;

  CXX      cygtls.o
winsup/cygwin/cygtls.cc: In member function ‘void _cygtls::init_thread(void*, DWORD (*)(void*, void*))’:
winsup/cygwin/cygtls.cc:63:59: error: invalid conversion from ‘void*’ to ‘void (*)(_reent*)’ [-fpermissive]
   63 |           local_clib.__cleanup = _GLOBAL_REENT->__cleanup ?
      |                                                           ^
      |                                                           |
      |                                                           void*

> diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
> index f3d09c169..16ca5888c 100644
> --- a/winsup/cygwin/dcrt0.cc
> +++ b/winsup/cygwin/dcrt0.cc
> @@ -824,15 +824,13 @@ main_thread_sinit ()
> [...]
> -     to _REENT here again. */
> -  _REENT->__sdidinit = -1;
> -  _REENT->__cleanup = _GLOBAL_REENT->__cleanup;
> +     To fix this issue we set __cleanup to -1 here. */
> +  _REENT->__cleanup = (void *)(uintptr_t)-1;

winsup/cygwin/dcrt0.cc: In function ‘void main_thread_sinit()’:
winsup/cygwin/dcrt0.cc:833:23: error: invalid conversion from ‘void*’ to ‘void (*)(_reent*)’ [-fpermissive]
  833 |   _REENT->__cleanup = (void *)(uintptr_t)-1;
      |                       ^~~~~~~~~~~~~~~~~~~~~
      |                       |
      |                       void*

I suggest this change, which also includes a matching change to
thread.cc, to be type-safe:

diff --git a/winsup/cygwin/cygtls.cc b/winsup/cygwin/cygtls.cc
index 239a9d7e1f51..e80fbce5f3e8 100644
--- a/winsup/cygwin/cygtls.cc
+++ b/winsup/cygwin/cygtls.cc
@@ -60,8 +60,9 @@ _cygtls::init_thread (void *x, DWORD (*func) (void *, void *))
 	  local_clib._stdin = _GLOBAL_REENT->_stdin;
 	  local_clib._stdout = _GLOBAL_REENT->_stdout;
 	  local_clib._stderr = _GLOBAL_REENT->_stderr;
-	  local_clib.__cleanup = _GLOBAL_REENT->__cleanup ?
-	    (void *)(uintptr_t)-1 : NULL;
+	  local_clib.__cleanup = (void (*) (struct _reent *))
+				 (_GLOBAL_REENT->__cleanup
+				  ? (void *) -1 : NULL);
 	  local_clib.__sglue._niobs = 3;
 	  local_clib.__sglue._iobs = &_GLOBAL_REENT->__sf[0];
 	}
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index 16ca5888c28a..7f26c6304030 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -830,7 +830,7 @@ main_thread_sinit ()
      read or written in the first stdio function call in the main thread.
 
      To fix this issue we set __cleanup to -1 here. */
-  _REENT->__cleanup = (void *)(uintptr_t)-1;
+  _REENT->__cleanup = (void (*) (struct _reent *)) -1;
 }
 
 /* Take over from libc's crt0.o and start the application. Note the
diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc
index 3c3a2f3b3a52..21b2dbe4686e 100644
--- a/winsup/cygwin/thread.cc
+++ b/winsup/cygwin/thread.cc
@@ -564,7 +564,7 @@ pthread::exit (void *value_ptr)
       mutex.unlock ();
     }
 
-  if (_my_tls.local_clib.__cleanup == (void *)(uintptr_t)-1)
+  if (_my_tls.local_clib.__cleanup == (void (*) (struct _reent *)) -1)
     _my_tls.local_clib.__cleanup = NULL;
   _reclaim_reent (_REENT);
 
With these changes, GTG.


Thx,
Corinna


      reply	other threads:[~2022-02-17 13:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-17 13:05 [PATCH 0/1] " Matthew Joyce
2022-02-17 13:05 ` [PATCH 1/1] " Matthew Joyce
2022-02-17 13:53   ` Corinna Vinschen [this message]

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=Yg5TRTGQ4dEq0lH6@calimero.vinschen.de \
    --to=vinschen@redhat.com \
    --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).