Skip to content
Merged
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
9 changes: 5 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# cpp11 (development version)

* Fix memory leak when move constructing vectors (#173)
* Fix handling of spaces in Makevars include filenames (@klmr, #160)
* New `cpp11::na()` function to return the NA sentinals for R objects(@sbearrows, #179)
* Incorrectly formatted cpp11 decorators now output a more informative error message (@sbearrows, #127)
* Generated registration code now uses C collation to avoid spurious diffs from `tools::package_native_routine_registration_skeleton()` (@sbearrows, #171)
* Memory lo longer leaks when move constructing vectors (#173)
* Makevars which include filenames now handle spaces in paths properly (@klmr, #160)

# cpp11 0.2.7

* Outputting more informative error message when cpp11 decorators are incorrectly formatted (@sbearrows, #127)
* Fix spurious diffs from `tools::package_native_routine_registration_skeleton()` by temporarily using C collation (@sbearrows, #171)
* Fix a transient memory leak for functions that return values from `cpp11::unwind_protect()` and `cpp11::safe` (#154)
* `cpp_source()` now gets an argument `dir` to allow customized temporary directory to store generated source files.
It makes it easier to debug C++ source files in non-package project via source mapping. (@renkun-ken, #156)
Expand Down
16 changes: 8 additions & 8 deletions cpp11test/src/cpp11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,16 @@ extern SEXP _cpp11test_rcpp_sum_dbl_foreach_(SEXP);
extern SEXP _cpp11test_rcpp_sum_int_for_(SEXP);
extern SEXP _cpp11test_remove_altrep(SEXP);
extern SEXP _cpp11test_row_sums(SEXP);
extern SEXP _cpp11test_sum_dbl_accumulate_(SEXP);
extern SEXP _cpp11test_sum_dbl_accumulate2_(SEXP);
extern SEXP _cpp11test_sum_dbl_for_(SEXP);
extern SEXP _cpp11test_sum_dbl_accumulate_(SEXP);
extern SEXP _cpp11test_sum_dbl_for2_(SEXP);
extern SEXP _cpp11test_sum_dbl_for3_(SEXP);
extern SEXP _cpp11test_sum_dbl_foreach_(SEXP);
extern SEXP _cpp11test_sum_dbl_for_(SEXP);
extern SEXP _cpp11test_sum_dbl_foreach2_(SEXP);
extern SEXP _cpp11test_sum_dbl_foreach_(SEXP);
extern SEXP _cpp11test_sum_int_accumulate_(SEXP);
extern SEXP _cpp11test_sum_int_for_(SEXP);
extern SEXP _cpp11test_sum_int_for2_(SEXP);
extern SEXP _cpp11test_sum_int_for_(SEXP);
extern SEXP _cpp11test_sum_int_foreach_(SEXP);
extern SEXP _cpp11test_upper_bound(SEXP, SEXP);
extern SEXP run_testthat_tests(SEXP);
Expand Down Expand Up @@ -398,16 +398,16 @@ static const R_CallMethodDef CallEntries[] = {
{"_cpp11test_rcpp_sum_int_for_", (DL_FUNC) &_cpp11test_rcpp_sum_int_for_, 1},
{"_cpp11test_remove_altrep", (DL_FUNC) &_cpp11test_remove_altrep, 1},
{"_cpp11test_row_sums", (DL_FUNC) &_cpp11test_row_sums, 1},
{"_cpp11test_sum_dbl_accumulate_", (DL_FUNC) &_cpp11test_sum_dbl_accumulate_, 1},
{"_cpp11test_sum_dbl_accumulate2_", (DL_FUNC) &_cpp11test_sum_dbl_accumulate2_, 1},
{"_cpp11test_sum_dbl_for_", (DL_FUNC) &_cpp11test_sum_dbl_for_, 1},
{"_cpp11test_sum_dbl_accumulate_", (DL_FUNC) &_cpp11test_sum_dbl_accumulate_, 1},
{"_cpp11test_sum_dbl_for2_", (DL_FUNC) &_cpp11test_sum_dbl_for2_, 1},
{"_cpp11test_sum_dbl_for3_", (DL_FUNC) &_cpp11test_sum_dbl_for3_, 1},
{"_cpp11test_sum_dbl_foreach_", (DL_FUNC) &_cpp11test_sum_dbl_foreach_, 1},
{"_cpp11test_sum_dbl_for_", (DL_FUNC) &_cpp11test_sum_dbl_for_, 1},
{"_cpp11test_sum_dbl_foreach2_", (DL_FUNC) &_cpp11test_sum_dbl_foreach2_, 1},
{"_cpp11test_sum_dbl_foreach_", (DL_FUNC) &_cpp11test_sum_dbl_foreach_, 1},
{"_cpp11test_sum_int_accumulate_", (DL_FUNC) &_cpp11test_sum_int_accumulate_, 1},
{"_cpp11test_sum_int_for_", (DL_FUNC) &_cpp11test_sum_int_for_, 1},
{"_cpp11test_sum_int_for2_", (DL_FUNC) &_cpp11test_sum_int_for2_, 1},
{"_cpp11test_sum_int_for_", (DL_FUNC) &_cpp11test_sum_int_for_, 1},
{"_cpp11test_sum_int_foreach_", (DL_FUNC) &_cpp11test_sum_int_foreach_, 1},
{"_cpp11test_upper_bound", (DL_FUNC) &_cpp11test_upper_bound, 2},
{"run_testthat_tests", (DL_FUNC) &run_testthat_tests, 1},
Expand Down
4 changes: 0 additions & 4 deletions cpp11test/src/test-list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
#include "cpp11/raws.hpp"
#include "cpp11/strings.hpp"

namespace cpp11 {
std::ostream& operator<<(std::ostream& os, r_bool b) { return os << int(b); }
} // namespace cpp11

context("list-C++") {
test_that("list.push_back()") {
cpp11::writable::list x;
Expand Down
12 changes: 12 additions & 0 deletions cpp11test/src/test-nas.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <testthat.h>
#include "cpp11/doubles.hpp"
#include "cpp11/integers.hpp"
#include "cpp11/r_bool.hpp"
#include "cpp11/r_string.hpp"

context("nas-C++") {
test_that("na integer") { expect_true(cpp11::na<int>() == NA_INTEGER); }
test_that("na double") { expect_true(ISNA(cpp11::na<double>())); }
test_that("na bool") { expect_true(cpp11::na<cpp11::r_bool>() == NA_LOGICAL); }
test_that("na string") { expect_true(cpp11::na<cpp11::r_string>() == NA_STRING); }
}
9 changes: 9 additions & 0 deletions inst/include/cpp11/R.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,13 @@ namespace literals {
constexpr R_xlen_t operator"" _xl(unsigned long long int value) { return value; }

} // namespace literals

template <typename T>
inline T na();

template <typename T>
inline bool is_na(const T& value) {
return value == na<T>();
}

} // namespace cpp11
11 changes: 10 additions & 1 deletion inst/include/cpp11/doubles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "cpp11/protect.hpp" // for SEXP, SEXPREC, REAL_ELT, R_Preserve...
#include "cpp11/r_vector.hpp" // for vector, vector<>::proxy, vector<>::...
#include "cpp11/sexp.hpp" // for sexp

// Specializations for doubles

namespace cpp11 {
Expand Down Expand Up @@ -130,5 +131,13 @@ typedef r_vector<double> doubles;

} // namespace writable

inline bool is_na(double x) { return ISNA(x); }
template <>
inline double na() {
return NA_REAL;
}

template <>
inline bool is_na(const double& x) {
return ISNA(x);
}
} // namespace cpp11
6 changes: 5 additions & 1 deletion inst/include/cpp11/integers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,9 @@ typedef r_vector<int> integers;

} // namespace writable

inline bool is_na(int x) { return x == NA_INTEGER; }
template <>
inline int na() {
return NA_INTEGER;
}

} // namespace cpp11
16 changes: 13 additions & 3 deletions inst/include/cpp11/r_bool.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#pragma once

#include <limits> // for numeric_limits
#include <limits> // for numeric_limits
#include <ostream>
#include <type_traits> // for is_convertible, enable_if

#include "R_ext/Boolean.h" // for Rboolean
#include "cpp11/R.hpp" // for SEXP, SEXPREC, ...
#include "cpp11/as.hpp" // for as_sexp
#include "cpp11/protect.hpp" // for unwind_protect, preserved
#include "cpp11/sexp.hpp" // for sexp
#include "cpp11/r_vector.hpp"
#include "cpp11/sexp.hpp" // for sexp

namespace cpp11 {

Expand Down Expand Up @@ -49,7 +51,10 @@ class r_bool {
int value_ = na;
};

inline bool is_na(r_bool x) { return x == r_bool(); }
inline std::ostream& operator<<(std::ostream& os, r_bool const& value) {
os << ((value == TRUE) ? "TRUE" : "FALSE");
return os;
}

template <typename T, typename R = void>
using enable_if_r_bool = enable_if_t<std::is_same<T, r_bool>::value, R>;
Expand All @@ -61,4 +66,9 @@ enable_if_r_bool<T, SEXP> as_sexp(T from) {
return res;
}

template <>
inline r_bool na() {
return NA_LOGICAL;
}

} // namespace cpp11
9 changes: 7 additions & 2 deletions inst/include/cpp11/r_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "cpp11/as.hpp" // for as_sexp
#include "cpp11/protect.hpp" // for unwind_protect, protect, protect::function
#include "cpp11/sexp.hpp" // for sexp

namespace cpp11 {

class r_string {
Expand Down Expand Up @@ -67,8 +68,6 @@ inline SEXP as_sexp(std::initializer_list<r_string> il) {
return data;
}

inline bool is_na(const r_string& x) { return x == NA_STRING; }

template <typename T, typename R = void>
using enable_if_r_string = enable_if_t<std::is_same<T, cpp11::r_string>::value, R>;

Expand All @@ -88,4 +87,10 @@ enable_if_r_string<T, SEXP> as_sexp(T from) {

return res;
}

template <>
inline r_string na() {
return NA_STRING;
}

} // namespace cpp11