FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Error if `get_namespace()` fails by DavisVaughan · Pull Request #396 · r-lib/cpp11 · GitHub

/ cpp11 Public

Error if get_namespace() fails - #396

Merged
DavisVaughan merged 1 commit into
r-lib:mainfrom
DavisVaughan:fix/package-error
Aug 26, 2024
Merged

DavisVaughan merged 1 commit into
r-lib:mainfrom
DavisVaughan:fix/package-error

Conversation

DavisVaughan commented Aug 26, 2024 •
edited
Loading

Copy link
Copy Markdown
Member

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
}
sexp name_sexp = safe[Rf_install](name);
return safe[Rf_findVarInFrame](R_NamespaceRegistry, name_sexp);
return safe[detail::r_env_get](R_NamespaceRegistry, name_sexp);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 merged commit 580c8de into r-lib:main Aug 26, 2024
DavisVaughan deleted the fix/package-error branch August 26, 2024 18:53
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL