Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

py_to_r does not unwrap external pointer #1511

Closed
llaniewski opened this issue Dec 11, 2023 · 2 comments · Fixed by #1519
Closed

py_to_r does not unwrap external pointer #1511

llaniewski opened this issue Dec 11, 2023 · 2 comments · Fixed by #1519
Labels

Comments

@llaniewski
Copy link
Contributor

Currently the py_to_r function does not unwrap an external pointer from a capsule. Namely py_to_r(r_to_py(x)) is not x if x is a R external pointer.

Code to reproduce:

library(reticulate)
library(Rcpp)

cppFunction("
SEXP fun() {
  static int k = 17;
  Rcpp::XPtr< int > ret(&k);
  return ret;
} 
")

x = fun()

identical( py_to_r(r_to_py(x)), x )

I'm open to writing a pull request with the correct the behaviour of py_to_r() function in src/python.cpp.

@t-kalinowski
Copy link
Member

Hello, thanks for reporting! I agree this should work. A PR would be most welcome!

(If I recall correctly, this does touch a somewhat gnarly part of the codebase, not a fix I'd expect from a first-time contributor :).

We'll certainly want to fix before the next release.

@llaniewski
Copy link
Contributor Author

llaniewski commented Jan 9, 2024

@t-kalinowski I solved the immediate problem in my code using reticulate:::py_capsule and did not have time to address this more general issue in reticulate itself. But now I had finally a minute and made the necessary changes in a PR (#1519). Please write if you would want me to add some tests to that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants