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

Error if get_namespace() fails #396

Merged
merged 1 commit into from
Aug 26, 2024

Conversation

DavisVaughan
Copy link
Member

@DavisVaughan DavisVaughan commented Aug 26, 2024

Closes #317

Previously, this would hang indefinitely

cpp11::cpp_function('
SEXP test() {
  auto fn = cpp11::package("foo")["bar"];
  return fn();
}
')

test()
#> Error: object 'foo' not found

Now it at least says foo is not found, the same error that any other environment lookup failure would throw

Rather than hanging indefinitely when a function is called
return safe[Rf_findVarInFrame](R_NamespaceRegistry, name_sexp);
return safe[detail::r_env_get](R_NamespaceRegistry, name_sexp);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confident about this switch:

  • r_env_get() uses Rf_findVarInFrame3(env, sym, TRUE) on older R
  • Rf_findVarInFrame() is exactly a wrapper around Rf_findVarInFrame3(env, sym, TRUE)

So r_env_get() is basically Rf_findVarInFrame() with a few extra checks - like erroring if the object is not found, as we want here.

On newer R it is using the "blessed" R_getVar() with inherits = false, which is also what we want.

@DavisVaughan DavisVaughan merged commit 580c8de into r-lib:main Aug 26, 2024
16 checks passed
@DavisVaughan DavisVaughan deleted the fix/package-error branch August 26, 2024 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

package("<pkg>") error if package namespace not found
1 participant