From wdunlap at tibco.com  Thu Apr 23 19:06:38 2009
From: wdunlap at tibco.com (William Dunlap)
Date: Thu, 23 Apr 2009 10:06:38 -0700
Subject: [Rd] reference counting problem in .Primitive's?
Message-ID: <77EB52C6DD32BA4D87471DCD70C8D70001130F9C@NA-PA-VBE03.na.tibco.com>

I think the following rather wierd expressions show a problem in how
some of the .Primitive functions evaluate their arguments.  I haven't
yet thought of a way that a nonabusive user might run into this problem.
In each case the first argument, x, is modified in the course of
evaluating the second argument and then modified x gets used
as the first argument:

> x<-as.integer(1:5); y <- x + { x[3]<-33L ; 1L } ; y
[1]  2  3 34  5  6
> x<-2^(0:4) ; y <- log(x, { x[3]<-64 ; 2 }) ; y
[1] 0 1 6 3 4

The reason I think it looks like a sharing problem (and not an order
of evaluation problem) is that if your modification to x causes it to
use a new block of memory then the unmodified version of x gets
used as the first argument.  E.g.,

> x<-as.integer(1:5) ; y <- x + { x[3]<-33.3; 1L} ; y
[1] 2 3 4 5 6

I haven't yet thought of a way that a nonabusive user might run
into this problem.

Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com 



[Rd] reference counting problem in .Primitive's?
William Dunlap