[PATCH v2 4/5] Cygwin: pty: Prevent pty from changing code page of parent console.
Takashi Yano
takashi.yano@nifty.ne.jp
Mon Jan 18 12:57:48 GMT 2021
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()?
--
Takashi Yano <takashi.yano@nifty.ne.jp>
More information about the Cygwin-patches
mailing list