Skip to content

Commit

Permalink
Deprecate env_unlock()
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed Jul 2, 2024
1 parent 369249f commit 33500f8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
25 changes: 22 additions & 3 deletions R/env.R
Original file line number Diff line number Diff line change
Expand Up @@ -554,16 +554,35 @@ env_is_locked <- function(env) {

#' Unlock an environment
#'
#' This function should only be used in development tools or
#' interactively.
#' `r lifecycle::badge("defunct")`. This function is now defunct
#' because recent versions of R no longer make it possible to
#' unlock an environment.
#'
#' @inheritParams env_lock
#' @return Whether the environment has been unlocked.
#'
#' @keywords internal
#' @export
env_unlock <- function(env) {
invisible(.Call(ffi_env_unlock, env))
msg <- "`env_unlock()` is defunct as of rlang 1.1.5"

old_pkgload_running <-
"pkgload" %in% loadedNamespaces() &&
some(sys.frames(), function(env) identical(topenv(env), ns_env("pkgload"))) &&
utils::packageVersion("pkgload") <= "1.3.4"

if (old_pkgload_running) {
ver <- utils::packageVersion("pkgload")
msg <- c(
msg,
"i" = sprintf(
"This error is likely caused by an outdated version of pkgload. You are running pkgload %s and you need at least 1.3.5",
ver
)
)
}

abort(msg)
}


Expand Down
5 changes: 3 additions & 2 deletions man/env_unlock.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions src/internal/env.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
#include <rlang.h>

#define FRAME_LOCK_MASK (1 << 14)
#define FRAME_IS_LOCKED(e) (ENVFLAGS(e) & FRAME_LOCK_MASK)
#define UNLOCK_FRAME(e) SET_ENVFLAGS(e, ENVFLAGS(e) & (~FRAME_LOCK_MASK))

// Should only be used in development tools
r_obj* ffi_env_unlock(r_obj* env) {
UNLOCK_FRAME(env);
return FRAME_IS_LOCKED(env) == 0 ? r_true : r_false;
}


void r_env_unbind_anywhere(r_obj* env, r_obj* sym) {
while (env != r_envs.empty) {
if (r_env_has(env, sym)) {
Expand Down
1 change: 0 additions & 1 deletion src/internal/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ static const R_CallMethodDef r_callables[] = {
{"ffi_env_poke", (DL_FUNC) &ffi_env_poke, 5},
{"ffi_env_poke_parent", (DL_FUNC) &ffi_env_poke_parent, 2},
{"ffi_env_unbind", (DL_FUNC) &ffi_env_unbind, 3},
{"ffi_env_unlock", (DL_FUNC) &ffi_env_unlock, 1},
{"ffi_eval_top", (DL_FUNC) &ffi_eval_top, 2},
{"ffi_exprs_interp", (DL_FUNC) &ffi_exprs_interp, 6},
{"ffi_f_lhs", (DL_FUNC) &r_f_lhs, 1},
Expand Down
8 changes: 0 additions & 8 deletions tests/testthat/test-env.R
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,6 @@ test_that("can lock environments", {
expect_true(env_lock(env))
})

test_that("can unlock environments", {
env <- env()
env_lock(env)
expect_true(env_unlock(env))
expect_false(env_is_locked(env))
expect_no_error(env_bind(env, a = 1))
})

test_that("env_print() has flexible input", {
# because it's primarily used interactively
f <- function() 1
Expand Down

0 comments on commit 33500f8

Please sign in to comment.