Skip to content

Commit 955733f

Browse files
committed
Restore R_Srcref on exit to avoid changing the DAP's top frame
1 parent 5391c47 commit 955733f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

crates/ark/src/interface.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1407,20 +1407,25 @@ impl RMain {
14071407

14081408
// The global source reference is stored in this global variable by
14091409
// the R REPL before evaluation. We do the same here.
1410+
let old_srcref = libr::Rf_protect(libr::get(libr::R_Srcref));
14101411
libr::set(libr::R_Srcref, srcref);
14111412

14121413
// Evaluate the expression. Beware: this may throw an R longjump.
14131414
let value = libr::Rf_eval(expr, frame);
14141415
libr::Rf_protect(value);
14151416

1417+
// Restore `R_Srcref`, necessary at least to avoid messing with
1418+
// DAP's last frame info
1419+
libr::set(libr::R_Srcref, old_srcref);
1420+
14161421
// Store in the base environment for robust access from (almost) any
14171422
// evaluation environment. We only require the presence of `::` so
14181423
// we can reach into base. Note that unlike regular environments
14191424
// which are stored in pairlists or hash tables, the base environment
14201425
// is stored in the `value` field of symbols, i.e. their "CDR".
14211426
libr::SETCDR(r_symbol!(".ark_last_value"), value);
14221427

1423-
libr::Rf_unprotect(2);
1428+
libr::Rf_unprotect(3);
14241429
value
14251430
};
14261431

0 commit comments

Comments
 (0)