From: "Aktemur, Tankut Baris via Gdb-patches" <gdb-patches@sourceware.org>
To: Tom Tromey <tom@tromey.com>,
"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: RE: [PATCH 5/6] gdb/continuations: use lambdas instead of function pointers
Date: Thu, 22 Apr 2021 07:49:27 +0000 [thread overview]
Message-ID: <SN6PR11MB2893DA74A6BFB030FBFC5D58C4469@SN6PR11MB2893.namprd11.prod.outlook.com> (raw)
In-Reply-To: <87sg3ja0eb.fsf@tromey.com>
On Wednesday, April 21, 2021 9:44 PM, Tom Tromey wrote:
> >>>>> ">" == Tankut Baris Aktemur via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> >> Use lambdas and std::list to track inferior continuations. This is a
> >> refactoring.
>
> Thanks for the patch.
>
> >> @@ -122,7 +39,12 @@ void
> >> do_all_inferior_continuations ()
> >> {
> >> struct inferior *inf = current_inferior ();
> >> - do_my_continuations (&inf->continuations);
> >> + while (!inf->continuations.empty ())
> >> + {
> >> + auto &cont = inf->continuations.front ();
> >> + inf->continuations.pop_front ();
> >> + cont ();
>
> It seems like this sequence can lead to 'cont' referencing an invalid
> function, because 'cont' is just a reference, but pop_front will cause
> it to be destroyed.
Ah, thanks for catching that.
> Maybe "auto cont = std::move (...)" would work ok.
> Or, delaying the pop until after the callback is called seems fine as
> well.
The continuations at the moment are rather plain, but just in case a
continuation in the future adds more continuations, delaying the pop
could cause a wrong element to be popped, I'm afraid. How about the
following? (The same is to be used in Patch 6/6, too).
@@ -122,7 +39,12 @@ void
do_all_inferior_continuations ()
{
struct inferior *inf = current_inferior ();
- do_my_continuations (&inf->continuations);
+ while (!inf->continuations.empty ())
+ {
+ auto iter = inf->continuations.begin ();
+ (*iter) ();
+ inf->continuations.erase (iter);
+ }
}
> >> + A continuation is a closure (i.e. a lambda) to be called to finish
>
> I think it would be fine to say "A continuation is a std::function"
> here, because that encompasses lambdas but also other valid forms, like
> ordinary functions.
Out of curiosity, how do you pronounce 'std'? I was just thinking if it
should be "a std::function" or "an std::function". I pronounce std as
"ess-tee-dee" and "an" sounded more natural to me.
> >> + std::list<std::function<void ()> > continuations;
>
> gdb style usually uses the ">>" token instead of adding the space here.
>
> thanks,
> Tom
Fixed.
Thanks
-Baris
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
next prev parent reply other threads:[~2021-04-22 7:49 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-21 12:57 [PATCH 0/6] Refactoring around inferior continuations Tankut Baris Aktemur via Gdb-patches
2021-04-21 12:57 ` [PATCH 1/6] gdb/infcmd: remove the unused parameter 'args' in 'attach_post_wait' Tankut Baris Aktemur via Gdb-patches
2021-04-21 19:24 ` Tom Tromey
2021-04-21 19:32 ` Simon Marchi via Gdb-patches
2021-04-21 19:47 ` Tom Tromey
2021-04-22 5:57 ` Aktemur, Tankut Baris via Gdb-patches
2021-04-21 12:57 ` [PATCH 2/6] gdb/infcmd: update the comment for 'attach_post_wait' Tankut Baris Aktemur via Gdb-patches
2021-04-21 19:25 ` Tom Tromey
2021-04-21 12:57 ` [PATCH 3/6] gdb/continuations: remove the 'err' from 'do_all_inferior_continuations' Tankut Baris Aktemur via Gdb-patches
2021-04-21 19:29 ` Tom Tromey
2021-04-21 12:57 ` [PATCH 4/6] gdb/continuations: do minor cleanup Tankut Baris Aktemur via Gdb-patches
2021-04-21 19:31 ` Tom Tromey
2021-04-21 12:57 ` [PATCH 5/6] gdb/continuations: use lambdas instead of function pointers Tankut Baris Aktemur via Gdb-patches
2021-04-21 19:43 ` Tom Tromey
2021-04-22 7:49 ` Aktemur, Tankut Baris via Gdb-patches [this message]
2021-04-22 12:50 ` Tom Tromey
2021-04-22 14:07 ` Aktemur, Tankut Baris via Gdb-patches
2021-04-22 14:12 ` Tom Tromey
2021-04-21 12:57 ` [PATCH 6/6] gdb/continuations: turn continuation functions into inferior methods Tankut Baris Aktemur via Gdb-patches
2021-04-21 19:46 ` Tom Tromey
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=SN6PR11MB2893DA74A6BFB030FBFC5D58C4469@SN6PR11MB2893.namprd11.prod.outlook.com \
--to=gdb-patches@sourceware.org \
--cc=tankut.baris.aktemur@intel.com \
--cc=tom@tromey.com \
/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