Skip to content

Commit 24efceb

Browse files
authored
Remove private environment accessors (#1721)
1 parent 18c7ef7 commit 24efceb

File tree

8 files changed

+30
-41
lines changed

8 files changed

+30
-41
lines changed

NEWS.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
* `env_browse()` and `env_is_browsed()` are now defunct as they require an API
44
that is no longer available to packages (#1727).
55

6+
* The SEXP iterator of the rlang C library (used in r-lib/memtools) is now
7+
behind a feature flag because it requires private API accessors. Compile
8+
rlang with `-DRLANG_USE_PRIVATE_ACCESSORS` to enable it.
9+
610
* `env_unlock()` is now defunct because recent versions of R no long
711
make it possible to unlock an environment (#1705). Make sure to use an
812
up-to-date version of pkgload (>= 1.4.0) following this change.
9-
13+
1014
* `is_dictionaryish()` now will return TRUE for NULL (@ilovemane, #1712).
1115

1216

R/c-lib.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ detect_rlang_lib_usage <- function(src_path) {
145145
FALSE
146146
}
147147

148+
has_private_accessors <- function() {
149+
.Call(ffi_has_private_accessors)
150+
}
151+
148152

149153
# cnd.c
150154

@@ -401,5 +405,5 @@ vec_resize <- function(x, n) {
401405
# walk.c
402406

403407
sexp_iterate <- function(x, fn) {
404-
.Call(ffi_sexp_iterate, x, fn)
408+
do.call(".Call", list(ffi_sexp_iterate, x, fn))
405409
}

R/obj.R

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ unmark_object <- function(x) {
4545
true_length <- function(x) {
4646
.Call(ffi_true_length, x)
4747
}
48-
env_frame <- function(x) {
49-
.Call(ffi_env_frame, x)
50-
}
51-
env_hash_table <- function(x) {
52-
.Call(ffi_env_hash_table, x)
53-
}
5448

5549
promise_expr <- function(name, env = caller_env()) {
5650
.Call(ffi_promise_expr, name, env)

src/internal/exported.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -476,13 +476,6 @@ r_obj* ffi_env_poke_parent(r_obj* env, r_obj* new_parent) {
476476
return env;
477477
}
478478

479-
r_obj* ffi_env_frame(r_obj* env) {
480-
return FRAME(env);
481-
}
482-
r_obj* ffi_env_hash_table(r_obj* env) {
483-
return HASHTAB(env);
484-
}
485-
486479
r_obj* ffi_env_inherits(r_obj* env, r_obj* ancestor) {
487480
return r_lgl(r_env_inherits(env, ancestor, r_envs.empty));
488481
}
@@ -1031,6 +1024,16 @@ r_obj* protect_missing(r_obj* x) {
10311024
}
10321025
}
10331026

1027+
r_obj* ffi_has_private_accessors(void) {
1028+
#ifdef RLANG_USE_PRIVATE_ACCESSORS
1029+
return r_true;
1030+
#else
1031+
return r_false;
1032+
#endif
1033+
}
1034+
1035+
#ifdef RLANG_USE_PRIVATE_ACCESSORS
1036+
10341037
// [[ register() ]]
10351038
r_obj* ffi_sexp_iterate(r_obj* x, r_obj* fn) {
10361039
struct r_dyn_array* p_out = r_new_dyn_vector(R_TYPE_list, 256);
@@ -1089,3 +1092,5 @@ r_obj* ffi_sexp_iterate(r_obj* x, r_obj* fn) {
10891092
FREE(3);
10901093
return r_dyn_unwrap(p_out);
10911094
}
1095+
1096+
#endif

src/internal/internal.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,9 @@ static const R_CallMethodDef r_callables[] = {
167167
{"ffi_env_binding_types", (DL_FUNC) &r_env_binding_types, 2},
168168
{"ffi_env_clone", (DL_FUNC) &r_env_clone, 2},
169169
{"ffi_env_coalesce", (DL_FUNC) &ffi_env_coalesce, 2},
170-
{"ffi_env_frame", (DL_FUNC) &ffi_env_frame, 1},
171170
{"ffi_env_get", (DL_FUNC) &ffi_env_get, 5},
172171
{"ffi_env_get_list", (DL_FUNC) &ffi_env_get_list, 5},
173172
{"ffi_env_has", (DL_FUNC) &ffi_env_has, 3},
174-
{"ffi_env_hash_table", (DL_FUNC) &ffi_env_hash_table, 1},
175173
{"ffi_env_inherits", (DL_FUNC) &ffi_env_inherits, 2},
176174
{"ffi_env_poke", (DL_FUNC) &ffi_env_poke, 5},
177175
{"ffi_env_poke_parent", (DL_FUNC) &ffi_env_poke_parent, 2},
@@ -189,6 +187,7 @@ static const R_CallMethodDef r_callables[] = {
189187
{"ffi_glue_is_here", (DL_FUNC) &ffi_glue_is_here, 0},
190188
{"ffi_has_dots_unnamed", (DL_FUNC) &ffi_has_dots_unnamed, 1},
191189
{"ffi_has_local_precious_list", (DL_FUNC) &ffi_has_local_precious_list, 0},
190+
{"ffi_has_private_accessors", (DL_FUNC) &ffi_has_private_accessors, 0},
192191
{"ffi_has_size_one_bool", (DL_FUNC) &ffi_has_size_one_bool, 0},
193192
{"ffi_hash", (DL_FUNC) &ffi_hash, 1},
194193
{"ffi_hash_file", (DL_FUNC) &ffi_hash_file, 1},
@@ -289,7 +288,9 @@ static const R_CallMethodDef r_callables[] = {
289288
{"ffi_replace_na", (DL_FUNC) &ffi_replace_na, 2},
290289
{"ffi_run_c_test", (DL_FUNC) &ffi_run_c_test, 1},
291290
{"ffi_set_names", (DL_FUNC) &ffi_set_names, 4},
291+
#ifdef RLANG_USE_PRIVATE_ACCESSORS
292292
{"ffi_sexp_iterate", (DL_FUNC) &ffi_sexp_iterate, 2},
293+
#endif
293294
{"ffi_squash", (DL_FUNC) &ffi_squash, 4},
294295
{"ffi_standalone_check_number_1.0.7", (DL_FUNC) &ffi_standalone_check_number, 7},
295296
{"ffi_standalone_is_bool_1.0.7", (DL_FUNC) &ffi_standalone_is_bool, 3},

src/rlang/rlang.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
#include "vec-chr.c"
3030
#include "vec-lgl.c"
3131
#include "vendor.c"
32-
#include "walk.c"
3332

33+
#ifdef RLANG_USE_PRIVATE_ACCESSORS
34+
#include "walk.c"
35+
#endif
3436

3537
// Allows long vectors to be indexed with doubles
3638
r_ssize r_arg_as_ssize(r_obj* n, const char* arg) {

tests/testthat/test-c-api.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,8 @@ test_that("can push to arrays in dynamic list-of", {
11941194
})
11951195

11961196
test_that("sexp iterator visits in full order", {
1197+
skip_if_not(has_private_accessors())
1198+
11971199
it_dirs <- function(snapshot) {
11981200
dirs <- sapply(snapshot, `[[`, "dir")
11991201
dirs <- table(dirs)

tests/testthat/test-env.R

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -405,29 +405,6 @@ test_that("env_length() gives env length", {
405405
expect_identical(env_length(env(a = "a")), 1L)
406406
})
407407

408-
test_that("env_clone() duplicates frame", {
409-
skip_silently("Would fail on non-GNU R")
410-
411-
e <- new.env(hash = FALSE)
412-
e$x <- 1
413-
c <- env_clone(e)
414-
expect_false(is_reference(env_frame(e), env_frame(c)))
415-
})
416-
417-
test_that("env_clone() duplicates hash table", {
418-
skip_silently("Would fail on non-GNU R")
419-
420-
e <- env(x = 1)
421-
c <- env_clone(e)
422-
423-
e_hash <- env_hash_table(e)
424-
c_hash <- env_hash_table(c)
425-
expect_false(is_reference(e_hash, c_hash))
426-
427-
i <- detect_index(e_hash, is_null, .p = is_false)
428-
expect_false(is_reference(e_hash[[i]], c_hash[[i]]))
429-
})
430-
431408
test_that("env_clone() increases refcounts (#621)", {
432409
e <- env(x = 1:2)
433410
env_bind_lazy(e, foo = 1)

0 commit comments

Comments
 (0)