Skip to content

Commit 28edbae

Browse files
author
maechler
committed
browser() nesting level from if() etc: fixing PR#18885 differently than PR#15770
git-svn-id: https://svn.r-project.org/R/trunk@88280 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 4d56121 commit 28edbae

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

doc/NEWS.Rd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@
113113

114114
\item Subsetting \code{"table"} objects keeps S3 classes more
115115
consistently, fixing \PR{18845}.
116+
117+
\item When \code{browser()} is active or when otherwise debugging, \R code
118+
such as \code{if(TRUE)} now longer triggers a new browser level, fixing
119+
\PR{18885} (differently than the fix for \PR{15770}), with thanks to
120+
\I{Ivan Krylov}.
116121
}
117122
}
118123
}

src/main/main.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,6 @@ typedef struct {
198198
attribute_hidden int
199199
Rf_ReplIteration(SEXP rho, int savestack, int browselevel, R_ReplState *state)
200200
{
201-
int c, browsevalue;
202-
SEXP value, thisExpr;
203-
bool wasDisplayed = FALSE;
204-
205201
/* clear warnings that might have accumulated during a jump to top level */
206202
if (R_CollectWarnings)
207203
PrintWarnings();
@@ -221,6 +217,7 @@ Rf_ReplIteration(SEXP rho, int savestack, int browselevel, R_ReplState *state)
221217
return(0);
222218
}
223219
#endif /* SHELL_ESCAPE */
220+
int c;
224221
while((c = *state->bufp)) {
225222
state->bufp++;
226223
R_IoBufferPutc(c, &R_ConsoleIob);
@@ -243,9 +240,10 @@ Rf_ReplIteration(SEXP rho, int savestack, int browselevel, R_ReplState *state)
243240
return 1;
244241

245242
case PARSE_OK:
246-
243+
{
247244
R_IoBufferReadReset(&R_ConsoleIob);
248245
R_CurrentExpr = R_Parse1Buffer(&R_ConsoleIob, 1, &state->status);
246+
int browsevalue = 0; /* -Wmaybe-uninit.. */
249247
if (browselevel) {
250248
browsevalue = ParseBrowser(R_CurrentExpr, rho);
251249
if(browsevalue == 1) return -1;
@@ -254,31 +252,34 @@ Rf_ReplIteration(SEXP rho, int savestack, int browselevel, R_ReplState *state)
254252
return 0;
255253
}
256254
/* PR#15770 We don't want to step into expressions entered at the debug prompt.
257-
The 'S' will be changed back to 's' after the next eval. */
258-
if (R_BrowserLastCommand == 's') R_BrowserLastCommand = 'S';
255+
+ PR#18885 Disable debugging of this environment for the duration of the call. */
256+
browsevalue = -RDEBUG(rho);
257+
SET_RDEBUG(rho, 0);
259258
}
260259
R_Visible = FALSE;
261260
R_EvalDepth = 0;
262261
resetTimeLimits();
263-
PROTECT(thisExpr = R_CurrentExpr);
262+
SEXP thisExpr = PROTECT(R_CurrentExpr);
264263
R_Busy(1);
265-
PROTECT(value = eval(thisExpr, rho));
264+
SEXP value = PROTECT(eval(thisExpr, rho));
266265
SET_SYMVALUE(R_LastvalueSymbol, value);
267266
if (NO_REFERENCES(value))
268267
INCREMENT_REFCNT(value);
269-
wasDisplayed = R_Visible;
268+
bool wasDisplayed = R_Visible;
270269
if (R_Visible)
271270
PrintValueEnv(value, rho);
272271
if (R_CollectWarnings)
273272
PrintWarnings();
274273
Rf_callToplevelHandlers(thisExpr, value, TRUE, wasDisplayed);
275274
R_CurrentExpr = value; /* Necessary? Doubt it. */
276275
UNPROTECT(2); /* thisExpr, value */
277-
if (R_BrowserLastCommand == 'S') R_BrowserLastCommand = 's';
276+
if (browselevel && browsevalue < 0)
277+
/* Done evaluating REPL expression, continue stepping. */
278+
SET_RDEBUG(rho, 1);
278279
R_IoBufferWriteReset(&R_ConsoleIob);
279280
state->prompt_type = 1;
280281
return(1);
281-
282+
}
282283
case PARSE_ERROR:
283284

284285
state->prompt_type = 1;
@@ -368,7 +369,6 @@ int R_ReplDLLdo1(void)
368369
int c;
369370
ParseStatus status;
370371
SEXP rho = R_GlobalEnv, lastExpr;
371-
bool wasDisplayed = FALSE;
372372

373373
if(!*DLLbufp) {
374374
R_Busy(0);
@@ -390,6 +390,7 @@ int R_ReplDLLdo1(void)
390390
prompt_type = 1;
391391
break;
392392
case PARSE_OK:
393+
{
393394
R_IoBufferReadReset(&R_ConsoleIob);
394395
R_CurrentExpr = R_Parse1Buffer(&R_ConsoleIob, 1, &status);
395396
R_Visible = FALSE;
@@ -400,7 +401,7 @@ int R_ReplDLLdo1(void)
400401
lastExpr = R_CurrentExpr;
401402
R_CurrentExpr = eval(R_CurrentExpr, rho);
402403
SET_SYMVALUE(R_LastvalueSymbol, R_CurrentExpr);
403-
wasDisplayed = R_Visible;
404+
bool wasDisplayed = R_Visible;
404405
if (R_Visible)
405406
PrintValueEnv(R_CurrentExpr, rho);
406407
if (R_CollectWarnings)
@@ -411,6 +412,7 @@ int R_ReplDLLdo1(void)
411412
R_Busy(0);
412413
prompt_type = 1;
413414
break;
415+
}
414416
case PARSE_ERROR:
415417
parseError(R_NilValue, 0);
416418
R_IoBufferWriteReset(&R_ConsoleIob);
@@ -812,7 +814,7 @@ static void invalid_parameter_handler_watson(
812814
unsigned int line,
813815
uintptr_t reserved)
814816
{
815-
_invoke_watson(expression, function, file, line, reserved);
817+
_invoke_watson(expression, function, file, line, reserved);
816818
}
817819
#endif
818820

0 commit comments

Comments
 (0)