Re: [PATCH 5/6] gdb/continuations: use lambdas instead of function pointers

Tom Tromey
2021-04-21T19:44:02Z

>>>>> ">" == 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.

Maybe "auto cont = std::move (...)" would work ok.
Or, delaying the pop until after the callback is called seems fine as
well.

>> + 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.

>> + std::list<std::function<void ()> > continuations;

gdb style usually uses the ">>" token instead of adding the space here.

thanks,
Tom