|
1 | 1 |
|
2 |
| -## Copyright (C) 2009 - 2019 Dirk Eddelbuettel and Romain Francois |
| 2 | +## Copyright (C) 2009 - 2020 Dirk Eddelbuettel and Romain Francois |
| 3 | +## Copyright (C) 2021 Dirk Eddelbuettel, Romain Francois and Iñaki Ucar |
3 | 4 | ##
|
4 | 5 | ## This file is part of Rcpp.
|
5 | 6 | ##
|
@@ -35,3 +36,33 @@ expect_true(xptr_release(xp), info = "check release of external pointer")
|
35 | 36 | expect_true(xptr_access_released(xp), info = "check access of released external pointer")
|
36 | 37 |
|
37 | 38 | expect_error(xptr_use_released(xp), info = "check exception on use of released external pointer")
|
| 39 | + |
| 40 | +# test finalizeOnExit default depending on RCPP_USE_FINALIZE_ON_EXIT |
| 41 | +file_path <- tempfile(fileext=".cpp") |
| 42 | +on.exit(unlink(file_path), add=TRUE) |
| 43 | +R <- shQuote(file.path(R.home(component = "bin"), "R")) |
| 44 | +cmd <- paste0(R, " -s -e 'Rcpp::sourceCpp(\"", file_path, "\"); test()'") |
| 45 | + |
| 46 | +code <- ' |
| 47 | +#include <Rcpp.h> |
| 48 | +using namespace Rcpp; |
| 49 | +
|
| 50 | +template <typename T> |
| 51 | +void custom_finalizer(T* obj) { |
| 52 | + Rcout << "custom_finalizer was called" << std::endl; |
| 53 | + delete obj; |
| 54 | +} |
| 55 | +
|
| 56 | +// [[Rcpp::export]] |
| 57 | +void test() { |
| 58 | + XPtr<int, PreserveStorage, custom_finalizer> x(new int); |
| 59 | +} |
| 60 | +' |
| 61 | + |
| 62 | +writeLines(code, file_path) |
| 63 | +expect_silent(system(cmd), info="check that finalizer is NOT called on exit") |
| 64 | + |
| 65 | +if (packageVersion("tinytest") < "1.2.0") exit_file("Skip remainder on older test platform") |
| 66 | + |
| 67 | +writeLines(c("#define RCPP_USE_FINALIZE_ON_EXIT", code), file_path) |
| 68 | +expect_stdout(system(cmd), info="check that finalizer is called on exit") |
0 commit comments