Skip to content

Commit 318f6ee

Browse files
committed
Merge branch 'development' into rc
2 parents 713a906 + 24050ac commit 318f6ee

6 files changed

Lines changed: 34 additions & 17 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Title: Trust, but Verify
33
Description: Declarative template-based framework for verifying that objects
44
meet structural requirements, and auto-composing error messages when they do
55
not.
6-
Version: 0.2.16
6+
Version: 0.2.16.9000
77
Authors@R: c(
88
person("Brodie", "Gaslam", email="brodie.gaslam@yahoo.com",
99
role=c("aut", "cre")),

NEWS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 0.2.17
2+
3+
* Fix bad C API accesses uncovered by new R-devel checks.
4+
5+
## 0.2.16
6+
7+
* Fix -Wformat warnings.
8+
19
## 0.2.15
210

311
* [#109](https://github.com/brodieG/vetr/issues/109) allow for substituted

src/alike.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ Go to <https://www.r-project.org/Licenses/GPL-2> for a copy of the license.
263263
extern SEXP ALIKEC_SYM_tilde;
264264
extern SEXP ALIKEC_SYM_paren_open;
265265
extern SEXP ALIKEC_SYM_args;
266+
extern SEXP ALIKEC_SYM_function;
266267
extern SEXP ALIKEC_SYM_deparse;
267268
extern SEXP ALIKEC_SYM_nlines;
268269
extern SEXP ALIKEC_SYM_getOption;

src/fun.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,17 @@ struct ALIKEC_res ALIKEC_fun_alike_internal(
4646
if(!isFunction(target) || !isFunction(current))
4747
error("Arguments must be functions.");
4848

49-
SEXP tar_form, cur_form, args;
49+
SEXP tar_form, cur_form, args, func;
5050
SEXPTYPE tar_type = TYPEOF(target), cur_type = TYPEOF(current);
5151
struct ALIKEC_res res = ALIKEC_res_init();
5252

5353
// Translate specials and builtins to formals, if possible
5454

5555
args = PROTECT(list2(ALIKEC_SYM_args, R_NilValue));
56-
if(
57-
tar_type == SPECIALSXP || tar_type == BUILTINSXP ||
58-
cur_type == SPECIALSXP || cur_type == BUILTINSXP
59-
) {
60-
SET_TYPEOF(args, LANGSXP);
61-
}
56+
SET_TYPEOF(args, LANGSXP);
57+
func = PROTECT(list3(ALIKEC_SYM_function, R_NilValue, R_NilValue));
58+
SET_TYPEOF(func, LANGSXP);
59+
6260
if(tar_type == SPECIALSXP || tar_type == BUILTINSXP) {
6361
SETCADR(args, target);
6462
target = PROTECT(eval(args, R_BaseEnv));
@@ -69,6 +67,16 @@ struct ALIKEC_res ALIKEC_fun_alike_internal(
6967
current = PROTECT(eval(args, R_BaseEnv));
7068
} else PROTECT(R_NilValue);
7169

70+
// As of ~r86700 R became stricter about what we could call FORMALS on, so we
71+
// need to make sure that we do get actual formals and not NULL.
72+
73+
if(TYPEOF(target) != CLOSXP) {
74+
target = PROTECT(eval(func, R_BaseEnv));
75+
} else PROTECT(R_NilValue);
76+
if(TYPEOF(current) != CLOSXP) {
77+
current = PROTECT(eval(func, R_BaseEnv));
78+
} else PROTECT(R_NilValue);
79+
7280
// Cycle through all formals
7381

7482
int dots = 0, dots_last = 0, dots_reset = 0, tag_match = 1, dots_cur = 0;
@@ -156,7 +164,7 @@ struct ALIKEC_res ALIKEC_fun_alike_internal(
156164
res.dat.strings.target[2] = arg_type;
157165
}
158166
}
159-
UNPROTECT(3);
167+
UNPROTECT(6);
160168
if(!res.success) res.wrap = allocVector(VECSXP, 2);
161169
return res;
162170
}

src/init.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ SEXP ALIKEC_SYM_inherits;
107107
SEXP ALIKEC_SYM_paren_open;
108108
SEXP ALIKEC_SYM_tilde;
109109
SEXP ALIKEC_SYM_args;
110+
SEXP ALIKEC_SYM_function;
110111
SEXP ALIKEC_SYM_deparse;
111112
SEXP ALIKEC_SYM_nlines;
112113
SEXP ALIKEC_SYM_widthcutoff;
@@ -143,6 +144,7 @@ void R_init_vetr(DllInfo *info)
143144
ALIKEC_SYM_paren_open = install("(");
144145
ALIKEC_SYM_tilde = install("~");
145146
ALIKEC_SYM_args = install("args");
147+
ALIKEC_SYM_function = install("function");
146148
ALIKEC_SYM_deparse = install("deparse");
147149
ALIKEC_SYM_nlines = install("nlines");
148150
ALIKEC_SYM_widthcutoff = install("width.cutoff");

src/merge.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,17 @@ static SEXP ALIKEC_unique_msg(SEXP msgs) {
117117
R_xlen_t len = xlength(msgs);
118118
if(len < 2) return(msgs);
119119

120-
// Loop once to check for dupes
120+
// Loop once to count how many distinct values
121121

122-
int some_dup = 0;
122+
int distinct_vals = 1;
123123
for(R_xlen_t i = 1; i < len; ++i) {
124-
if(R_compute_identical(VECTOR_ELT(msgs, i - 1), VECTOR_ELT(msgs, i), 16)) {
125-
some_dup = 1;
126-
break;
124+
if(!R_compute_identical(VECTOR_ELT(msgs, i - 1), VECTOR_ELT(msgs, i), 16)) {
125+
++distinct_vals;
127126
}
128127
}
129128
SEXP res;
130-
if(some_dup) {
131-
res = PROTECT(allocVector(VECSXP, len));
129+
if(distinct_vals != len) {
130+
res = PROTECT(allocVector(VECSXP, distinct_vals));
132131
SET_VECTOR_ELT(res, 0, VECTOR_ELT(msgs, 0));
133132
R_xlen_t j = 1;
134133
for(R_xlen_t i = 1; i < len; ++i) {
@@ -138,7 +137,6 @@ static SEXP ALIKEC_unique_msg(SEXP msgs) {
138137
SET_VECTOR_ELT(res, j++, VECTOR_ELT(msgs, i));
139138
}
140139
}
141-
SETLENGTH(res, j);
142140
UNPROTECT(1);
143141
} else res = msgs;
144142
return res;

0 commit comments

Comments
 (0)