[R-pkg-devel] Check if any object pointing to a given address is locked

Tomas Kalibera tom@@@k@||ber@ @end|ng |rom gm@||@com
Thu Apr 24 16:38:13 CEST 2025


On 4/24/25 14:36, Tony Wilkes wrote:
> Hi everyone,
>
> I have a question.
>
> Given the address of an object ("address" in the sense given by, for example, "data.table::address()"), is it possible to check if any binding in any environment pointing to that address is locked?
> So a function similar to "bindingIsLocked()", except the function checks all bindings sharing the same address, instead of checking a binding by name in a specific environment.
>
> One use-case for this is to check if it's save to modify an object by reference.
> For example, when saying x <- base::letters, x is not save to modify by reference:
> Although the binding of x itself is not locked, the binding of base::letters is locked, and we obviously don't want to modify base::letters.

The question seems to be mixing R-level abstractions with the underlying 
C-level abstractions. To answer whether one can modify a C-level R 
objects (an SEXP) in place or not, one should think in C-level R API 
abstractions. One can modify an R object (SEXP x) in place when 
NO_REFERENCES(x) is true.

If this doesn't answer your question, please try to clarify it, explain 
what is the problem you are trying to solve.

Best
Tomas

> It should be possible, I think. R has a few pass-by-reference classes (like environments), so R should be able to check something like this. I just have no idea how exactly R checks this.
>
> Thanks in advance for any response!
>
> Kind regards,
>
> Tony
>
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel



More information about the R-package-devel mailing list