guile-devel
[Top][All Lists]
Advanced

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

Re: scm_remember


From: Marius Vollmer
Subject: Re: scm_remember
Date: 01 Nov 2000 11:51:23 +0100
User-agent: Gnus/5.0803 (Gnus v5.8.3) Emacs/20.7

Dirk Herrmann <address@hidden> writes:

> Hello!
> 
> The function scm_remember has the purpose, to protect its argument from
> gc:
> 
>   chars = SCM_STRING_CHARS (str);
>   some_syscall (chars);
>   scm_remember (&str);
> 
> The call to scm_remember forces the compiler to keep the value str
> alive until after the call to some_syscall.  Currently, scm_remember
> expects a scm* as its parameter.  However, for the sake of keeping the
> value alive it would suffice to pass the SCM value:
> 
>   chars = SCM_STRING_CHARS (str);
>   some_syscall (chars);
>   scm_remember (str);
> 
> The protection is the same,

Hmm, the former will make sure that `str' stays on the stack, and you
can use the variable `str' to point to different SCM objects in the
course of the function and they wil all be protected.

For example:

    SCM str;
    char *chars = SCM_STRING_CHARS (str);
    some_syscall (chars);
    str = SCM_BOOL_F;
    scm_remember (&str);

will ensure that the object originally pointed to by `str' is properly
protected, while

    SCM str;
    char *chars = SCM_STRING_CHARS (str);
    some_syscall (chars);
    str = SCM_BOOL_F;
    scm_remember_value (str);

might be optimized into

    SCM str;
    char *chars = SCM_STRING_CHARS (str);
    some_syscall (chars);
    scm_remember_value (SCM_BOOL_F);

which would provide no protection for the object originally pointed to
by `str'.

> but this solution does not require the compiler to actually store
> the SCM value in memory - it is also legal to keep it in a register.
> Thus, I suggest to either change the signature of scm_remember to
> only take a SCM parameter, or to add a new function for that purpose
> and deprecate scm_remember at the same time.

I'd suggest to add a new function `scm_remember_value' but to not
deprecate `scm_remember'.



reply via email to

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