Skip to content

Commit aa8ec75

Browse files
committed
Rf_findVar -> R_getVar and related
1 parent 36a4a98 commit aa8ec75

5 files changed

Lines changed: 40 additions & 4 deletions

File tree

src/cleancall.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ void cleancall_SetExternalPtrAddrFn(SEXP s, DL_FUNC p) {
3535
// Initialised at load time with the `.Call` primitive
3636
SEXP cleancall_fns_dot_call = NULL;
3737

38+
#if (defined(R_VERSION) && R_VERSION < R_Version(4, 5, 0))
39+
#define R_getVar(x,y,z) Rf_findVar(x,y)
40+
#endif
41+
3842
void cleancall_init(void) {
39-
cleancall_fns_dot_call = Rf_findVar(Rf_install(".Call"), R_BaseEnv);
43+
cleancall_fns_dot_call = R_getVar(Rf_install(".Call"), R_BaseEnv, TRUE);
4044
}
4145

4246
struct eval_args {

src/init.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ static const R_CallMethodDef callMethods[] = {
100100

101101
#define RCC(fun) R_RegisterCCallable("cli", # fun, (DL_FUNC) fun);
102102

103+
#if (defined(R_VERSION) && R_VERSION < R_Version(4, 5, 0))
104+
#define R_getVar(x,y,z) Rf_findVar(x,y)
105+
#endif
106+
103107
r_export
104108
void R_init_cli(DllInfo *dll) {
105109
#if R_VERSION >= R_Version(3, 5, 0)
@@ -110,7 +114,7 @@ void R_init_cli(DllInfo *dll) {
110114
R_useDynamicSymbols(dll, FALSE);
111115
R_forceSymbols(dll, TRUE);
112116

113-
cleancall_fns_dot_call = Rf_findVar(Rf_install(".Call"), R_BaseEnv);
117+
cleancall_fns_dot_call = R_getVar(Rf_install(".Call"), R_BaseEnv, TRUE);
114118

115119
RCC(cli_progress_add);
116120
RCC(cli_progress_bar);

src/progress.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ SEXP clic_get_time(void) {
9696
return Rf_ScalarReal(ts);
9797
}
9898

99+
#if (defined(R_VERSION) && R_VERSION < R_Version(4, 5, 0))
99100
SEXP clic__find_var(SEXP rho, SEXP symbol) {
100101
SEXP ret = Rf_findVarInFrame(rho, symbol);
101102
if (ret == R_UnboundValue) {
@@ -111,6 +112,25 @@ SEXP clic__find_var(SEXP rho, SEXP symbol) {
111112
return ret;
112113
}
113114
}
115+
#else
116+
SEXP clic__find_var(SEXP rho, SEXP symbol) {
117+
Rboolean ex = R_existsVarInFrame(rho, symbol);
118+
if (!ex) {
119+
error("Cannot find variable `%s`.", CHAR(PRINTNAME(symbol)));
120+
}
121+
122+
SEXP ret = R_getVar(symbol, rho, TRUE);
123+
if (TYPEOF(ret) == PROMSXP) {
124+
PROTECT(ret);
125+
SEXP ret2 = Rf_eval(ret, rho);
126+
UNPROTECT(1);
127+
return(ret2);
128+
129+
} else {
130+
return ret;
131+
}
132+
}
133+
#endif
114134

115135
static int cli__counter = 0;
116136

tests/testthat/progresstest/src/cleancall.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ void cleancall_SetExternalPtrAddrFn(SEXP s, DL_FUNC p) {
3535
// Initialised at load time with the `.Call` primitive
3636
SEXP cleancall_fns_dot_call = NULL;
3737

38+
#if (defined(R_VERSION) && R_VERSION < R_Version(4, 5, 0))
39+
#define R_getVar(x,y,z) Rf_findVar(x,y)
40+
#endif
41+
3842
void cleancall_init() {
39-
cleancall_fns_dot_call = Rf_findVar(Rf_install(".Call"), R_BaseEnv);
43+
cleancall_fns_dot_call = R_getVar(Rf_install(".Call"), R_BaseEnv, TRUE);
4044
}
4145

4246
struct eval_args {

tests/testthat/progresstest/src/test.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,13 @@ static const R_CallMethodDef CallEntries[] = {
9797
{ NULL, NULL, 0 }
9898
};
9999

100+
#if (defined(R_VERSION) && R_VERSION < R_Version(4, 5, 0))
101+
#define R_getVar(x,y,z) Rf_findVar(x,y)
102+
#endif
103+
100104
void R_init_progresstest(DllInfo *dll) {
101105
R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
102106
R_useDynamicSymbols(dll, FALSE);
103107
R_forceSymbols(dll, TRUE);
104-
cleancall_fns_dot_call = Rf_findVar(Rf_install(".Call"), R_BaseEnv);
108+
cleancall_fns_dot_call = R_getVar(Rf_install(".Call"), R_BaseEnv, TRUE);
105109
}

0 commit comments

Comments
 (0)