This is the mail archive of the gdb-patches@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]

Re: [RFA] Return unique_xmalloc_ptr from target_fileio_readlink


Hi Tom,

On 2017-11-23 11:39 AM, Tom Tromey wrote:
> This changes to_fileio_readlink and target_fileio_readlink to return a
> unique_xmalloc_ptr, and then fixes up the callers and implementations.
> This allows the removal of some cleanups.
> 
> I chose unique_xmalloc_ptr rather than std::string due to the NULL
> return -- although a symlink can't point to the empty string, so an
> empty string could be used instead, it seemed obscure to do so.
What about gdb::optional<std::string> or std::unique_ptr<std::string>?

> --- a/gdb/linux-tdep.c
> +++ b/gdb/linux-tdep.c
> @@ -759,26 +759,20 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args,
>    if (cwd_f)
>      {
>        xsnprintf (filename, sizeof filename, "/proc/%ld/cwd", pid);
> -      data = target_fileio_readlink (NULL, filename, &target_errno);
> -      if (data)
> -	{
> -	  struct cleanup *cleanup = make_cleanup (xfree, data);
> -          printf_filtered ("cwd = '%s'\n", data);
> -	  do_cleanups (cleanup);
> -	}
> +      gdb::unique_xmalloc_ptr<char> contents
> +	= target_fileio_readlink (NULL, filename, &target_errno);
> +      if (contents)

contents != NULL

> +	printf_filtered ("cwd = '%s'\n", contents.get ());
>        else
>  	warning (_("unable to read link '%s'"), filename);
>      }
>    if (exe_f)
>      {
>        xsnprintf (filename, sizeof filename, "/proc/%ld/exe", pid);
> -      data = target_fileio_readlink (NULL, filename, &target_errno);
> -      if (data)
> -	{
> -	  struct cleanup *cleanup = make_cleanup (xfree, data);
> -          printf_filtered ("exe = '%s'\n", data);
> -	  do_cleanups (cleanup);
> -	}
> +      gdb::unique_xmalloc_ptr<char> contents
> +	= target_fileio_readlink (NULL, filename, &target_errno);
> +      if (contents)

contents != NULL

Simon


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