Repository navigation
Open
Description
I believe we could expand on END_CPP11 (or add a sibling).
cpp11/inst/include/cpp11/declarations.hpp
Lines 47 to 63 in 51f4cd5
| #define END_CPP11 \ | |
| } \ | |
| catch (cpp11::unwind_exception & e) { \ | |
| err = e.token; \ | |
| } \ | |
| catch (std::exception & e) { \ | |
| strncpy(buf, e.what(), sizeof(buf) - 1); \ | |
| } \ | |
| catch (...) { \ | |
| strncpy(buf, "C++ error (unknown cause)", sizeof(buf) - 1); \ | |
| } \ | |
| if (buf[0] != '\0') { \ | |
| Rf_errorcall(R_NilValue, "%s", buf); \ | |
| } else if (err != R_NilValue) { \ | |
| CPP11_UNWIND \ | |
| } \ | |
| return R_NilValue; |
so that it would take parameters, easily generated in generate_cpp_functions(), i.e. package and funs$name
Lines 165 to 185 in 51f4cd5
| generate_cpp_functions <- function(funs, package = "cpp11") { | |
| funs <- funs[c("name", "return_type", "args", "file", "line", "decoration")] | |
| funs$real_params <- vcapply(funs$args, glue_collapse_data, "{type} {name}") | |
| funs$sexp_params <- vcapply(funs$args, glue_collapse_data, "SEXP {name}") | |
| funs$calls <- mapply(wrap_call, funs$name, funs$return_type, funs$args, SIMPLIFY = TRUE) | |
| funs$package <- package | |
| out <- glue::glue_data(funs, | |
| ' | |
| // {basename(file)} | |
| {return_type} {name}({real_params}); | |
| extern "C" SEXP _{package}_{name}({sexp_params}) {{ | |
| BEGIN_CPP11 | |
| {calls} | |
| END_CPP11 | |
| }} | |
| ' | |
| ) | |
| out <- glue::glue_collapse(out, sep = "\n") | |
| unclass(out) | |
| } |
so that we could construct a call to use in Rf_errorcall() instead of using R_NilValue.
Metadata
Metadata
Assignees
Labels
No labels
Activity
krlmlr commentedon May 1, 2024
I did something similar in duckdb, it has cpp11 vendored.