This is the mail archive of the gdb-testers@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] fork-child.c: Avoid unnecessary heap-allocation / string copying


*** TEST RESULTS FOR COMMIT 808480f667e41e2fdb66bfdc9d5e047f1aa34a68 ***

Author: Pedro Alves <palves@redhat.com>
Branch: master
Commit: 808480f667e41e2fdb66bfdc9d5e047f1aa34a68

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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]