Re: [PATCH v2 21/31] Use ui_file_as_string in gdb/compile/

Simon Marchi
2016-10-19T23:08:44Z

The doc for get_new_file_names should probably be updated:

/* Compute the names of source and object files to use. The names are
allocated by malloc and should be freed by the caller. */

> static void
> -get_new_file_names (char **source_file, char **object_file)
> +get_new_file_names (std::string *source_file, std::string
> *object_file)
> {

Same for compile_to_object, both for the "freeing" part and the part
that talks about the return value.

We should use $other_language instead of C++, to be able to do

source_filep, object_filep = compile_to_object (...)

:)

Btw, would it be good to use references for those strings?

> error condition, error () is called. The caller is responsible for
> freeing both strings. */
>
> -static char *
> +static void
> compile_to_object (struct command_line *cmd, const char *cmd_string,
> enum compile_i_scope_types scope,
> - char **source_filep)
> + std::string *source_filep,
> + std::string *object_filep)
> {

...

> @@ -609,30 +606,27 @@ void
> eval_compile_command (struct command_line *cmd, const char
> *cmd_string,
> enum compile_i_scope_types scope, void *scope_data)
> {
> - char *object_file, *source_file;
> + std::string source_file, object_file;
>
> - object_file = compile_to_object (cmd, cmd_string, scope,
> &source_file);
> - if (object_file != NULL)
> + compile_to_object (cmd, cmd_string, scope, &source_file,
> &object_file);
> + if (!object_file.empty ())

Can this actually happen?