This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA] Return unique_xmalloc_ptr from target_fileio_readlink
- From: Simon Marchi <simon dot marchi at ericsson dot com>
- To: Tom Tromey <tom at tromey dot com>, <gdb-patches at sourceware dot org>
- Date: Thu, 23 Nov 2017 14:28:34 -0500
- Subject: Re: [RFA] Return unique_xmalloc_ptr from target_fileio_readlink
- Authentication-results: sourceware.org; auth=none
- Authentication-results: spf=none (sender IP is ) smtp.mailfrom=simon dot marchi at ericsson dot com;
- References: <20171123163915.4604-1-tom@tromey.com>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
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