Jean Abou Samra <j...@abou-samra.fr> writes:

> Le 21/06/2022 à 13:21, David Kastrup a écrit :
>> Jean Abou Samra <j...@abou-samra.fr> writes:
>>
>>> To check that, I applied
>>>
>>> diff --git a/lily/duration-scheme.cc b/lily/duration-scheme.cc
>>> index 5d9b4447f1..6a09253adf 100644
>>> --- a/lily/duration-scheme.cc
>>> +++ b/lily/duration-scheme.cc
>>> @@ -45,6 +45,8 @@ Is @var{p1} shorter than @var{p2}?
>>>     auto *const a = LY_ASSERT_SMOB (Duration, p1, 1);
>>>     auto *const b = LY_ASSERT_SMOB (Duration, p2, 2);
>>>
>>> +  scm_gc ();
>>> +
>>>     if (Duration::compare (*a, *b) < 0)
>>>       return SCM_BOOL_T;
>>>     else
>>>
>>> and compiled
>>>
>>> #(do ((i 0 (1+ i)))
>>>     ((= i 100))
>>>     (ly:duration<? #{ 4 #} #{ 8 #}))
>>>
>>>
>>> No crashes observed.
>> That tells you nothing at all unless you verify that the generated code
>> writes over p1 and p2 before scm_gc is called.  This is possible due to
>> optimisation but unlikely.
>
>
> <facepalm> Correct. Next try:
>
> diff --git a/lily/duration-scheme.cc b/lily/duration-scheme.cc
> index 5d9b4447f1..be75c6ac9d 100644
> --- a/lily/duration-scheme.cc
> +++ b/lily/duration-scheme.cc
> @@ -45,6 +45,11 @@ Is @var{p1} shorter than @var{p2}?
>    auto *const a = LY_ASSERT_SMOB (Duration, p1, 1);
>    auto *const b = LY_ASSERT_SMOB (Duration, p2, 2);
>
> +  p1 = SCM_UNDEFINED;
> +  p2 = SCM_UNDEFINED;
> +
> +  scm_gc ();
> +
>    if (Duration::compare (*a, *b) < 0)
>      return SCM_BOOL_T;
>    else
>
>
> Does that look better?

On its surface, but the compiler is free to optimise the assignments
away unless p1 and p2 are declared volatile.  Unless you disable
optimisations, there really is not much of a way around looking at the
actual code.

-- 
David Kastrup

Reply via email to