[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: C++ question on wrapper API for setting Guile fluids
From: |
Dan Eble |
Subject: |
Re: C++ question on wrapper API for setting Guile fluids |
Date: |
Wed, 20 Apr 2022 22:57:40 -0400 |
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 ()
}
> 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.
—
Dan
Re: C++ question on wrapper API for setting Guile fluids, Han-Wen Nienhuys, 2022/04/21