New implementation of pseudo console support (experimental)

Johannes Schindelin Johannes.Schindelin@gmx.de
Tue Sep 1 06:32:30 GMT 2020


Hi Takashi,

On Tue, 1 Sep 2020, Takashi Yano via Cygwin-developers wrote:

> On Tue, 1 Sep 2020 06:46:53 +0200 (CEST)
> Johannes Schindelin wrote:
>
> > -- snip --
> > diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
> > index 43eebc174..65b4d45fa 100644
> > --- a/winsup/cygwin/fhandler_tty.cc
> > +++ b/winsup/cygwin/fhandler_tty.cc
> > @@ -2867,7 +2867,16 @@ fhandler_pty_slave::setup_locale (void)
> >    char charset[ENCODING_LEN + 1] = "ASCII";
> >    LCID lcid = get_langinfo (locale, charset);
> >
> > -  /* Set console code page form locale */
> > +  /* Special-case the UTF-8 character set */
> > +  if (strcasecmp (charset, "UTF-8") == 0)
> > +    {
> > +      get_ttyp ()->term_code_page = CP_UTF8;
> > +      SetConsoleCP (CP_UTF8);
> > +      SetConsoleOutputCP (CP_UTF8);
> > +      return;
> > +    }
> > +
> > +  /* Set console code page from locale */
> >    if (get_pseudo_console ())
> >      {
> >        UINT code_page;
> > -- snap --
>
> I don't think you do right thing. Your first test case makes
> garbled output in command prompt, therefore output in cygwin
> should be the same.
>
> I believe the correct maner as Windows programs are such as:
>
> [Code A]
> #include <windows.h>
> #include <stdio.h>
>
> int main(){
>   int origcp = GetConsoleOutputCP();
>   SetConsoleOutputCP(CP_UTF8);
>   puts("Привет мир! Hello world!");
>   SetConsoleOutputCP(origcp);
>   return 0;
> }
>
> [Code B]
> #include <locale.h>
> #include <stdio.h>
>
> int main(){
>   setlocale (LC_ALL, "");
>   _putws(L"Привет мир! Hello world!");
>   return 0;
> }
>
> if the source code is in UTF-8 coding. Or compiled
> with -fexec-charset=utf-8.
>
> Both work as expected in command prompt as well as
> in current cygwin.

Sorry for being unclear.

The test program was only provided in order to provide a working
reproducer for an issue we see in _many_ instances.

In many cases, I am _not_ at liberty (nor do I have the time) to recompile
the programs.

And even if what you say is true, the fact is that there are many existing
executables out there that do not call `SetConsoleOutputCP()`.

All of them would be helped with my patch (provided that `LANG` or friends
define the charset to be `UTF-8`).

Are they buggy? Yes. Does the patch help the users? Also yes.

But what I am really a lot more interested in is your answer to the
question why the code path behind `disable_pcon` does anything different
from what v3.0.7 did.

I think that really is important to understand. Without that information,
I am not sure whether my patch is hiding an even bigger problem.

So please, please, please, can I have an answer to that? Why did the
non-Pseudo Console code path change? And in what way?

Ciao,
Johannes


More information about the Cygwin-developers mailing list