From: Ian Lance Taylor <iant@google.com>
To: Ray Donnelly <mingw.android@gmail.com>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>, Kai Tietz <ktietz70@gmail.com>
Subject: Re: [PATCH] Windows libibery: Don't quote args unnecessarily
Date: Fri, 09 May 2014 05:08:00 -0000 [thread overview]
Message-ID: <CAKOQZ8xmmzYEGkcWRrvOZ2-X5CARSkOM0GVBV_9XiPUxZ5GugA@mail.gmail.com> (raw)
In-Reply-To: <1399445760-4060-2-git-send-email-mingw.android@gmail.com>
On Tue, May 6, 2014 at 11:56 PM, Ray Donnelly <mingw.android@gmail.com> wrote:
> We only quote arguments that contain spaces, \t or "
> characters to prevent wasting 2 characters per
> argument of the CreateProcess() 32,768 limit.
This is OK.
Thanks.
Ian
> libiberty/pex-win32.c | 46 +++++++++++++++++++++++++++++++++++++---------
> 1 file changed, 37 insertions(+), 9 deletions(-)
>
> diff --git a/libiberty/pex-win32.c b/libiberty/pex-win32.c
> index eae72c5..8b9d4f0 100644
> --- a/libiberty/pex-win32.c
> +++ b/libiberty/pex-win32.c
> @@ -340,17 +340,25 @@ argv_to_cmdline (char *const *argv)
> char *p;
> size_t cmdline_len;
> int i, j, k;
> + int needs_quotes;
>
> cmdline_len = 0;
> for (i = 0; argv[i]; i++)
> {
> - /* We quote every last argument. This simplifies the problem;
> - we need only escape embedded double-quotes and immediately
> + /* We only quote arguments that contain spaces, \t or " characters to
> + prevent wasting 2 chars per argument of the CreateProcess 32k char
> + limit. We need only escape embedded double-quotes and immediately
> preceeding backslash characters. A sequence of backslach characters
> that is not follwed by a double quote character will not be
> escaped. */
> + needs_quotes = 0;
> for (j = 0; argv[i][j]; j++)
> {
> + if (argv[i][j] == ' ' || argv[i][j] == '\t' || argv[i][j] == '"')
> + {
> + needs_quotes = 1;
> + }
> +
> if (argv[i][j] == '"')
> {
> /* Escape preceeding backslashes. */
> @@ -362,16 +370,33 @@ argv_to_cmdline (char *const *argv)
> }
> /* Trailing backslashes also need to be escaped because they will be
> followed by the terminating quote. */
> - for (k = j - 1; k >= 0 && argv[i][k] == '\\'; k--)
> - cmdline_len++;
> + if (needs_quotes)
> + {
> + for (k = j - 1; k >= 0 && argv[i][k] == '\\'; k--)
> + cmdline_len++;
> + }
> cmdline_len += j;
> - cmdline_len += 3; /* for leading and trailing quotes and space */
> + /* for leading and trailing quotes and space */
> + cmdline_len += needs_quotes * 2 + 1;
> }
> cmdline = XNEWVEC (char, cmdline_len);
> p = cmdline;
> for (i = 0; argv[i]; i++)
> {
> - *p++ = '"';
> + needs_quotes = 0;
> + for (j = 0; argv[i][j]; j++)
> + {
> + if (argv[i][j] == ' ' || argv[i][j] == '\t' || argv[i][j] == '"')
> + {
> + needs_quotes = 1;
> + break;
> + }
> + }
> +
> + if (needs_quotes)
> + {
> + *p++ = '"';
> + }
> for (j = 0; argv[i][j]; j++)
> {
> if (argv[i][j] == '"')
> @@ -382,9 +407,12 @@ argv_to_cmdline (char *const *argv)
> }
> *p++ = argv[i][j];
> }
> - for (k = j - 1; k >= 0 && argv[i][k] == '\\'; k--)
> - *p++ = '\\';
> - *p++ = '"';
> + if (needs_quotes)
> + {
> + for (k = j - 1; k >= 0 && argv[i][k] == '\\'; k--)
> + *p++ = '\\';
> + *p++ = '"';
> + }
> *p++ = ' ';
> }
> p[-1] = '\0';
> --
> 1.9.2
>
next prev parent reply other threads:[~2014-05-09 5:08 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-19 19:41 [PATCH 0/2] Windows: Two improvements Ray Donnelly
2014-04-19 19:41 ` [PATCH 1/2] Windows libibery: Don't quote args unnecessarily Ray Donnelly
2014-04-19 20:41 ` Kai Tietz
2014-04-20 6:37 ` Eli Zaretskii
2014-04-21 15:38 ` Joel Brobecker
2014-04-19 20:23 ` [PATCH 2/2] Windows libcpp: Make path-exists semantics more Posix-like Ray Donnelly
2014-04-20 6:07 ` Kai Tietz
2014-04-25 16:58 ` Pedro Alves
2014-04-25 19:24 ` Kai Tietz
2014-04-25 19:35 ` Pedro Alves
2014-04-25 20:34 ` Kai Tietz
2015-08-18 20:23 ` Ray Donnelly
2014-04-25 17:06 ` Pedro Alves
2014-05-07 6:56 ` [PATCH] Windows libiberty: Don't quote args unnecessarily (v2) Ray Donnelly
2014-05-07 6:56 ` [PATCH] Windows libibery: Don't quote args unnecessarily Ray Donnelly
2014-05-08 7:22 ` Kai Tietz
2014-05-09 5:08 ` Ian Lance Taylor [this message]
2014-05-08 7:19 ` [PATCH] Windows libiberty: Don't quote args unnecessarily (v2) Kai Tietz
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=CAKOQZ8xmmzYEGkcWRrvOZ2-X5CARSkOM0GVBV_9XiPUxZ5GugA@mail.gmail.com \
--to=iant@google.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=ktietz70@gmail.com \
--cc=mingw.android@gmail.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).