From 949c0ec28c86623b83ae56651c00d1bd3c3a5d0c Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Mon, 10 Mar 2008 17:23:50 +0000 Subject: [PATCH] * fhandler.h (class fhandler_console): Add write_buf as pointer to temporary buffer space. * fhandler_console.cc (CONVERT_LIMIT): Define as NT_MAX_PATH. Add comment. (fhandler_console::write_normal): Use write_buf throughout. (fhandler_console::write): Use tmp_pathbuf to allocate write_buf. --- winsup/cygwin/ChangeLog | 9 +++++++++ winsup/cygwin/fhandler.h | 3 ++- winsup/cygwin/fhandler_console.cc | 21 ++++++++++++++------- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index d1697badf..6ee0b2cfe 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,12 @@ +2008-03-10 Corinna Vinschen + + * fhandler.h (class fhandler_console): Add write_buf as pointer to + temporary buffer space. + * fhandler_console.cc (CONVERT_LIMIT): Define as NT_MAX_PATH. Add + comment. + (fhandler_console::write_normal): Use write_buf throughout. + (fhandler_console::write): Use tmp_pathbuf to allocate write_buf. + 2008-03-10 Corinna Vinschen * fhandler_console.cc (fhandler_console::write_normal): Don't print diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index cedf7f987..f78861cde 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -884,7 +884,7 @@ class dev_console bool raw_win32_keyboard_mode; inline UINT get_console_cp (); - bool con_to_str (char *d, int dlen, WCHAR w); + DWORD con_to_str (char *d, int dlen, WCHAR w); DWORD str_to_con (PWCHAR d, const char *s, DWORD sz); void set_color (HANDLE); bool fillin_info (HANDLE); @@ -906,6 +906,7 @@ class fhandler_console: public fhandler_termios int len; unsigned char buf[4]; /* Max len of valid UTF-8 sequence. */ } trunc_buf; + PWCHAR write_buf; /* Output calls */ void set_default_attr (); diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index 2b8b45703..2d5e18b9b 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -31,9 +31,12 @@ details. */ #include "pinfo.h" #include "shared_info.h" #include "cygtls.h" +#include "tls_pbuf.h" #include "registry.h" -#define CONVERT_LIMIT 65536 +/* Don't make this bigger than NT_MAX_PATH as long as the temporary buffer + is allocated using tmp_pathbuf!!! */ +#define CONVERT_LIMIT NT_MAX_PATH /* * Scroll the screen context. @@ -1473,10 +1476,10 @@ fhandler_console::write_normal (const unsigned char *src, /* Valid multibyte sequence? Process. */ if (nfound) { - WCHAR buf[2]; - buf_len = dev_state->str_to_con (buf, (const char *) trunc_buf.buf, + buf_len = dev_state->str_to_con (write_buf, + (const char *) trunc_buf.buf, nfound - trunc_buf.buf); - WriteConsoleW (get_output_handle (), buf, buf_len, &done, 0); + WriteConsoleW (get_output_handle (), write_buf, buf_len, &done, 0); found = src + (nfound - trunc_buf.buf - trunc_buf.len); trunc_buf.len = 0; return found; @@ -1509,9 +1512,7 @@ fhandler_console::write_normal (const unsigned char *src, if (found != src) { DWORD len = found - src; - PWCHAR buf = (PWCHAR) alloca (CONVERT_LIMIT * sizeof (WCHAR)); - - buf_len = dev_state->str_to_con (buf, (const char *) src, len); + buf_len = dev_state->str_to_con (write_buf, (const char *) src, len); if (!buf_len) { debug_printf ("conversion error, handle %p", @@ -1527,6 +1528,7 @@ fhandler_console::write_normal (const unsigned char *src, scroll_screen (x, y, -1, y, x + buf_len, y); } + register PWCHAR buf = write_buf; do { if (!WriteConsoleW (get_output_handle (), buf, buf_len, &done, 0)) @@ -1600,6 +1602,11 @@ fhandler_console::write (const void *vsrc, size_t len) /* Run and check for ansi sequences */ unsigned const char *src = (unsigned char *) vsrc; unsigned const char *end = src + len; + /* This might look a bit far fetched, but using the TLS path buffer allows + to allocate a big buffer without using the stack too much. Doing it here + in write instead of in write_normal should be faster, too. */ + tmp_pathbuf tp; + write_buf = tp.w_get (); debug_printf ("%x, %d", vsrc, len);