lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C++ question on wrapper API for setting Guile fluids


From: Jean Abou Samra
Subject: Re: C++ question on wrapper API for setting Guile fluids
Date: Thu, 21 Apr 2022 08:11:11 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0

Le 21/04/2022 à 04:57, Dan Eble a écrit :
On Apr 20, 2022, at 18:04, Jean Abou Samra <jean@abou-samra.fr> wrote:
Calls to scm_dynwind_begin () and scm_dynwind_end () must be
paired correctly. Obviously, if '...' contains statements
causing non-local control flow like return, break, continue,
and such, it is easy to miss a scm_dynwind_end (). I read
that you can avoid that using RAII:
Yes.

   {
     // Constructor does scm_dynwind_begin () and scm_dynwind_fluid ()
     Fluid_setter setter (fluid, value);
Might you want to call scm_dynwind_fluid () more than once?  How about this?

     {
       // dwc constructor calls scm_dynwind_begin ()
       Dynwind_context dwc;
       scm_dynwind_fluid (fluid1, value1);
       scm_dynwind_fluid (fluid2, value2);
       . . .
       // dwc destructor calls scm_dynwind_end ()
     }



Why not. There is likely just one caller that will need to introduce several
fluids at once, but it is probably clearer this way.



What disturbs me slightly with this approach is the variable 'setter',
which will never be used, but must nevertheless be defined in order
for the object not to be thrown away as temporary.
If I understand you, turning the main effect (scm_dynwind_begin) into a side 
effect of the constructor bothers you.  It wouldn't bother me as long as the 
class had a good name.  I can think of two alternatives, but they have their 
own problems.

Does that sound about right? Would this be considered an idiomatic
approach?
Yes.


Thanks!

Jean



reply via email to

[Prev in Thread] Current Thread [Next in Thread]