* spawn.cc (child_info_spawn::worker): Eliminate call to newargv.set() in favor

of conglomerated newargv.setup().  Let newargv.setup() decide when to call
dup_all().  Only set argc and argv for cygwin processes.
(av::setup): Rename from av::fixup.  Accept argc and argv parameters.  Fill out
argv and argc here.  Duplicate whole argv structure when this is a Cygwin
executable.
* winf.cc (linebuf::fromargv): Don't bother duplicating argv elements since
they will never be used.
* winf.h (av::set): Delete.
(av::setup): Rename from av::fixup.  Add two parameters.
(av::replace0_maybe): Assign calloced to 1 rather than 'true' for clarity.
(av::dup_maybe): Delete.
(av::dup_all): Set calloced to show that we have duplicated all of the
arguments in the list.
This commit is contained in:
Christopher Faylor 2013-06-19 16:00:43 +00:00
parent 82c19d335a
commit 37ee5b49af
4 changed files with 181 additions and 170 deletions

View File

@ -1,3 +1,21 @@
2013-06-19 Christopher Faylor <me.cygwin2013@cgf.cx>
* spawn.cc (child_info_spawn::worker): Eliminate call to newargv.set()
in favor of conglomerated newargv.setup(). Let newargv.setup() decide
when to call dup_all(). Only set argc and argv for cygwin processes.
(av::setup): Rename from av::fixup. Accept argc and argv parameters.
Fill out argv and argc here. Duplicate whole argv structure when this
is a Cygwin executable.
* winf.cc (linebuf::fromargv): Don't bother duplicating argv elements
since they will never be used.
* winf.h (av::set): Delete.
(av::setup): Rename from av::fixup. Add two parameters.
(av::replace0_maybe): Assign calloced to 1 rather than 'true' for
clarity.
(av::dup_maybe): Delete.
(av::dup_all): Set calloced to show that we have duplicated all of the
arguments in the list.
2013-06-18 Corinna Vinschen <corinna@vinschen.de>
* nlsfuncs.cc (__collate_range_cmp): Convert input to wchar_t and call

View File

@ -359,8 +359,6 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
for (ac = 0; argv[ac]; ac++)
/* nothing */;
newargv.set (ac, argv);
int err;
const char *ext;
if ((ext = perhaps_suffix (prog_arg, real_path, err, FE_NADA)) == NULL)
@ -370,7 +368,7 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
goto out;
}
res = newargv.fixup (prog_arg, real_path, ext, p_type_exec);
res = newargv.setup (prog_arg, real_path, ext, ac, argv, p_type_exec);
if (res)
goto out;
@ -405,7 +403,10 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
else
{
if (real_path.iscygexec ())
newargv.dup_all ();
{
moreinfo->argc = newargv.argc;
moreinfo->argv = newargv;
}
else if (!one_line.fromargv (newargv, real_path.get_win32 (),
real_path.iscygexec ()))
{
@ -414,10 +415,6 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
}
newargv.all_calloced ();
moreinfo->argc = newargv.argc;
moreinfo->argv = newargv;
if (mode != _P_OVERLAY || !real_path.iscygexec ()
|| !DuplicateHandle (GetCurrentProcess (), myself.shared_handle (),
GetCurrentProcess (), &moreinfo->myself_pinfo,
@ -1073,17 +1070,18 @@ spawnvpe (int mode, const char *file, const char * const *argv,
}
int
av::fixup (const char *prog_arg, path_conv& real_path, const char *ext,
bool p_type_exec)
av::setup (const char *prog_arg, path_conv& real_path, const char *ext,
int argc, const char *const *argv, bool p_type_exec)
{
const char *p;
bool exeext = ascii_strcasematch (ext, ".exe");
if ((exeext && real_path.iscygexec ()) || ascii_strcasematch (ext, ".bat"))
return 0;
if (!*ext && ((p = ext - 4) > real_path.get_win32 ())
new (this) av (argc, argv);
if ((exeext && real_path.iscygexec ()) || ascii_strcasematch (ext, ".bat")
|| (!*ext && ((p = ext - 4) > real_path.get_win32 ())
&& (ascii_strcasematch (p, ".bat") || ascii_strcasematch (p, ".cmd")
|| ascii_strcasematch (p, ".btm")))
return 0;
|| ascii_strcasematch (p, ".btm"))))
/* no extra checks needed */;
else
while (1)
{
char *pgm = NULL;
@ -1202,7 +1200,7 @@ av::fixup (const char *prog_arg, path_conv& real_path, const char *ext,
}
}
UnmapViewOfFile (buf);
just_shell:
just_shell:
if (!pgm)
{
if (!p_type_exec)
@ -1241,6 +1239,8 @@ just_shell:
find_exec (pgm, real_path, "PATH=", FE_NATIVE, &ext);
unshift (real_path.get_win32 (), 1);
}
if (real_path.iscygexec ())
dup_all ();
return 0;
err:

View File

@ -73,7 +73,6 @@ linebuf::fromargv (av& newargv, const char *real_path, bool cmdlenoverflow_ok)
char *p = NULL;
const char *a;
newargv.dup_maybe (i);
a = i ? newargv[i] : (char *) real_path;
int len = strlen (a);
if (len != 0 && !strpbrk (a, " \t\n\r\""))

View File

@ -34,13 +34,11 @@ class av
memcpy (argv, av_in, (argc + 1) * sizeof (char *));
}
void *operator new (size_t, void *p) __attribute__ ((nothrow)) {return p;}
void set (int ac_in, const char * const *av_in) {new (this) av (ac_in, av_in);}
~av ()
{
if (argv)
{
for (int i = 0; i < calloced; i++)
if (argv[i])
cfree (argv[i]);
cfree (argv);
}
@ -54,20 +52,16 @@ class av
if (!calloced)
{
argv[0] = cstrdup1 (arg0);
calloced = true;
calloced = 1;
}
}
void dup_maybe (int i)
{
if (i >= calloced)
argv[i] = cstrdup1 (argv[i]);
}
void dup_all ()
{
for (int i = calloced; i < argc; i++)
argv[i] = cstrdup1 (argv[i]);
calloced = argc;
}
int fixup (const char *, path_conv&, const char *, bool);
int setup (const char *, path_conv&, const char *, int, const char *const *, bool) __reg3;
};
class linebuf