Skip to content

Commit 7f42857

Browse files
author
luke
committed
Mark values returned by active binding functions as not mutable to
prevent unintended mutation in complex assignments. git-svn-id: https://svn.r-project.org/R/trunk@89121 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent b9b8f10 commit 7f42857

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

doc/NEWS.Rd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@
423423
\item \code{model.frame(~1, list(), na.action=na.pass)} and similar
424424
\dQuote{border-line} uses no longer produce invalid data frames,
425425
fixing \PR{18977}, reported with patch by \I{Mikael Jagan}.
426+
427+
\item Values returned by active binding functions are now marked as
428+
not mutable to prevent unintended mutation in complex assignment
429+
operations.
426430
}
427431
}
428432
}

src/main/envir.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ static SEXP getActiveValue(SEXP fun)
167167
PROTECT(expr);
168168
expr = eval(expr, R_GlobalEnv);
169169
UNPROTECT(1);
170+
/* mark unmutable to prevent mutations in complex assignments */
171+
MARK_NOT_MUTABLE(expr);
170172
return expr;
171173
}
172174

tests/reg-tests-1e.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2400,6 +2400,13 @@ stopifnot(chk0(structure(.Date (numeric()), foobar = list(Dt = "A"))),
24002400
chk0(structure(.POSIXct(numeric()), foobar = list(ct = "C"))))
24012401
## in R <= 4.5.2, give.attr=FALSE was not obeyed for 0-length "Date" / "POSIXt"
24022402

2403+
## guard against mutation through active bindings
2404+
y <- 1 + 0
2405+
if (exists("x")) rm(x)
2406+
makeActiveBinding("x", function(v) y, .GlobalEnv)
2407+
x[1] <- 2
2408+
stopifnot(y == 1)
2409+
rm(x)
24032410

24042411

24052412
## keep at end

0 commit comments

Comments
 (0)