Rich comparisons fall-out:

- Use PyObject_RichCompare*() where possible: when comparing
  keyword arguments, in _PyEval_SliceIndex(), and of course in
  cmp_outcome().

Unrelated stuff:

- Removed all trailing whitespace.

- Folded some long lines.
This commit is contained in:
Guido van Rossum 2001-01-17 15:42:30 +00:00
parent f916e7aa62
commit ac7be6888b
1 changed files with 147 additions and 148 deletions

View File

@ -48,7 +48,7 @@ static PyObject *fast_function(PyObject *, PyObject ***, int, int, int);
static PyObject *fast_cfunction(PyObject *, PyObject ***, int); static PyObject *fast_cfunction(PyObject *, PyObject ***, int);
static PyObject *do_call(PyObject *, PyObject ***, int, int); static PyObject *do_call(PyObject *, PyObject ***, int, int);
static PyObject *ext_do_call(PyObject *, PyObject ***, int, int, int); static PyObject *ext_do_call(PyObject *, PyObject ***, int, int, int);
static PyObject *update_keyword_args(PyObject *, int, PyObject ***, PyObject *); static PyObject *update_keyword_args(PyObject *, int, PyObject ***,PyObject *);
static PyObject *update_star_args(int, int, PyObject *, PyObject ***); static PyObject *update_star_args(int, int, PyObject *, PyObject ***);
static PyObject *load_args(PyObject ***, int); static PyObject *load_args(PyObject ***, int);
#define CALL_FLAG_VAR 1 #define CALL_FLAG_VAR 1
@ -493,8 +493,12 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
for (j = 0; j < co->co_argcount; j++) { for (j = 0; j < co->co_argcount; j++) {
PyObject *nm = PyTuple_GET_ITEM( PyObject *nm = PyTuple_GET_ITEM(
co->co_varnames, j); co->co_varnames, j);
if (PyObject_Compare(keyword, nm) == 0) int cmp = PyObject_RichCompareBool(
keyword, nm, Py_EQ);
if (cmp > 0)
break; break;
else if (cmp < 0)
goto fail;
} }
/* Check errors from Compare */ /* Check errors from Compare */
if (PyErr_Occurred()) if (PyErr_Occurred())
@ -512,7 +516,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
} }
else { else {
if (GETLOCAL(j) != NULL) { if (GETLOCAL(j) != NULL) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"%.200s() got multiple " "%.200s() got multiple "
"values for keyword " "values for keyword "
"argument '%.400s'", "argument '%.400s'",
@ -606,12 +610,12 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
_PyCode_GETCODEPTR(co, &first_instr); _PyCode_GETCODEPTR(co, &first_instr);
next_instr = first_instr; next_instr = first_instr;
stack_pointer = f->f_valuestack; stack_pointer = f->f_valuestack;
why = WHY_NOT; why = WHY_NOT;
err = 0; err = 0;
x = Py_None; /* Not a reference, just anything non-NULL */ x = Py_None; /* Not a reference, just anything non-NULL */
w = NULL; w = NULL;
for (;;) { for (;;) {
/* Do periodic things. Doing this every time through /* Do periodic things. Doing this every time through
the loop would add too much overhead, so we do it the loop would add too much overhead, so we do it
@ -620,7 +624,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
event needs attention (e.g. a signal handler or event needs attention (e.g. a signal handler or
async I/O handler); see Py_AddPendingCall() and async I/O handler); see Py_AddPendingCall() and
Py_MakePendingCalls() above. */ Py_MakePendingCalls() above. */
if (things_to_do || --tstate->ticker < 0) { if (things_to_do || --tstate->ticker < 0) {
tstate->ticker = tstate->interp->checkinterval; tstate->ticker = tstate->interp->checkinterval;
if (things_to_do) { if (things_to_do) {
@ -662,7 +666,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
#if defined(Py_DEBUG) || defined(LLTRACE) #if defined(Py_DEBUG) || defined(LLTRACE)
f->f_lasti = INSTR_OFFSET(); f->f_lasti = INSTR_OFFSET();
#endif #endif
opcode = NEXTOP(); opcode = NEXTOP();
if (HAS_ARG(opcode)) if (HAS_ARG(opcode))
oparg = NEXTARG(); oparg = NEXTARG();
@ -677,7 +681,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
#ifdef LLTRACE #ifdef LLTRACE
/* Instruction tracing */ /* Instruction tracing */
if (lltrace) { if (lltrace) {
if (HAS_ARG(opcode)) { if (HAS_ARG(opcode)) {
printf("%d: %d, %d\n", printf("%d: %d, %d\n",
@ -693,26 +697,26 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
/* Main switch on opcode */ /* Main switch on opcode */
switch (opcode) { switch (opcode) {
/* BEWARE! /* BEWARE!
It is essential that any operation that fails sets either It is essential that any operation that fails sets either
x to NULL, err to nonzero, or why to anything but WHY_NOT, x to NULL, err to nonzero, or why to anything but WHY_NOT,
and that no operation that succeeds does this! */ and that no operation that succeeds does this! */
/* case STOP_CODE: this is an error! */ /* case STOP_CODE: this is an error! */
case POP_TOP: case POP_TOP:
v = POP(); v = POP();
Py_DECREF(v); Py_DECREF(v);
continue; continue;
case ROT_TWO: case ROT_TWO:
v = POP(); v = POP();
w = POP(); w = POP();
PUSH(v); PUSH(v);
PUSH(w); PUSH(w);
continue; continue;
case ROT_THREE: case ROT_THREE:
v = POP(); v = POP();
w = POP(); w = POP();
@ -721,7 +725,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
PUSH(w); PUSH(w);
continue; continue;
case ROT_FOUR: case ROT_FOUR:
u = POP(); u = POP();
v = POP(); v = POP();
@ -732,13 +736,13 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(w); PUSH(w);
PUSH(v); PUSH(v);
continue; continue;
case DUP_TOP: case DUP_TOP:
v = TOP(); v = TOP();
Py_INCREF(v); Py_INCREF(v);
PUSH(v); PUSH(v);
continue; continue;
case DUP_TOPX: case DUP_TOPX:
switch (oparg) { switch (oparg) {
case 1: case 1:
@ -819,7 +823,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case UNARY_NEGATIVE: case UNARY_NEGATIVE:
v = POP(); v = POP();
x = PyNumber_Negative(v); x = PyNumber_Negative(v);
@ -827,7 +831,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case UNARY_NOT: case UNARY_NOT:
v = POP(); v = POP();
err = PyObject_IsTrue(v); err = PyObject_IsTrue(v);
@ -844,7 +848,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
continue; continue;
} }
break; break;
case UNARY_CONVERT: case UNARY_CONVERT:
v = POP(); v = POP();
x = PyObject_Repr(v); x = PyObject_Repr(v);
@ -852,7 +856,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case UNARY_INVERT: case UNARY_INVERT:
v = POP(); v = POP();
x = PyNumber_Invert(v); x = PyNumber_Invert(v);
@ -860,7 +864,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case BINARY_POWER: case BINARY_POWER:
w = POP(); w = POP();
v = POP(); v = POP();
@ -870,7 +874,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case BINARY_MULTIPLY: case BINARY_MULTIPLY:
w = POP(); w = POP();
v = POP(); v = POP();
@ -880,7 +884,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case BINARY_DIVIDE: case BINARY_DIVIDE:
w = POP(); w = POP();
v = POP(); v = POP();
@ -890,7 +894,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case BINARY_MODULO: case BINARY_MODULO:
w = POP(); w = POP();
v = POP(); v = POP();
@ -900,7 +904,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case BINARY_ADD: case BINARY_ADD:
w = POP(); w = POP();
v = POP(); v = POP();
@ -925,7 +929,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case BINARY_SUBTRACT: case BINARY_SUBTRACT:
w = POP(); w = POP();
v = POP(); v = POP();
@ -950,7 +954,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case BINARY_SUBSCR: case BINARY_SUBSCR:
w = POP(); w = POP();
v = POP(); v = POP();
@ -977,7 +981,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case BINARY_LSHIFT: case BINARY_LSHIFT:
w = POP(); w = POP();
v = POP(); v = POP();
@ -987,7 +991,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case BINARY_RSHIFT: case BINARY_RSHIFT:
w = POP(); w = POP();
v = POP(); v = POP();
@ -997,7 +1001,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case BINARY_AND: case BINARY_AND:
w = POP(); w = POP();
v = POP(); v = POP();
@ -1007,7 +1011,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case BINARY_XOR: case BINARY_XOR:
w = POP(); w = POP();
v = POP(); v = POP();
@ -1017,7 +1021,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case BINARY_OR: case BINARY_OR:
w = POP(); w = POP();
v = POP(); v = POP();
@ -1037,7 +1041,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case INPLACE_MULTIPLY: case INPLACE_MULTIPLY:
w = POP(); w = POP();
v = POP(); v = POP();
@ -1047,7 +1051,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case INPLACE_DIVIDE: case INPLACE_DIVIDE:
w = POP(); w = POP();
v = POP(); v = POP();
@ -1057,7 +1061,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case INPLACE_MODULO: case INPLACE_MODULO:
w = POP(); w = POP();
v = POP(); v = POP();
@ -1067,7 +1071,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case INPLACE_ADD: case INPLACE_ADD:
w = POP(); w = POP();
v = POP(); v = POP();
@ -1092,7 +1096,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case INPLACE_SUBTRACT: case INPLACE_SUBTRACT:
w = POP(); w = POP();
v = POP(); v = POP();
@ -1117,7 +1121,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case INPLACE_LSHIFT: case INPLACE_LSHIFT:
w = POP(); w = POP();
v = POP(); v = POP();
@ -1127,7 +1131,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case INPLACE_RSHIFT: case INPLACE_RSHIFT:
w = POP(); w = POP();
v = POP(); v = POP();
@ -1137,7 +1141,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case INPLACE_AND: case INPLACE_AND:
w = POP(); w = POP();
v = POP(); v = POP();
@ -1147,7 +1151,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case INPLACE_XOR: case INPLACE_XOR:
w = POP(); w = POP();
v = POP(); v = POP();
@ -1157,7 +1161,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case INPLACE_OR: case INPLACE_OR:
w = POP(); w = POP();
v = POP(); v = POP();
@ -1188,7 +1192,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case STORE_SLICE+0: case STORE_SLICE+0:
case STORE_SLICE+1: case STORE_SLICE+1:
case STORE_SLICE+2: case STORE_SLICE+2:
@ -1210,7 +1214,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
Py_XDECREF(w); Py_XDECREF(w);
if (err == 0) continue; if (err == 0) continue;
break; break;
case DELETE_SLICE+0: case DELETE_SLICE+0:
case DELETE_SLICE+1: case DELETE_SLICE+1:
case DELETE_SLICE+2: case DELETE_SLICE+2:
@ -1231,7 +1235,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
Py_XDECREF(w); Py_XDECREF(w);
if (err == 0) continue; if (err == 0) continue;
break; break;
case STORE_SUBSCR: case STORE_SUBSCR:
w = POP(); w = POP();
v = POP(); v = POP();
@ -1243,7 +1247,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
Py_DECREF(w); Py_DECREF(w);
if (err == 0) continue; if (err == 0) continue;
break; break;
case DELETE_SUBSCR: case DELETE_SUBSCR:
w = POP(); w = POP();
v = POP(); v = POP();
@ -1311,7 +1315,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
if (err == 0) if (err == 0)
continue; continue;
break; break;
case PRINT_NEWLINE_TO: case PRINT_NEWLINE_TO:
w = stream = POP(); w = stream = POP();
/* fall through to PRINT_NEWLINE */ /* fall through to PRINT_NEWLINE */
@ -1331,7 +1335,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
Py_XDECREF(stream); Py_XDECREF(stream);
stream = NULL; stream = NULL;
break; break;
#ifdef CASE_TOO_BIG #ifdef CASE_TOO_BIG
default: switch (opcode) { default: switch (opcode) {
@ -1361,7 +1365,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
break; break;
} }
break; break;
case LOAD_LOCALS: case LOAD_LOCALS:
if ((x = f->f_locals) == NULL) { if ((x = f->f_locals) == NULL) {
PyErr_SetString(PyExc_SystemError, PyErr_SetString(PyExc_SystemError,
@ -1371,7 +1375,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
Py_INCREF(x); Py_INCREF(x);
PUSH(x); PUSH(x);
break; break;
case RETURN_VALUE: case RETURN_VALUE:
retval = POP(); retval = POP();
why = WHY_RETURN; why = WHY_RETURN;
@ -1386,7 +1390,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
Py_DECREF(v); Py_DECREF(v);
Py_DECREF(w); Py_DECREF(w);
break; break;
case POP_BLOCK: case POP_BLOCK:
{ {
PyTryBlock *b = PyFrame_BlockPop(f); PyTryBlock *b = PyFrame_BlockPop(f);
@ -1396,7 +1400,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
} }
} }
break; break;
case END_FINALLY: case END_FINALLY:
v = POP(); v = POP();
if (PyInt_Check(v)) { if (PyInt_Check(v)) {
@ -1418,7 +1422,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
} }
Py_DECREF(v); Py_DECREF(v);
break; break;
case BUILD_CLASS: case BUILD_CLASS:
u = POP(); u = POP();
v = POP(); v = POP();
@ -1429,7 +1433,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
Py_DECREF(v); Py_DECREF(v);
Py_DECREF(w); Py_DECREF(w);
break; break;
case STORE_NAME: case STORE_NAME:
w = GETNAMEV(oparg); w = GETNAMEV(oparg);
v = POP(); v = POP();
@ -1441,7 +1445,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
err = PyDict_SetItem(x, w, v); err = PyDict_SetItem(x, w, v);
Py_DECREF(v); Py_DECREF(v);
break; break;
case DELETE_NAME: case DELETE_NAME:
w = GETNAMEV(oparg); w = GETNAMEV(oparg);
if ((x = f->f_locals) == NULL) { if ((x = f->f_locals) == NULL) {
@ -1450,7 +1454,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
break; break;
} }
if ((err = PyDict_DelItem(x, w)) != 0) if ((err = PyDict_DelItem(x, w)) != 0)
format_exc_check_arg(PyExc_NameError, format_exc_check_arg(PyExc_NameError,
NAME_ERROR_MSG ,w); NAME_ERROR_MSG ,w);
break; break;
@ -1498,7 +1502,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
} }
Py_DECREF(v); Py_DECREF(v);
break; break;
case STORE_ATTR: case STORE_ATTR:
w = GETNAMEV(oparg); w = GETNAMEV(oparg);
v = POP(); v = POP();
@ -1507,7 +1511,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
Py_DECREF(v); Py_DECREF(v);
Py_DECREF(u); Py_DECREF(u);
break; break;
case DELETE_ATTR: case DELETE_ATTR:
w = GETNAMEV(oparg); w = GETNAMEV(oparg);
v = POP(); v = POP();
@ -1515,27 +1519,27 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
/* del v.w */ /* del v.w */
Py_DECREF(v); Py_DECREF(v);
break; break;
case STORE_GLOBAL: case STORE_GLOBAL:
w = GETNAMEV(oparg); w = GETNAMEV(oparg);
v = POP(); v = POP();
err = PyDict_SetItem(f->f_globals, w, v); err = PyDict_SetItem(f->f_globals, w, v);
Py_DECREF(v); Py_DECREF(v);
break; break;
case DELETE_GLOBAL: case DELETE_GLOBAL:
w = GETNAMEV(oparg); w = GETNAMEV(oparg);
if ((err = PyDict_DelItem(f->f_globals, w)) != 0) if ((err = PyDict_DelItem(f->f_globals, w)) != 0)
format_exc_check_arg( format_exc_check_arg(
PyExc_NameError, NAME_ERROR_MSG ,w); PyExc_NameError, NAME_ERROR_MSG ,w);
break; break;
case LOAD_CONST: case LOAD_CONST:
x = GETCONST(oparg); x = GETCONST(oparg);
Py_INCREF(x); Py_INCREF(x);
PUSH(x); PUSH(x);
break; break;
case LOAD_NAME: case LOAD_NAME:
w = GETNAMEV(oparg); w = GETNAMEV(oparg);
if ((x = f->f_locals) == NULL) { if ((x = f->f_locals) == NULL) {
@ -1550,7 +1554,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
x = PyDict_GetItem(f->f_builtins, w); x = PyDict_GetItem(f->f_builtins, w);
if (x == NULL) { if (x == NULL) {
format_exc_check_arg( format_exc_check_arg(
PyExc_NameError, PyExc_NameError,
NAME_ERROR_MSG ,w); NAME_ERROR_MSG ,w);
break; break;
} }
@ -1559,7 +1563,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
Py_INCREF(x); Py_INCREF(x);
PUSH(x); PUSH(x);
break; break;
case LOAD_GLOBAL: case LOAD_GLOBAL:
w = GETNAMEV(oparg); w = GETNAMEV(oparg);
x = PyDict_GetItem(f->f_globals, w); x = PyDict_GetItem(f->f_globals, w);
@ -1567,7 +1571,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
x = PyDict_GetItem(f->f_builtins, w); x = PyDict_GetItem(f->f_builtins, w);
if (x == NULL) { if (x == NULL) {
format_exc_check_arg( format_exc_check_arg(
PyExc_NameError, PyExc_NameError,
NAME_ERROR_MSG ,w); NAME_ERROR_MSG ,w);
break; break;
} }
@ -1608,7 +1612,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
} }
SETLOCAL(oparg, NULL); SETLOCAL(oparg, NULL);
continue; continue;
case BUILD_TUPLE: case BUILD_TUPLE:
x = PyTuple_New(oparg); x = PyTuple_New(oparg);
if (x != NULL) { if (x != NULL) {
@ -1620,7 +1624,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
continue; continue;
} }
break; break;
case BUILD_LIST: case BUILD_LIST:
x = PyList_New(oparg); x = PyList_New(oparg);
if (x != NULL) { if (x != NULL) {
@ -1632,13 +1636,13 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
continue; continue;
} }
break; break;
case BUILD_MAP: case BUILD_MAP:
x = PyDict_New(); x = PyDict_New();
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case LOAD_ATTR: case LOAD_ATTR:
w = GETNAMEV(oparg); w = GETNAMEV(oparg);
v = POP(); v = POP();
@ -1647,7 +1651,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case COMPARE_OP: case COMPARE_OP:
w = POP(); w = POP();
v = POP(); v = POP();
@ -1680,7 +1684,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case IMPORT_NAME: case IMPORT_NAME:
w = GETNAMEV(oparg); w = GETNAMEV(oparg);
x = PyDict_GetItemString(f->f_builtins, "__import__"); x = PyDict_GetItemString(f->f_builtins, "__import__");
@ -1706,7 +1710,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PUSH(x); PUSH(x);
if (x != NULL) continue; if (x != NULL) continue;
break; break;
case IMPORT_STAR: case IMPORT_STAR:
v = POP(); v = POP();
PyFrame_FastToLocals(f); PyFrame_FastToLocals(f);
@ -1732,7 +1736,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
case JUMP_FORWARD: case JUMP_FORWARD:
JUMPBY(oparg); JUMPBY(oparg);
continue; continue;
case JUMP_IF_FALSE: case JUMP_IF_FALSE:
err = PyObject_IsTrue(TOP()); err = PyObject_IsTrue(TOP());
if (err > 0) if (err > 0)
@ -1742,7 +1746,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
else else
break; break;
continue; continue;
case JUMP_IF_TRUE: case JUMP_IF_TRUE:
err = PyObject_IsTrue(TOP()); err = PyObject_IsTrue(TOP());
if (err > 0) { if (err > 0) {
@ -1754,11 +1758,11 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
else else
break; break;
continue; continue;
case JUMP_ABSOLUTE: case JUMP_ABSOLUTE:
JUMPTO(oparg); JUMPTO(oparg);
continue; continue;
case FOR_LOOP: case FOR_LOOP:
/* for v in s: ... /* for v in s: ...
On entry: stack contains s, i. On entry: stack contains s, i.
@ -1789,14 +1793,14 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
} }
} }
break; break;
case SETUP_LOOP: case SETUP_LOOP:
case SETUP_EXCEPT: case SETUP_EXCEPT:
case SETUP_FINALLY: case SETUP_FINALLY:
PyFrame_BlockSetup(f, opcode, INSTR_OFFSET() + oparg, PyFrame_BlockSetup(f, opcode, INSTR_OFFSET() + oparg,
STACK_LEVEL()); STACK_LEVEL());
continue; continue;
case SET_LINENO: case SET_LINENO:
#ifdef LLTRACE #ifdef LLTRACE
if (lltrace) if (lltrace)
@ -1827,13 +1831,13 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
if (PyCFunction_Check(func)) { if (PyCFunction_Check(func)) {
if (PyCFunction_GET_FLAGS(func) == 0) { if (PyCFunction_GET_FLAGS(func) == 0) {
x = fast_cfunction(func, x = fast_cfunction(func,
&stack_pointer, na); &stack_pointer, na);
} else { } else {
x = do_call(func, &stack_pointer, x = do_call(func, &stack_pointer,
na, nk); na, nk);
} }
} else { } else {
if (PyMethod_Check(func) if (PyMethod_Check(func)
&& PyMethod_GET_SELF(func) != NULL) { && PyMethod_GET_SELF(func) != NULL) {
/* optimize access to bound methods */ /* optimize access to bound methods */
PyObject *self = PyMethod_GET_SELF(func); PyObject *self = PyMethod_GET_SELF(func);
@ -1844,11 +1848,11 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
*pfunc = self; *pfunc = self;
na++; na++;
n++; n++;
} else } else
Py_INCREF(func); Py_INCREF(func);
if (PyFunction_Check(func)) { if (PyFunction_Check(func)) {
x = fast_function(func, &stack_pointer, x = fast_function(func, &stack_pointer,
n, na, nk); n, na, nk);
} else { } else {
x = do_call(func, &stack_pointer, x = do_call(func, &stack_pointer,
na, nk); na, nk);
@ -1861,11 +1865,11 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
Py_DECREF(w); Py_DECREF(w);
} }
PUSH(x); PUSH(x);
if (x != NULL) if (x != NULL)
continue; continue;
break; break;
} }
case CALL_FUNCTION_VAR: case CALL_FUNCTION_VAR:
case CALL_FUNCTION_KW: case CALL_FUNCTION_KW:
case CALL_FUNCTION_VAR_KW: case CALL_FUNCTION_VAR_KW:
@ -1883,7 +1887,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
func = *pfunc; func = *pfunc;
f->f_lasti = INSTR_OFFSET() - 3; /* For tracing */ f->f_lasti = INSTR_OFFSET() - 3; /* For tracing */
if (PyMethod_Check(func) if (PyMethod_Check(func)
&& PyMethod_GET_SELF(func) != NULL) { && PyMethod_GET_SELF(func) != NULL) {
PyObject *self = PyMethod_GET_SELF(func); PyObject *self = PyMethod_GET_SELF(func);
Py_INCREF(self); Py_INCREF(self);
@ -1893,7 +1897,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
*pfunc = self; *pfunc = self;
na++; na++;
n++; n++;
} else } else
Py_INCREF(func); Py_INCREF(func);
x = ext_do_call(func, &stack_pointer, flags, na, nk); x = ext_do_call(func, &stack_pointer, flags, na, nk);
Py_DECREF(func); Py_DECREF(func);
@ -1903,11 +1907,11 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
Py_DECREF(w); Py_DECREF(w);
} }
PUSH(x); PUSH(x);
if (x != NULL) if (x != NULL)
continue; continue;
break; break;
} }
case MAKE_FUNCTION: case MAKE_FUNCTION:
v = POP(); /* code object */ v = POP(); /* code object */
x = PyFunction_New(v, f->f_globals); x = PyFunction_New(v, f->f_globals);
@ -1966,9 +1970,9 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
} /* switch */ } /* switch */
on_error: on_error:
/* Quickly continue if no error occurred */ /* Quickly continue if no error occurred */
if (why == WHY_NOT) { if (why == WHY_NOT) {
if (err == 0 && x != NULL) { if (err == 0 && x != NULL) {
#ifdef CHECKEXC #ifdef CHECKEXC
@ -1986,7 +1990,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
} }
/* Double-check exception status */ /* Double-check exception status */
if (why == WHY_EXCEPTION || why == WHY_RERAISE) { if (why == WHY_EXCEPTION || why == WHY_RERAISE) {
if (!PyErr_Occurred()) { if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_SystemError, PyErr_SetString(PyExc_SystemError,
@ -2007,7 +2011,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
#endif #endif
/* Log traceback info if this is a real exception */ /* Log traceback info if this is a real exception */
if (why == WHY_EXCEPTION) { if (why == WHY_EXCEPTION) {
f->f_lasti = INSTR_OFFSET() - 1; f->f_lasti = INSTR_OFFSET() - 1;
if (HAS_ARG(opcode)) if (HAS_ARG(opcode))
@ -2020,14 +2024,14 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
call_exc_trace(&tstate->sys_profilefunc, call_exc_trace(&tstate->sys_profilefunc,
(PyObject**)0, f); (PyObject**)0, f);
} }
/* For the rest, treat WHY_RERAISE as WHY_EXCEPTION */ /* For the rest, treat WHY_RERAISE as WHY_EXCEPTION */
if (why == WHY_RERAISE) if (why == WHY_RERAISE)
why = WHY_EXCEPTION; why = WHY_EXCEPTION;
/* Unwind stacks if a (pseudo) exception occurred */ /* Unwind stacks if a (pseudo) exception occurred */
while (why != WHY_NOT && f->f_iblock > 0) { while (why != WHY_NOT && f->f_iblock > 0) {
PyTryBlock *b = PyFrame_BlockPop(f); PyTryBlock *b = PyFrame_BlockPop(f);
while (STACK_LEVEL() > b->b_level) { while (STACK_LEVEL() > b->b_level) {
@ -2077,22 +2081,22 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
} /* unwind stack */ } /* unwind stack */
/* End the loop if we still have an error (or return) */ /* End the loop if we still have an error (or return) */
if (why != WHY_NOT) if (why != WHY_NOT)
break; break;
} /* main loop */ } /* main loop */
/* Pop remaining stack entries */ /* Pop remaining stack entries */
while (!EMPTY()) { while (!EMPTY()) {
v = POP(); v = POP();
Py_XDECREF(v); Py_XDECREF(v);
} }
if (why != WHY_RETURN) if (why != WHY_RETURN)
retval = NULL; retval = NULL;
if (f->f_trace) { if (f->f_trace) {
if (why == WHY_RETURN) { if (why == WHY_RETURN) {
if (call_trace(&f->f_trace, &f->f_trace, f, if (call_trace(&f->f_trace, &f->f_trace, f,
@ -2103,7 +2107,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
} }
} }
} }
if (tstate->sys_profilefunc && why == WHY_RETURN) { if (tstate->sys_profilefunc && why == WHY_RETURN) {
if (call_trace(&tstate->sys_profilefunc, (PyObject**)0, if (call_trace(&tstate->sys_profilefunc, (PyObject**)0,
f, "return", retval)) { f, "return", retval)) {
@ -2118,17 +2122,18 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
--tstate->recursion_depth; --tstate->recursion_depth;
fail: /* Jump here from prelude on failure */ fail: /* Jump here from prelude on failure */
/* Restore previous frame and release the current one */ /* Restore previous frame and release the current one */
tstate->frame = f->f_back; tstate->frame = f->f_back;
Py_DECREF(f); Py_DECREF(f);
return retval; return retval;
} }
static void static void
set_exc_info(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) set_exc_info(PyThreadState *tstate,
PyObject *type, PyObject *value, PyObject *tb)
{ {
PyFrameObject *frame; PyFrameObject *frame;
PyObject *tmp_type, *tmp_value, *tmp_tb; PyObject *tmp_type, *tmp_value, *tmp_tb;
@ -2224,7 +2229,7 @@ do_raise(PyObject *type, PyObject *value, PyObject *tb)
Py_XINCREF(value); Py_XINCREF(value);
Py_XINCREF(tb); Py_XINCREF(tb);
} }
/* We support the following forms of raise: /* We support the following forms of raise:
raise <class>, <classinstance> raise <class>, <classinstance>
raise <class>, <argument tuple> raise <class>, <argument tuple>
@ -2315,7 +2320,7 @@ unpack_sequence(PyObject *v, int argcnt, PyObject **sp)
{ {
int i; int i;
PyObject *w; PyObject *w;
for (i = 0; i < argcnt; i++) { for (i = 0; i < argcnt; i++) {
if (! (w = PySequence_GetItem(v, i))) { if (! (w = PySequence_GetItem(v, i))) {
if (PyErr_ExceptionMatches(PyExc_IndexError)) if (PyErr_ExceptionMatches(PyExc_IndexError))
@ -2396,7 +2401,7 @@ call_trace(PyObject **p_trace, PyObject **p_newtrace, PyFrameObject *f,
PyThreadState *tstate = f->f_tstate; PyThreadState *tstate = f->f_tstate;
PyObject *args, *what; PyObject *args, *what;
PyObject *res = NULL; PyObject *res = NULL;
if (tstate->tracing) { if (tstate->tracing) {
/* Don't do recursive traces */ /* Don't do recursive traces */
if (p_newtrace) { if (p_newtrace) {
@ -2405,7 +2410,7 @@ call_trace(PyObject **p_trace, PyObject **p_newtrace, PyFrameObject *f,
} }
return 0; return 0;
} }
args = PyTuple_New(3); args = PyTuple_New(3);
if (args == NULL) if (args == NULL)
goto cleanup; goto cleanup;
@ -2598,7 +2603,7 @@ call_object(PyObject *func, PyObject *arg, PyObject *kw)
if (result == NULL && !PyErr_Occurred()) if (result == NULL && !PyErr_Occurred())
PyErr_SetString(PyExc_SystemError, PyErr_SetString(PyExc_SystemError,
"NULL result without error in call_object"); "NULL result without error in call_object");
return result; return result;
} }
@ -2726,7 +2731,7 @@ call_eval_code2(PyObject *func, PyObject *arg, PyObject *kw)
d = NULL; d = NULL;
nd = 0; nd = 0;
} }
if (kw != NULL) { if (kw != NULL) {
int pos, i; int pos, i;
nk = PyDict_Size(kw); nk = PyDict_Size(kw);
@ -2746,17 +2751,17 @@ call_eval_code2(PyObject *func, PyObject *arg, PyObject *kw)
k = NULL; k = NULL;
nk = 0; nk = 0;
} }
result = eval_code2( result = eval_code2(
(PyCodeObject *)PyFunction_GET_CODE(func), (PyCodeObject *)PyFunction_GET_CODE(func),
PyFunction_GET_GLOBALS(func), (PyObject *)NULL, PyFunction_GET_GLOBALS(func), (PyObject *)NULL,
&PyTuple_GET_ITEM(arg, 0), PyTuple_Size(arg), &PyTuple_GET_ITEM(arg, 0), PyTuple_Size(arg),
k, nk, k, nk,
d, nd); d, nd);
if (k != NULL) if (k != NULL)
PyMem_DEL(k); PyMem_DEL(k);
return result; return result;
} }
@ -2778,7 +2783,7 @@ fast_cfunction(PyObject *func, PyObject ***pp_stack, int na)
return (*meth)(self, NULL); return (*meth)(self, NULL);
else if (na == 1) { else if (na == 1) {
PyObject *arg = EXT_POP(*pp_stack); PyObject *arg = EXT_POP(*pp_stack);
PyObject *result = (*meth)(self, arg); PyObject *result = (*meth)(self, arg);
Py_DECREF(arg); Py_DECREF(arg);
return result; return result;
} else { } else {
@ -2790,7 +2795,7 @@ fast_cfunction(PyObject *func, PyObject ***pp_stack, int na)
} }
static PyObject * static PyObject *
fast_function(PyObject *func, PyObject ***pp_stack, int n, int na, int nk) fast_function(PyObject *func, PyObject ***pp_stack, int n, int na, int nk)
{ {
PyObject *co = PyFunction_GET_CODE(func); PyObject *co = PyFunction_GET_CODE(func);
PyObject *globals = PyFunction_GET_GLOBALS(func); PyObject *globals = PyFunction_GET_GLOBALS(func);
@ -2802,7 +2807,7 @@ fast_function(PyObject *func, PyObject ***pp_stack, int n, int na, int nk)
d = &PyTuple_GET_ITEM(argdefs, 0); d = &PyTuple_GET_ITEM(argdefs, 0);
nd = ((PyTupleObject *)argdefs)->ob_size; nd = ((PyTupleObject *)argdefs)->ob_size;
} }
return eval_code2((PyCodeObject *)co, globals, return eval_code2((PyCodeObject *)co, globals,
(PyObject *)NULL, (*pp_stack)-n, na, (PyObject *)NULL, (*pp_stack)-n, na,
(*pp_stack)-2*nk, nk, d, nd); (*pp_stack)-2*nk, nk, d, nd);
} }
@ -2826,7 +2831,7 @@ update_keyword_args(PyObject *orig_kwdict, int nk, PyObject ***pp_stack,
PyObject *key = EXT_POP(*pp_stack); PyObject *key = EXT_POP(*pp_stack);
if (PyDict_GetItem(kwdict, key) != NULL) { if (PyDict_GetItem(kwdict, key) != NULL) {
PyObject* fn = ((PyFunctionObject*) func)->func_name; PyObject* fn = ((PyFunctionObject*) func)->func_name;
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"%.200s%s got multiple values " "%.200s%s got multiple values "
"for keyword argument '%.400s'", "for keyword argument '%.400s'",
fn ? PyString_AsString(fn) : "function", fn ? PyString_AsString(fn) : "function",
@ -3002,32 +3007,37 @@ _PyEval_SliceIndex(PyObject *v, int *pi)
x = PyLong_AsLong(v); x = PyLong_AsLong(v);
if (x==-1 && PyErr_Occurred()) { if (x==-1 && PyErr_Occurred()) {
PyObject *long_zero; PyObject *long_zero;
int cmp;
if (!PyErr_ExceptionMatches( PyExc_OverflowError ) ) { if (!PyErr_ExceptionMatches(
/* It's not an overflow error, so just PyExc_OverflowError)) {
/* It's not an overflow error, so just
signal an error */ signal an error */
return 0; return 0;
} }
/* It's an overflow error, so we need to /* Clear the OverflowError */
check the sign of the long integer, PyErr_Clear();
set the value to INT_MAX or 0, and clear
/* It's an overflow error, so we need to
check the sign of the long integer,
set the value to INT_MAX or 0, and clear
the error. */ the error. */
/* Create a long integer with a value of 0 */ /* Create a long integer with a value of 0 */
long_zero = PyLong_FromLong( 0L ); long_zero = PyLong_FromLong(0L);
if (long_zero == NULL) return 0; if (long_zero == NULL) return 0;
/* Check sign */ /* Check sign */
if (PyObject_Compare(long_zero, v) < 0) cmp = PyObject_RichCompareBool(v, long_zero,
Py_GT);
Py_DECREF(long_zero);
if (cmp < 0)
return 0;
else if (cmp > 0)
x = INT_MAX; x = INT_MAX;
else else
x = 0; x = 0;
/* Free the long integer we created, and clear the
OverflowError */
Py_DECREF(long_zero);
PyErr_Clear();
} }
} else { } else {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
@ -3056,7 +3066,8 @@ apply_slice(PyObject *u, PyObject *v, PyObject *w) /* return u[v:w] */
} }
static int static int
assign_slice(PyObject *u, PyObject *v, PyObject *w, PyObject *x) /* u[v:w] = x */ assign_slice(PyObject *u, PyObject *v, PyObject *w, PyObject *x)
/* u[v:w] = x */
{ {
int ilow = 0, ihigh = INT_MAX; int ilow = 0, ihigh = INT_MAX;
if (!_PyEval_SliceIndex(v, &ilow)) if (!_PyEval_SliceIndex(v, &ilow))
@ -3072,8 +3083,7 @@ assign_slice(PyObject *u, PyObject *v, PyObject *w, PyObject *x) /* u[v:w] = x *
static PyObject * static PyObject *
cmp_outcome(int op, register PyObject *v, register PyObject *w) cmp_outcome(int op, register PyObject *v, register PyObject *w)
{ {
register int cmp; int res = 0;
register int res = 0;
switch (op) { switch (op) {
case IS: case IS:
case IS_NOT: case IS_NOT:
@ -3093,18 +3103,7 @@ cmp_outcome(int op, register PyObject *v, register PyObject *w)
res = PyErr_GivenExceptionMatches(v, w); res = PyErr_GivenExceptionMatches(v, w);
break; break;
default: default:
cmp = PyObject_Compare(v, w); return PyObject_RichCompare(v, w, op);
if (cmp && PyErr_Occurred())
return NULL;
switch (op) {
case LT: res = cmp < 0; break;
case LE: res = cmp <= 0; break;
case EQ: res = cmp == 0; break;
case NE: res = cmp != 0; break;
case GT: res = cmp > 0; break;
case GE: res = cmp >= 0; break;
/* XXX no default? (res is initialized to 0 though) */
}
} }
v = res ? Py_True : Py_False; v = res ? Py_True : Py_False;
Py_INCREF(v); Py_INCREF(v);
@ -3124,7 +3123,7 @@ import_from(PyObject *v, PyObject *name)
} }
return x; return x;
} }
static int static int
import_all_from(PyObject *locals, PyObject *v) import_all_from(PyObject *locals, PyObject *v)
{ {
@ -3274,7 +3273,7 @@ exec_statement(PyFrameObject *f, PyObject *prog, PyObject *globals,
!PyCode_Check(prog) && !PyCode_Check(prog) &&
!PyFile_Check(prog)) { !PyFile_Check(prog)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"exec: arg 1 must be a string, file, or code object"); "exec: arg 1 must be a string, file, or code object");
return -1; return -1;
} }
if (!PyDict_Check(globals)) { if (!PyDict_Check(globals)) {
@ -3311,7 +3310,7 @@ exec_statement(PyFrameObject *f, PyObject *prog, PyObject *globals,
return 0; return 0;
} }
static void static void
format_exc_check_arg(PyObject *exc, char *format_str, PyObject *obj) format_exc_check_arg(PyObject *exc, char *format_str, PyObject *obj)
{ {
char *obj_str; char *obj_str;