Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate env_unlock() #1720

Merged
merged 4 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE)
URL: https://rlang.r-lib.org, https://github.com/r-lib/rlang
BugReports: https://github.com/r-lib/rlang/issues
Config/build/compilation-database: true
Config/testthat/edition: 3
Config/Needs/website:
dplyr,
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# rlang (development version)

* `env_unlock()` is now defunct because recent versions of R no long
make it possible to unlock an environment. Make sure to use an up-to-date
version of pkgload (>= 1.4.0) following this change.


# rlang 1.1.4

* Added missing C level `r_dyn_raw_push_back()` and `r_dyn_chr_push_back()`
Expand Down
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.4.0",
ver
)
)
}

abort(msg)
}


Expand Down
3 changes: 3 additions & 0 deletions R/rlang-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ compiled_by_gcc <- function() {
#' @rawNamespace export(ffi_standalone_is_bool_1.0.7)
#' @rawNamespace export(ffi_standalone_check_number_1.0.7)
NULL

# Enable pkgload to hotpatch `::` in detached namespaces
on_load(`::` <- base::`::`)
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
Loading