Skip to content

cpp_register(): use_package by default #230

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions R/register.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#' In order to use `cpp_register()` the `cli`, `decor`, `desc`, `glue`,
#' `tibble` and `vctrs` packages must also be installed.
#' @param path The path to the package root directory
#' @param use_package If `TRUE`, uses `.Call("yourfunc", ..., PACKAGE="yourpackage")`
#' to call C++ functions, otherwise (the default) uses ``.Call(`yourfunc`, ...)``.
#' @param quiet If `TRUE` suppresses output from this function
#' @return The paths to the generated R and C++ source files (in that order).
#' @export
Expand All @@ -31,7 +33,7 @@
#'
#' # cleanup
#' unlink(dir, recursive = TRUE)
cpp_register <- function(path = ".", quiet = FALSE) {
cpp_register <- function(path = ".", use_package = FALSE, quiet = FALSE) {
stop_unless_installed(get_cpp_register_needs())

r_path <- file.path(path, "R", "cpp11.R")
Expand All @@ -56,7 +58,7 @@ cpp_register <- function(path = ".", quiet = FALSE) {

init <- generate_init_functions(get_registered_functions(all_decorations, "cpp11::init", quiet))

r_functions <- generate_r_functions(funs, package, use_package = FALSE)
r_functions <- generate_r_functions(funs, package, use_package = use_package)

dir.create(dirname(r_path), recursive = TRUE, showWarnings = FALSE)

Expand Down Expand Up @@ -102,6 +104,8 @@ cpp_register <- function(path = ".", quiet = FALSE) {

extra_includes <- paste0(extra_includes, collapse = "\n")

forceSymbols = if (use_package) "" else "\n R_forceSymbols(dll, TRUE);"

brio::write_lines(path = cpp_path, glue::glue('
// Generated by cpp11: do not edit by hand
// clang-format off
Expand All @@ -118,8 +122,7 @@ cpp_register <- function(path = ".", quiet = FALSE) {
{init$declarations}
extern "C" attribute_visible void R_init_{package}(DllInfo* dll){{
R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
R_useDynamicSymbols(dll, FALSE);{init$calls}
R_forceSymbols(dll, TRUE);
R_useDynamicSymbols(dll, FALSE);{init$calls}{forceSymbols}
}}
',
call_entries = glue::glue_collapse(call_entries, "\n")
Expand Down
5 changes: 4 additions & 1 deletion man/cpp_register.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.