Skip to content

Commit eed75ab

Browse files
committed
tinytest step seven: convert expose_class, function and interface
1 parent 88169f8 commit eed75ab

File tree

26 files changed

+446
-305
lines changed

26 files changed

+446
-305
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
* inst/tinytest/test_environments.R: Idem
1313
* inst/tinytest/test_exceptions.R: Idem
1414
* inst/tinytest/test_exceptions_nocall.R: Idem
15+
* inst/tinytest/test_expose_class.R: Idem
16+
* inst/tinytest/test_function.R: Idem
17+
* inst/tinytest/test_interface.R: Idem
1518

1619
2019-11-23 Dirk Eddelbuettel <edd@debian.org>
1720

File renamed without changes.
File renamed without changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
2+
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
3+
4+
#' @export
5+
test_cpp_interface <- function(x, fast = FALSE) {
6+
.Call(`_testRcppInterfaceExporter_test_cpp_interface`, x, fast)
7+
}
8+
9+
# Register entry points for exported C++ functions
10+
methods::setLoadAction(function(ns) {
11+
.Call('_testRcppInterfaceExporter_RcppExport_registerCCallable', PACKAGE = 'testRcppInterfaceExporter')
12+
})
File renamed without changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Generated by using Rcpp::compileAttributes() -> do not edit by hand
2+
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
3+
4+
#ifndef RCPP_testRcppInterfaceExporter_H_GEN_
5+
#define RCPP_testRcppInterfaceExporter_H_GEN_
6+
7+
#include "testRcppInterfaceExporter_RcppExports.h"
8+
9+
#endif // RCPP_testRcppInterfaceExporter_H_GEN_
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Generated by using Rcpp::compileAttributes() -> do not edit by hand
2+
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
3+
4+
#ifndef RCPP_testRcppInterfaceExporter_RCPPEXPORTS_H_GEN_
5+
#define RCPP_testRcppInterfaceExporter_RCPPEXPORTS_H_GEN_
6+
7+
#include <Rcpp.h>
8+
9+
namespace testRcppInterfaceExporter {
10+
11+
using namespace Rcpp;
12+
13+
namespace {
14+
void validateSignature(const char* sig) {
15+
Rcpp::Function require = Rcpp::Environment::base_env()["require"];
16+
require("testRcppInterfaceExporter", Rcpp::Named("quietly") = true);
17+
typedef int(*Ptr_validate)(const char*);
18+
static Ptr_validate p_validate = (Ptr_validate)
19+
R_GetCCallable("testRcppInterfaceExporter", "_testRcppInterfaceExporter_RcppExport_validate");
20+
if (!p_validate(sig)) {
21+
throw Rcpp::function_not_exported(
22+
"C++ function with signature '" + std::string(sig) + "' not found in testRcppInterfaceExporter");
23+
}
24+
}
25+
}
26+
27+
inline SEXP test_cpp_interface(SEXP x, bool fast = false) {
28+
typedef SEXP(*Ptr_test_cpp_interface)(SEXP,SEXP);
29+
static Ptr_test_cpp_interface p_test_cpp_interface = NULL;
30+
if (p_test_cpp_interface == NULL) {
31+
validateSignature("SEXP(*test_cpp_interface)(SEXP,bool)");
32+
p_test_cpp_interface = (Ptr_test_cpp_interface)R_GetCCallable("testRcppInterfaceExporter", "_testRcppInterfaceExporter_test_cpp_interface");
33+
}
34+
RObject rcpp_result_gen;
35+
{
36+
RNGScope RCPP_rngScope_gen;
37+
rcpp_result_gen = p_test_cpp_interface(Shield<SEXP>(Rcpp::wrap(x)), Shield<SEXP>(Rcpp::wrap(fast)));
38+
}
39+
if (rcpp_result_gen.inherits("interrupted-error"))
40+
throw Rcpp::internal::InterruptedException();
41+
if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen))
42+
throw Rcpp::LongjumpException(rcpp_result_gen);
43+
if (rcpp_result_gen.inherits("try-error"))
44+
throw Rcpp::exception(Rcpp::as<std::string>(rcpp_result_gen).c_str());
45+
return Rcpp::as<SEXP >(rcpp_result_gen);
46+
}
47+
48+
}
49+
50+
#endif // RCPP_testRcppInterfaceExporter_RCPPEXPORTS_H_GEN_
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Generated by using Rcpp::compileAttributes() -> do not edit by hand
2+
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
3+
4+
#include "../inst/include/testRcppInterfaceExporter.h"
5+
#include <Rcpp.h>
6+
#include <string>
7+
#include <set>
8+
9+
using namespace Rcpp;
10+
11+
// test_cpp_interface
12+
SEXP test_cpp_interface(SEXP x, bool fast);
13+
static SEXP _testRcppInterfaceExporter_test_cpp_interface_try(SEXP xSEXP, SEXP fastSEXP) {
14+
BEGIN_RCPP
15+
Rcpp::RObject rcpp_result_gen;
16+
Rcpp::traits::input_parameter< SEXP >::type x(xSEXP);
17+
Rcpp::traits::input_parameter< bool >::type fast(fastSEXP);
18+
rcpp_result_gen = Rcpp::wrap(test_cpp_interface(x, fast));
19+
return rcpp_result_gen;
20+
END_RCPP_RETURN_ERROR
21+
}
22+
RcppExport SEXP _testRcppInterfaceExporter_test_cpp_interface(SEXP xSEXP, SEXP fastSEXP) {
23+
SEXP rcpp_result_gen;
24+
{
25+
Rcpp::RNGScope rcpp_rngScope_gen;
26+
rcpp_result_gen = PROTECT(_testRcppInterfaceExporter_test_cpp_interface_try(xSEXP, fastSEXP));
27+
}
28+
Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
29+
if (rcpp_isInterrupt_gen) {
30+
UNPROTECT(1);
31+
Rf_onintr();
32+
}
33+
bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
34+
if (rcpp_isLongjump_gen) {
35+
Rcpp::internal::resumeJump(rcpp_result_gen);
36+
}
37+
Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
38+
if (rcpp_isError_gen) {
39+
SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
40+
UNPROTECT(1);
41+
Rf_error(CHAR(rcpp_msgSEXP_gen));
42+
}
43+
UNPROTECT(1);
44+
return rcpp_result_gen;
45+
}
46+
47+
// validate (ensure exported C++ functions exist before calling them)
48+
static int _testRcppInterfaceExporter_RcppExport_validate(const char* sig) {
49+
static std::set<std::string> signatures;
50+
if (signatures.empty()) {
51+
signatures.insert("SEXP(*test_cpp_interface)(SEXP,bool)");
52+
}
53+
return signatures.find(sig) != signatures.end();
54+
}
55+
56+
// registerCCallable (register entry points for exported C++ functions)
57+
RcppExport SEXP _testRcppInterfaceExporter_RcppExport_registerCCallable() {
58+
R_RegisterCCallable("testRcppInterfaceExporter", "_testRcppInterfaceExporter_test_cpp_interface", (DL_FUNC)_testRcppInterfaceExporter_test_cpp_interface_try);
59+
R_RegisterCCallable("testRcppInterfaceExporter", "_testRcppInterfaceExporter_RcppExport_validate", (DL_FUNC)_testRcppInterfaceExporter_RcppExport_validate);
60+
return R_NilValue;
61+
}
62+
63+
static const R_CallMethodDef CallEntries[] = {
64+
{"_testRcppInterfaceExporter_test_cpp_interface", (DL_FUNC) &_testRcppInterfaceExporter_test_cpp_interface, 2},
65+
{"_testRcppInterfaceExporter_RcppExport_registerCCallable", (DL_FUNC) &_testRcppInterfaceExporter_RcppExport_registerCCallable, 0},
66+
{NULL, NULL, 0}
67+
};
68+
69+
RcppExport void R_init_testRcppInterfaceExporter(DllInfo *dll) {
70+
R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
71+
R_useDynamicSymbols(dll, FALSE);
72+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#define RCPP_USE_UNWIND_PROTECT

0 commit comments

Comments
 (0)