Re: btowc problem

Eli Zaretskii <eliz-mXXj517/[email protected]> Fri, 03 Jul 2020 15:51:52 +0300
Newsgroups gmane.comp.gnu.mingw.user
Message-ID <[email protected]>
> Date: Thu, 02 Jul 2020 05:41:46 +0300
> From: Eli Zaretskii <[email protected]>
> 
> > > My suggestion was to add to 5.3.x libmingwex.a implementations of
> > > btowc etc. that simply call the corresponding __msvcrt_* functions, so
> > > that libraries compiled by older MinGW versions could still be happy
> > > when linked under the newer mingwrt.
> > 
> > No, that cannot work; it would create a recursive call loop with no
> > terminal condition, until the process runs out of stack space.
> 
> You are saying that __msvcrt_* functions call btowc etc.?  I thought
> they were doing that via a function pointer, which gets populated at
> run time?

I think I see what you were alluding to.  It's this code in the
__msvcrt_* functions:

  if(  (redirector_hook == NULL)
  &&  ((redirector_hook = dlsym( RTLD_DEFAULT, "btowc" )) == NULL)  )
  {
    /* ...but when no Microsoft implementation can be found, register
     * the MinGW fallback in its stead.
     */
    redirector_hook = __mingw_btowc_fallback;
  }

Since the dlsym call uses RTLD_DEFAULT, it will search the modules
that are already loaded into the program's address space, and will
thus find the implementation I proposed to put in libmingwex, which
then will cause it to call itself, recursively, this blowing up the
stack.  Not good.

But we could instead look for these functions explicitly in
MSVCRT.DLL, not in all of the loaded modules, couldn't we?

However, if this is not a good idea, then yes, I think having these
functions in libmingwex that redirect to __mingw_* replacements
unconditionally is a good-enough solution.

_______________________________________________
MinGW-Users mailing list
[email protected]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.osdn.me/mailman/listinfo/mingw-users
Also: mailto:[email protected]?subject=unsubscribe