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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cpp  (1) .hpp  (1) .md  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
3 changes: 3 additions & 0 deletions NEWS.md
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# cpp11 (development version)

* `cpp11::package` now errors if given a package name that hasn't been loaded
yet. Previously it would cause R to hang indefinitely (#317).

* `cpp11::function` now protects its underlying function, for maximum safety
(#294).

Expand Down
4 changes: 4 additions & 0 deletions cpp11test/src/test-function.cpp
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ context("function-C++") {

close(con);
}

test_that("unknown packages cause an error (#317)") {
expect_error_as(cpp11::package("definitely_not_a_package"), cpp11::unwind_exception);
}
}
2 changes: 1 addition & 1 deletion inst/include/cpp11/function.hpp
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class package {
return R_BaseEnv;
}
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.

}

// Either base env or in namespace registry, so no protection needed
Expand Down

Back | FazBrowse Home | New Git URL