[R] `UNPROTECT' and `return'
ripley@stats.ox.ac.uk
ripley at stats.ox.ac.uk
Wed Feb 12 17:26:10 CET 2003
This _is_ covered in `Writing R Extensions'. What is unsafe is to allow a
gc to occur.
On Wed, 12 Feb 2003, Timur Elzhov wrote:
> In all R functions written in C one must unprotect
> result before returning them:
>
> {
> ...
> UNPROTECT(1) /* unprotecting `ans' */
>
> return ans;
> }
>
> Why does one shure that memory occupied by `ans'
> won't be used by R immediately after unprotecting?
>
> Ok, is the next construction also absolutely safe?
> {
> ...
> UNPROTECT(1) /* unprotecting `ans' */
>
> PROTECT( val = ans )
> ...
> }
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list