Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix valgrind issue #1094

Merged
merged 2 commits into from
Aug 1, 2023
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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).

Expand Down
25 changes: 24 additions & 1 deletion src/coerce.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,34 @@
#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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to keep things in sync, it looks like set_vector_value() does call cant_coerce() for RAWSXP too (but not for VECSXP, so no need to add that case)

case RAWSXP:
to_friendly = "a raw vector";
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
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/map.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading