From 9bc3c0745c530606aeb9c77e9edc5f9ea40e4a7b Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Mon, 31 Jul 2023 12:41:14 -0500 Subject: [PATCH 1/2] Fix valgrind issue --- NEWS.md | 2 ++ src/coerce.c | 22 +++++++++++++++++++++- tests/testthat/_snaps/map.md | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 08b5074d..50aae7b0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # purrr (development version) +* Fixed valgrind issue. + * Deprecation infrastructure in `map_chr()` now has much less overhead leading to improved performance (#1089). diff --git a/src/coerce.c b/src/coerce.c index 2cc6a6fc..0a9f754f 100644 --- a/src/coerce.c +++ b/src/coerce.c @@ -6,11 +6,31 @@ #include "conditions.h" void cant_coerce(SEXP from, SEXP to, int i) { + + const char* to_friendly; + switch(TYPEOF(to)) { + case INTSXP: + to_friendly = "an integer"; + break; + case REALSXP: + to_friendly = "a double"; + break; + case STRSXP: + to_friendly = "a string"; + break; + case LGLSXP: + to_friendly = "a logical"; + break; + default: + to_friendly = Rf_type2char(TYPEOF(to)); + } + + Rf_errorcall( R_NilValue, "Can't coerce from %s to %s.", rlang_obj_type_friendly_full(from, false, false), - rlang_obj_type_friendly_full(to, false, false) + to_friendly ); } diff --git a/tests/testthat/_snaps/map.md b/tests/testthat/_snaps/map.md index 3fa0ac7c..7ad15343 100644 --- a/tests/testthat/_snaps/map.md +++ b/tests/testthat/_snaps/map.md @@ -29,7 +29,7 @@ Error in `map_int()`: i In index: 3. Caused by error: - ! Can't coerce from a string to an integer vector. + ! Can't coerce from a string to an integer. Code map(1:3, ~ fail_at_3(.x, stop("Doesn't work"))) Condition From a749121df47fcfd45b7add90fc159215061d368f Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 1 Aug 2023 13:47:48 -0500 Subject: [PATCH 2/2] Add case for raw vector --- src/coerce.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/coerce.c b/src/coerce.c index 0a9f754f..e3bc9071 100644 --- a/src/coerce.c +++ b/src/coerce.c @@ -21,6 +21,9 @@ void cant_coerce(SEXP from, SEXP to, int i) { case LGLSXP: to_friendly = "a logical"; break; + case RAWSXP: + to_friendly = "a raw vector"; + break; default: to_friendly = Rf_type2char(TYPEOF(to)); }