Commit 4e02f398 authored by Radford Neal's avatar Radford Neal

remove unneded protects in applyClosure

parent c77da5d2
......@@ -1118,29 +1118,19 @@ SEXP attribute_hidden applyClosure_v(SEXP call, SEXP op, SEXP arglist, SEXP rho,
SEXP formals, actuals, savedrho, savedsrcref;
volatile SEXP body, newrho;
SEXP f, a, res;
SEXP f, a;
RCNTXT cntxt;
PROTECT2(op,arglist);
formals = FORMALS(op);
body = BODY(op);
savedrho = CLOENV(op);
if (0 && R_jit_enabled > 0 && TYPEOF(body) != BCODESXP) {
int old_enabled = R_jit_enabled;
SEXP newop;
R_jit_enabled = 0;
newop = R_cmpfun(op);
body = BODY(newop);
SET_BODY(op, body);
R_jit_enabled = old_enabled;
}
/* Set up a context with the call in it for use if an error occurs below
in matchArgs or from running out of memory (eg, in NewEnvironment). */
in matchArgs or from running out of memory (eg, in NewEnvironment).
Note that this also protects call, savedrho, rho, arglist, and op. */
begincontext(&cntxt, CTXT_RETURN, call, savedrho, rho, arglist, op);
savedsrcref = R_Srcref; /* saved in context for longjmp, and protection */
/* Build a list which matches the actual (unevaluated) arguments
......@@ -1240,23 +1230,27 @@ SEXP attribute_hidden applyClosure_v(SEXP call, SEXP op, SEXP arglist, SEXP rho,
UNPROTECT(1);
}
/* Set a longjmp target which will catch any explicit returns
from the function body. */
/* Set a longjmp target which will catch any explicit returns from
the function body. */
SEXP res;
if ((SETJMP(cntxt.cjmpbuf))) {
if (R_ReturnedValue == R_RestartToken) {
cntxt.callflag = CTXT_RETURN; /* turn restart off */
R_ReturnedValue = R_NilValue; /* remove restart token */
PROTECT(res = evalv (body, newrho, vrnt));
res = evalv (body, newrho, vrnt);
}
else {
PROTECT(res = R_ReturnedValue);
res = R_ReturnedValue;
}
}
else {
PROTECT(res = evalv (body, newrho, vrnt));
res = evalv (body, newrho, vrnt);
}
PROTECT(res);
R_variant_result &= ~VARIANT_RTN_FLAG;
R_Srcref = savedsrcref;
......@@ -1270,7 +1264,7 @@ SEXP attribute_hidden applyClosure_v(SEXP call, SEXP op, SEXP arglist, SEXP rho,
printcall(call,rho);
}
UNPROTECT(3); /* op, arglist, res */
UNPROTECT(1); /* res */
return res;
}
......@@ -1288,23 +1282,11 @@ static SEXP R_execClosure(SEXP call, SEXP op, SEXP arglist, SEXP rho,
SEXP newrho)
{
volatile SEXP body;
SEXP res, savedsrcref;
SEXP savedsrcref;
RCNTXT cntxt;
PROTECT2(op,arglist);
body = BODY(op);
if (0 && R_jit_enabled > 0 && TYPEOF(body) != BCODESXP) {
int old_enabled = R_jit_enabled;
SEXP newop;
R_jit_enabled = 0;
newop = R_cmpfun(op);
body = BODY(newop);
SET_BODY(op, body);
R_jit_enabled = old_enabled;
}
begincontext(&cntxt, CTXT_RETURN, call, newrho, rho, arglist, op);
savedsrcref = R_Srcref; /* saved in context for longjmp, and protection */
......@@ -1335,21 +1317,25 @@ static SEXP R_execClosure(SEXP call, SEXP op, SEXP arglist, SEXP rho,
/* Set a longjmp target which will catch any explicit returns
from the function body. */
SEXP res;
if ((SETJMP(cntxt.cjmpbuf))) {
if (R_ReturnedValue == R_RestartToken) {
cntxt.callflag = CTXT_RETURN; /* turn restart off */
R_ReturnedValue = R_NilValue; /* remove restart token */
PROTECT(res = evalv(body, newrho, VARIANT_NOT_WHOLE_BODY));
res = evalv(body, newrho, VARIANT_NOT_WHOLE_BODY);
}
else {
PROTECT(res = R_ReturnedValue);
res = R_ReturnedValue;
WAIT_UNTIL_COMPUTED(res);
}
}
else {
PROTECT(res = evalv(body, newrho, 0));
res = evalv(body, newrho, 0);
}
PROTECT(res);
R_Srcref = savedsrcref;
endcontext(&cntxt);
......@@ -1358,7 +1344,7 @@ static SEXP R_execClosure(SEXP call, SEXP op, SEXP arglist, SEXP rho,
printcall (call, rho);
}
UNPROTECT(3); /* op, arglist, res */
UNPROTECT(1); /* res */
return res;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment