Skip to content

Commit d920b29

Browse files
committed
Fix rchk issues
1 parent 5ba3ef9 commit d920b29

File tree

4 files changed

+9
-20
lines changed

4 files changed

+9
-20
lines changed

src/map.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ SEXP map_impl(SEXP env, SEXP x_name_, SEXP f_name_, SEXP type_) {
6666
SEXP i = Rf_install("i");
6767
SEXPTYPE type = Rf_str2type(CHAR(Rf_asChar(type_)));
6868

69-
SEXP x_val = Rf_eval(x, env);
69+
SEXP x_val = PROTECT(Rf_eval(x, env));
7070
check_vector(x_val, ".x");
7171

7272
int n = Rf_length(x_val);
7373
if (n == 0) {
7474
SEXP out = PROTECT(Rf_allocVector(type, 0));
7575
copy_names(x_val, out);
76-
UNPROTECT(1);
76+
UNPROTECT(2);
7777
return out;
7878
}
7979

@@ -86,7 +86,7 @@ SEXP map_impl(SEXP env, SEXP x_name_, SEXP f_name_, SEXP type_) {
8686
SEXP out = PROTECT(call_loop(env, f_call, n, type, 1));
8787
copy_names(x_val, out);
8888

89-
UNPROTECT(3);
89+
UNPROTECT(4);
9090

9191
return out;
9292
}

src/pluck.c

+6
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ SEXP pluck_impl(SEXP x, SEXP index, SEXP missing, SEXP strict_arg) {
201201
stop_bad_type(index, "a list", NULL, "where");
202202
}
203203

204+
PROTECT_INDEX idx;
205+
PROTECT_WITH_INDEX(x, &idx);
206+
204207
int n = Rf_length(index);
205208
bool strict = Rf_asLogical(strict_arg);
206209

@@ -209,11 +212,13 @@ SEXP pluck_impl(SEXP x, SEXP index, SEXP missing, SEXP strict_arg) {
209212

210213
if (is_function(index_i)) {
211214
x = extract_fn(x, index_i);
215+
REPROTECT(x, idx);
212216
continue;
213217
}
214218
// Assume all S3 objects implement the vector interface
215219
if (OBJECT(x) && TYPEOF(x) != S4SXP) {
216220
x = extract_vector(x, index_i, i, strict);
221+
REPROTECT(x, idx);
217222
continue;
218223
}
219224

@@ -247,6 +252,7 @@ SEXP pluck_impl(SEXP x, SEXP index, SEXP missing, SEXP strict_arg) {
247252
}
248253

249254
end:
255+
UNPROTECT(1);
250256
return (Rf_length(x) == 0) ? missing : x;
251257
}
252258

src/utils.c

-13
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,6 @@ SEXP sym_protect(SEXP x) {
1111
}
1212
}
1313

14-
// The return value might be garbage-collected so should be used in
15-
// non-jumpy context
16-
const char* friendly_typeof(SEXP x) {
17-
SEXP head = Rf_lang3(Rf_install(":::"), Rf_install("purrr"), Rf_install("friendly_type_of"));
18-
SEXP call = Rf_lang2(PROTECT(head), PROTECT(sym_protect(x)));
19-
20-
PROTECT(call);
21-
SEXP type = Rf_eval(call, R_BaseEnv);
22-
UNPROTECT(2);
23-
24-
return CHAR(STRING_ELT(type, 0));
25-
}
26-
2714
bool is_vector(SEXP x) {
2815
switch (TYPEOF(x)) {
2916
case LGLSXP:

src/utils.h

-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66

77
SEXP sym_protect(SEXP x);
88

9-
// The return value might be garbage-collected so should be used in
10-
// non-jumpy context
11-
const char* friendly_typeof(SEXP x);
12-
139
bool is_vector(SEXP x);
1410

1511
SEXP lang7(SEXP s, SEXP t, SEXP u, SEXP v, SEXP w, SEXP x, SEXP y);

0 commit comments

Comments
 (0)