fork-child.c: Avoid unnecessary heap-allocation / string copying
authorPedro Alves <palves@redhat.com>
Thu, 13 Apr 2017 10:46:07 +0000 (11:46 +0100)
committerPedro Alves <palves@redhat.com>
Thu, 13 Apr 2017 10:46:07 +0000 (11:46 +0100)
commit808480f667e41e2fdb66bfdc9d5e047f1aa34a68
tree6af17a76cdbe8aa21e47ea3e68c173f553c5dec4
parent8f0dd45fde9de100160f45cad3e537e4e01a5493
fork-child.c: Avoid unnecessary heap-allocation / string copying

The previous change to fork-child.c converted the argv building from
an alloca-allocated array of non-owning arg pointers, to a std::vector
of owning pointers, which results in N string dups, with N being the
number of arguments in the vector, and then requires manually
releasing the pointers owned by the vector.

This patch makes the vector hold non-owning pointers, and avoids the
string dups, by doing one single string copy of the arguments upfront,
and replacing separators with NULL terminators in place, like we used
to.  All the logic to do that is encapsulated in a new class.

With this, there's no need to remember to manually release the argv
elements with free_vector_argv either.

gdb/ChangeLog:
2017-04-13  Pedro Alves  <palves@redhat.com>

* fork-child.c (execv_argv): New class.
(breakup_args): Refactored as ...
(execv_argv::init_for_no_shell): .. this method of execv_argv.
Copy arguments to storage and replace separators with NULL
terminators in place.
(escape_bang_in_quoted_argument): Adjust to return bool.
(execv_argv::execv_argv): New ctor.
(execv_argv::init_for_shell): New method, factored out from
fork_inferior.  Don't strdup strings into the vector.
(fork_inferior): Eliminate "shell" local and use execv_argv.  Use
Remove free_vector_argv call.
gdb/ChangeLog
gdb/fork-child.c
This page took 0.033721 seconds and 4 git commands to generate.