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

> Le 17/06/2022 à 23:49, David Kastrup a écrit :
>> Jean Abou Samra <j...@abou-samra.fr> writes:
>>
>>> By the way, I have a side question. Suppose I have determined
>>> that I need to mark the local variable scm_obj with
>>> scm_remember_upto_here in this code:
>>>
>>> SCM scm_obj = get_it_from_somewhere ();
>>>
>>> return something_that_needs_scm_obj_alive;
>>>
>>> // Is this correct?
>>> scm_remember_upto_here (scm_obj);
>>>
>>>
>>> Might the compiler detect that return exits the function and
>>> ignore the scm_remember_upto_here?
>> return; releases the stack frame.  "return
>> something_that_needs_scm_obj_alive;" is not a valid pattern unless the
>> returned value itself is an SCM that will cover scm_obj in its GC scope.
>
>
>
> Well, I was thinking of something like this:
>
> Pitch *p = unsmob<Pitch> (scm_pitch);
> return *p;
> scm_remember_upto_here (scm_pitch); // ??

Not a good pattern.  Just use Pitch p = ...

scm_remember_upto_here is not a magic instruction to the compiler but
just C code that requires scm_pitch to be still defined.  Putting it
into a code path that is not being executed is useless.

-- 
David Kastrup

Reply via email to