From: Pedro Alves <palves@redhat.com>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH v2 5/5] Eliminate make_cleanup_ui_file_delete / make ui_file a class hierarchy
Date: Wed, 25 Jan 2017 18:28:00 -0000 [thread overview]
Message-ID: <0a004b52-a388-e7ec-fe3e-ccac3e31f7b2@redhat.com> (raw)
In-Reply-To: <91ab941736dd82a711868ea56651c20d@polymtl.ca>
On 01/24/2017 07:11 PM, Simon Marchi wrote:
> Can xstrdup take an std::string? Implicit conversions only go the other
> way I think.
Meh. No, that's broken. I'll fix it.
>
> It might be worth sending the series on the buildbot to test AIX.
I'll try building this on gcc119 (AIX 7.2) on the compile farm.
From the discussion on gdb@, the bot is broken. :-/
>> + string_file stb;
>> + stb.printf ("%s%s%s",
>> + _("The valid values are:\n"),
>> + regdesc,
>> + _("The default is \"std\"."));
>> + helptext = std::move (stb.string ());
>
> I think having that static helptext variable is useless here. The help
> text is copied in add_setshow_enum_cmd, so we don't need to keep
> helptext for the whole lifetime of the program. We could pass stb.c_str
> () directly to add_setshow_enum_cmd.
OK. While at it, this can actually be a string_printf
instead of a string_file. I've made that change.
>
>> +class string_file : public ui_file
>> +{
>> +public:
>> + string_file () {}
>> + ~string_file () override;
>>
>> -/* Returns a std::string containing the entire contents of FILE (as
>> - determined by ui_file_put()). */
>> -extern std::string ui_file_as_string (struct ui_file *file);
>> + /* Override ui_file methods. */
>>
>> -/* Similar to ui_file_xstrdup, but return a new string allocated on
>> - OBSTACK. */
>> -extern char *ui_file_obsavestring (struct ui_file *file,
>> - struct obstack *obstack, long *length);
>> + void write (const char *buf, long length_buf) override;
>>
>> -extern long ui_file_read (struct ui_file *file, char *buf, long
>> length_buf);
>> + long read (char *buf, long length_buf) override
>> + { gdb_assert_not_reached ("a string_file is not readable"); }
>> +
>> + /* string_file-specific public API. */
>> +
>> + /* Accesses the std::string containing the entire output collected
>> + so far. Returns a non-const reference so that it's easy to move
>> + the string contents out of the string_file. */
>
> I didn't understand what you meant by "to move the string contents
> out..." until I saw this
>
> helptext = std::move (stb.string ());
>
> If it had been "to std::move the string contents out..." it might have
> been a bit clearer, I'm not entirely sure.
That would read a bit odd to me, since "std::move" itself
does nothing, it's just a cast. Maybe it'll be clearer with
an example? Something like:
/* Accesses the std::string containing the entire output collected
- so far. Returns a non-const reference so that it's easy to move
- the string contents out of the string_file. */
+ so far.
+
+ Returns a non-const reference so that it's easy to move the
+ string contents out of the string_file. E.g.:
+
+ string_file buf;
+ buf.printf (....");
+ buf.printf (....");
+ return std::move (buf.string ());
+ */
std::string &string () { return m_string; }
>
>> --- a/gdb/utils.c
>> +++ b/gdb/utils.c
>> @@ -187,18 +187,6 @@ make_cleanup_obstack_free (struct obstack *obstack)
>> return make_cleanup (do_obstack_free, obstack);
>> }
>>
>> -static void
>> -do_ui_file_delete (void *arg)
>> -{
>> - ui_file_delete ((struct ui_file *) arg);
>> -}
>> -
>> -struct cleanup *
>> -make_cleanup_ui_file_delete (struct ui_file *arg)
>> -{
>> - return make_cleanup (do_ui_file_delete, arg);
>> -}
>> -
>
> You can remove the declaration in utils.h for this.
Indeed. Fixed.
>
> That's all for me.
>
> Thanks!
Thank you!
--
Pedro Alves
next prev parent reply other threads:[~2017-01-25 18:28 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-17 1:39 [PATCH 0/5] Eliminate cleanups & make ui_file a C++ " Pedro Alves
2017-01-17 1:39 ` [PATCH 3/5] gdb/stack.c: Remove unused mem_fileopen Pedro Alves
2017-01-17 1:39 ` [PATCH 1/5] gdb: make_scoped_restore and types convertible to T Pedro Alves
2017-01-17 1:39 ` [PATCH 2/5] gdb/varobj.c: Fix leak Pedro Alves
2017-01-17 1:39 ` [PATCH 5/5] Eliminate make_cleanup_ui_file_delete / make ui_file a class hierarchy Pedro Alves
2017-01-17 19:57 ` Simon Marchi
2017-01-17 19:58 ` Simon Marchi
2017-01-23 16:58 ` Pedro Alves
2017-01-23 17:17 ` Pedro Alves
2017-01-23 19:18 ` Simon Marchi
2017-01-23 23:19 ` [PATCH v2 " Pedro Alves
2017-01-24 18:29 ` Simon Marchi
2017-01-24 19:14 ` Simon Marchi
2017-01-25 18:37 ` Pedro Alves
2017-01-25 17:52 ` Pedro Alves
2017-01-25 19:31 ` Pedro Alves
2017-01-25 19:47 ` [PATCH v3 " Pedro Alves
2017-02-01 0:31 ` Pedro Alves
2017-01-25 18:27 ` [PATCH v2 " Pedro Alves
2017-01-24 19:11 ` Simon Marchi
2017-01-25 18:28 ` Pedro Alves [this message]
2017-01-25 18:39 ` Simon Marchi
2017-01-25 18:41 ` Pedro Alves
2017-01-17 1:47 ` [PATCH 4/5] gdb/mi/mi-interp.c: Fix typos Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0a004b52-a388-e7ec-fe3e-ccac3e31f7b2@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox