Since the fast_yield branch target was introduced, it appears that most

tests of "why" against WHY_YIELD became useless.  This patch removes them,
but assert()s that why != WHY_YIELD everywhere such a test was removed.
The test suite ran fine under a debug build (i.e., the asserts never
triggered).
This commit is contained in:
Tim Peters 2004-04-05 19:36:21 +00:00
parent ed9192e2ae
commit 8a5c3c76be
1 changed files with 41 additions and 41 deletions

View File

@ -47,7 +47,7 @@ static int call_trace(Py_tracefunc, PyObject *, PyFrameObject *,
static void call_trace_protected(Py_tracefunc, PyObject *, static void call_trace_protected(Py_tracefunc, PyObject *,
PyFrameObject *, int); PyFrameObject *, int);
static void call_exc_trace(Py_tracefunc, PyObject *, PyFrameObject *); static void call_exc_trace(Py_tracefunc, PyObject *, PyFrameObject *);
static int maybe_call_line_trace(Py_tracefunc, PyObject *, static int maybe_call_line_trace(Py_tracefunc, PyObject *,
PyFrameObject *, int *, int *, int *); PyFrameObject *, int *, int *, int *);
static PyObject *apply_slice(PyObject *, PyObject *, PyObject *); static PyObject *apply_slice(PyObject *, PyObject *, PyObject *);
@ -123,7 +123,7 @@ static int pcall[PCALL_NUM];
PyObject * PyObject *
PyEval_GetCallStats(PyObject *self) PyEval_GetCallStats(PyObject *self)
{ {
return Py_BuildValue("iiiiiiiiii", return Py_BuildValue("iiiiiiiiii",
pcall[0], pcall[1], pcall[2], pcall[3], pcall[0], pcall[1], pcall[2], pcall[3],
pcall[4], pcall[5], pcall[6], pcall[7], pcall[4], pcall[5], pcall[6], pcall[7],
pcall[8], pcall[9]); pcall[8], pcall[9]);
@ -147,7 +147,7 @@ typedef struct {
PyFrameObject *gi_frame; PyFrameObject *gi_frame;
/* True if generator is being executed. */ /* True if generator is being executed. */
int gi_running; int gi_running;
/* List of weak reference. */ /* List of weak reference. */
@ -593,11 +593,11 @@ eval_frame(PyFrameObject *f)
PyThreadState *tstate = PyThreadState_GET(); PyThreadState *tstate = PyThreadState_GET();
PyCodeObject *co; PyCodeObject *co;
/* when tracing we set things up so that /* when tracing we set things up so that
not (instr_lb <= current_bytecode_offset < instr_ub) not (instr_lb <= current_bytecode_offset < instr_ub)
is true when the line being executed has changed. The is true when the line being executed has changed. The
initial values are such as to make this false the first initial values are such as to make this false the first
time it is tested. */ time it is tested. */
int instr_ub = -1, instr_lb = 0, instr_prev = -1; int instr_ub = -1, instr_lb = 0, instr_prev = -1;
@ -644,8 +644,8 @@ eval_frame(PyFrameObject *f)
A successful prediction saves a trip through the eval-loop including A successful prediction saves a trip through the eval-loop including
its two unpredictable branches, the HASARG test and the switch-case. its two unpredictable branches, the HASARG test and the switch-case.
If collecting opcode statistics, turn off prediction so that If collecting opcode statistics, turn off prediction so that
statistics are accurately maintained (the predictions bypass statistics are accurately maintained (the predictions bypass
the opcode frequency counter updates). the opcode frequency counter updates).
*/ */
@ -841,7 +841,7 @@ eval_frame(PyFrameObject *f)
/* see maybe_call_line_trace /* see maybe_call_line_trace
for expository comments */ for expository comments */
f->f_stacktop = stack_pointer; f->f_stacktop = stack_pointer;
err = maybe_call_line_trace(tstate->c_tracefunc, err = maybe_call_line_trace(tstate->c_tracefunc,
tstate->c_traceobj, tstate->c_traceobj,
f, &instr_lb, &instr_ub, f, &instr_lb, &instr_ub,
@ -1539,7 +1539,7 @@ eval_frame(PyFrameObject *f)
!isspace(Py_CHARMASK(s[len-1])) || !isspace(Py_CHARMASK(s[len-1])) ||
s[len-1] == ' ') s[len-1] == ' ')
PyFile_SoftSpace(w, 1); PyFile_SoftSpace(w, 1);
} }
#ifdef Py_USING_UNICODE #ifdef Py_USING_UNICODE
else if (PyUnicode_Check(v)) { else if (PyUnicode_Check(v)) {
Py_UNICODE *s = PyUnicode_AS_UNICODE(v); Py_UNICODE *s = PyUnicode_AS_UNICODE(v);
@ -1653,8 +1653,8 @@ eval_frame(PyFrameObject *f)
v = POP(); v = POP();
if (PyInt_Check(v)) { if (PyInt_Check(v)) {
why = (enum why_code) PyInt_AS_LONG(v); why = (enum why_code) PyInt_AS_LONG(v);
assert(why != WHY_YIELD);
if (why == WHY_RETURN || if (why == WHY_RETURN ||
why == WHY_YIELD ||
why == WHY_CONTINUE) why == WHY_CONTINUE)
retval = POP(); retval = POP();
} }
@ -2325,9 +2325,10 @@ eval_frame(PyFrameObject *f)
/* Unwind stacks if a (pseudo) exception occurred */ /* Unwind stacks if a (pseudo) exception occurred */
fast_block_end: fast_block_end:
while (why != WHY_NOT && why != WHY_YIELD && f->f_iblock > 0) { while (why != WHY_NOT && f->f_iblock > 0) {
PyTryBlock *b = PyFrame_BlockPop(f); PyTryBlock *b = PyFrame_BlockPop(f);
assert(why != WHY_YIELD);
if (b->b_type == SETUP_LOOP && why == WHY_CONTINUE) { if (b->b_type == SETUP_LOOP && why == WHY_CONTINUE) {
/* For a continue inside a try block, /* For a continue inside a try block,
don't pop the block for the loop. */ don't pop the block for the loop. */
@ -2397,15 +2398,14 @@ fast_block_end:
} /* main loop */ } /* main loop */
if (why != WHY_YIELD) { assert(why != WHY_YIELD);
/* Pop remaining stack entries -- but when yielding */ /* Pop remaining stack entries. */
while (!EMPTY()) { while (!EMPTY()) {
v = POP(); v = POP();
Py_XDECREF(v); Py_XDECREF(v);
}
} }
if (why != WHY_RETURN && why != WHY_YIELD) if (why != WHY_RETURN)
retval = NULL; retval = NULL;
fast_yield: fast_yield:
@ -2461,7 +2461,7 @@ PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,
PyObject *x, *u; PyObject *x, *u;
if (globals == NULL) { if (globals == NULL) {
PyErr_SetString(PyExc_SystemError, PyErr_SetString(PyExc_SystemError,
"PyEval_EvalCodeEx: NULL globals"); "PyEval_EvalCodeEx: NULL globals");
return NULL; return NULL;
} }
@ -3083,12 +3083,12 @@ _PyEval_CallTracing(PyObject *func, PyObject *args)
} }
static int static int
maybe_call_line_trace(Py_tracefunc func, PyObject *obj, maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
PyFrameObject *frame, int *instr_lb, int *instr_ub, PyFrameObject *frame, int *instr_lb, int *instr_ub,
int *instr_prev) int *instr_prev)
{ {
/* The theory of SET_LINENO-less tracing. /* The theory of SET_LINENO-less tracing.
In a nutshell, we use the co_lnotab field of the code object In a nutshell, we use the co_lnotab field of the code object
to tell when execution has moved onto a different line. to tell when execution has moved onto a different line.
@ -3117,17 +3117,17 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
2 0 LOAD_FAST 0 (a) 2 0 LOAD_FAST 0 (a)
3 JUMP_IF_FALSE 9 (to 15) 3 JUMP_IF_FALSE 9 (to 15)
6 POP_TOP 6 POP_TOP
3 7 LOAD_CONST 1 (1) 3 7 LOAD_CONST 1 (1)
10 PRINT_ITEM 10 PRINT_ITEM
11 PRINT_NEWLINE 11 PRINT_NEWLINE
12 JUMP_FORWARD 6 (to 21) 12 JUMP_FORWARD 6 (to 21)
>> 15 POP_TOP >> 15 POP_TOP
5 16 LOAD_CONST 2 (2) 5 16 LOAD_CONST 2 (2)
19 PRINT_ITEM 19 PRINT_ITEM
20 PRINT_NEWLINE 20 PRINT_NEWLINE
>> 21 LOAD_CONST 0 (None) >> 21 LOAD_CONST 0 (None)
24 RETURN_VALUE 24 RETURN_VALUE
@ -3193,7 +3193,7 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
if (addr == frame->f_lasti) { if (addr == frame->f_lasti) {
frame->f_lineno = line; frame->f_lineno = line;
result = call_trace(func, obj, frame, result = call_trace(func, obj, frame,
PyTrace_LINE, Py_None); PyTrace_LINE, Py_None);
} }
@ -3211,7 +3211,7 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
} }
else if (frame->f_lasti <= *instr_prev) { else if (frame->f_lasti <= *instr_prev) {
/* jumping back in the same line forces a trace event */ /* jumping back in the same line forces a trace event */
result = call_trace(func, obj, frame, result = call_trace(func, obj, frame,
PyTrace_LINE, Py_None); PyTrace_LINE, Py_None);
} }
*instr_prev = frame->f_lasti; *instr_prev = frame->f_lasti;
@ -3412,14 +3412,14 @@ static void
err_args(PyObject *func, int flags, int nargs) err_args(PyObject *func, int flags, int nargs)
{ {
if (flags & METH_NOARGS) if (flags & METH_NOARGS)
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"%.200s() takes no arguments (%d given)", "%.200s() takes no arguments (%d given)",
((PyCFunctionObject *)func)->m_ml->ml_name, ((PyCFunctionObject *)func)->m_ml->ml_name,
nargs); nargs);
else else
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"%.200s() takes exactly one argument (%d given)", "%.200s() takes exactly one argument (%d given)",
((PyCFunctionObject *)func)->m_ml->ml_name, ((PyCFunctionObject *)func)->m_ml->ml_name,
nargs); nargs);
} }
@ -3505,8 +3505,8 @@ call_function(PyObject ***pp_stack, int oparg)
BEGIN_C_TRACE BEGIN_C_TRACE
x = PyCFunction_Call(func, callargs, NULL); x = PyCFunction_Call(func, callargs, NULL);
END_C_TRACE END_C_TRACE
Py_XDECREF(callargs); Py_XDECREF(callargs);
} }
} else { } else {
if (PyMethod_Check(func) && PyMethod_GET_SELF(func) != NULL) { if (PyMethod_Check(func) && PyMethod_GET_SELF(func) != NULL) {
/* optimize access to bound methods */ /* optimize access to bound methods */
@ -3524,11 +3524,11 @@ call_function(PyObject ***pp_stack, int oparg)
Py_INCREF(func); Py_INCREF(func);
if (PyFunction_Check(func)) if (PyFunction_Check(func))
x = fast_function(func, pp_stack, n, na, nk); x = fast_function(func, pp_stack, n, na, nk);
else else
x = do_call(func, pp_stack, na, nk); x = do_call(func, pp_stack, na, nk);
Py_DECREF(func); Py_DECREF(func);
} }
/* What does this do? */ /* What does this do? */
while ((*pp_stack) > pfunc) { while ((*pp_stack) > pfunc) {
w = EXT_POP(*pp_stack); w = EXT_POP(*pp_stack);
@ -3822,7 +3822,7 @@ _PyEval_SliceIndex(PyObject *v, int *pi)
/* It's an overflow error, so we need to /* It's an overflow error, so we need to
check the sign of the long integer, check the sign of the long integer,
set the value to INT_MAX or -INT_MAX, set the value to INT_MAX or -INT_MAX,
and clear the error. */ and clear the error. */
/* Create a long integer with a value of 0 */ /* Create a long integer with a value of 0 */
@ -4114,10 +4114,10 @@ exec_statement(PyFrameObject *f, PyObject *prog, PyObject *globals,
cf.cf_flags = 0; cf.cf_flags = 0;
if (PyEval_MergeCompilerFlags(&cf)) if (PyEval_MergeCompilerFlags(&cf))
v = PyRun_FileFlags(fp, name, Py_file_input, globals, v = PyRun_FileFlags(fp, name, Py_file_input, globals,
locals, &cf); locals, &cf);
else else
v = PyRun_File(fp, name, Py_file_input, globals, v = PyRun_File(fp, name, Py_file_input, globals,
locals); locals);
} }
else { else {
PyObject *tmp = NULL; PyObject *tmp = NULL;
@ -4136,7 +4136,7 @@ exec_statement(PyFrameObject *f, PyObject *prog, PyObject *globals,
if (PyString_AsStringAndSize(prog, &str, NULL)) if (PyString_AsStringAndSize(prog, &str, NULL))
return -1; return -1;
if (PyEval_MergeCompilerFlags(&cf)) if (PyEval_MergeCompilerFlags(&cf))
v = PyRun_StringFlags(str, Py_file_input, globals, v = PyRun_StringFlags(str, Py_file_input, globals,
locals, &cf); locals, &cf);
else else
v = PyRun_String(str, Py_file_input, globals, locals); v = PyRun_String(str, Py_file_input, globals, locals);