Unprotects the Robj if the reference count hits zero and unprotect is true.
Needed to change the reference count.
For convenience, returns the underlying Robj when you want to pass the data back to R.
Wrapper around the data that holds the reference count
Enables reference counting of objects allocated by R. It takes care of protecting and unprotecting objects from the R garbage collector.
R objects allocated inside R and passed to D are automatically protected. Attempting to protect/unprotect them will result in an error. R objects allocated by D have to be protected from the garbage collector while they are active, and unprotected when you are done with them.
This is an implementation of the reference counting scheme in Adam Ruppe's D Cookbook.