Skip to content

Commit

Permalink
Error if get_namespace() fails (#396)
Browse files Browse the repository at this point in the history
Rather than hanging indefinitely when a function is called
  • Loading branch information
DavisVaughan authored Aug 26, 2024
1 parent 61c78b4 commit 580c8de
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS.md
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
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
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);
}

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

0 comments on commit 580c8de

Please sign in to comment.