[Rd] classed

Saikat DebRoy saikat@stat.wisc.edu
15 Sep 2000 14:09:46 -0500


I decided to experiment with this a little. I use a little C function
called printAddress that prints the address of an R object to standard
error.

> x <- 1
> .Call("printAddress", x)
0x891fedc
NULL
> x <- classd(x, "a")
> .Call("printAddress", x)
0x891fd2c
NULL

So the address has changed. Now we can go inside a debugger and see if
do_classgets has anything to do with it.

...

> x <- 1
> .Call("printAddress", x)
0x891fc78
NULL
> x <- classd(x, "a")
# now go to debugger
Breakpoint 1, do_classgets (call=0x89221f0, op=0x81d6720, args=0x8922164, 
    env=0x8922298) at ../../../r-devel/src/main/attrib.c:315
(gdb) p args->u.listsxp.carval
$7 = (struct SEXPREC *) 0x8921aa8
(gdb) n
(gdb) n
(gdb) n
(gdb) p args->u.listsxp.carval
$9 = (struct SEXPREC *) 0x8921aa8
(gdb) n
Rf_eval (e=0x89221f0, rho=0x8922298) at ../../../r-devel/src/main/eval.c:335

So do_classgets does not change the 
(gdb) c
Continuing.
# now we are back to R
> .Call("printAddress", x)
0x89219f4
NULL

The interesting thing is that the object address changed twice. That
is, x is getting copied twice - once after classd is called but before
setting the class and another time when it returns from classd. I was
expecting the second change but not the first.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._