public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin-patches@cygwin.com
Subject: Re: [PATCH v2 4/5] Cygwin: pty: Prevent pty from changing code page of parent console.
Date: Mon, 18 Jan 2021 14:00:16 +0100	[thread overview]
Message-ID: <20210118130016.GD59030@calimero.vinschen.de> (raw)
In-Reply-To: <20210118215748.53084ce47333655288d09aaa@nifty.ne.jp>

On Jan 18 21:57, Takashi Yano via Cygwin-patches wrote:
> On Mon, 18 Jan 2021 13:39:01 +0100
> Corinna Vinschen wrote:
> > Sorry if I'm slow, but I was just mulling over this code snippet again,
> > and I was wondering if we couldn't do without the HeapAlloc loop.
> > Assuming you use a tmp_pathbuf here, you'd have space for 16384
> > processes per console.  Shouldn't that be more than enough?  I.e.
> > 
> > static DWORD
> > get_console_process_id (DWORD pid, bool match)
> > {
> >   tmp_pathbuf tp;
> >   DWORD *list = (DWORD *) tp.w_get ();
> >   const DWORD num = NT_MAX_PATH * sizeof (WCHAR) / sizeof (DWORD);
> >   DWORD res = 0;
> > 
> >   num = GetConsoleProcessList (&list, num);
> > 
> >   /* Last one is the oldest. */
> >   /* https://github.com/microsoft/terminal/issues/95 */
> >   for (int i = (int) num - 1; i >= 0; i--)
> >     if ((match && list[i] == pid) || (!match && list[i] != pid))
> >       {
> > 	res = list[i];
> > 	break;
> >       }
> >   return res;
> > }
> > 
> > 
> > What do you think?
> 
> That's more that enough. I will submit v3 patch. Thanks again.
> By the way, why do you think tmp_pathbuf is better than HeapAlloc()?

tmp_pathbuf never frees the buffers it used at least once. so
chances are hight that the call just returns the next free
pointer to an already alloocated buffer.


Corinna

      reply	other threads:[~2021-01-18 13:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-18 11:24 Takashi Yano
2021-01-18 12:39 ` Corinna Vinschen
2021-01-18 12:57   ` Takashi Yano
2021-01-18 13:00     ` 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=20210118130016.GD59030@calimero.vinschen.de \
    --to=corinna-cygwin@cygwin.com \
    --cc=cygwin-patches@cygwin.com \
    /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).