Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7198a52

Browse files
committed
Patch #494783: Rename cmp_op enumerators.
1 parent 653d85f commit 7198a52

5 files changed

Lines changed: 39 additions & 32 deletions

File tree

Include/opcode.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ extern "C" {
142142
/* Support for opargs more than 16 bits long */
143143
#define EXTENDED_ARG 143
144144

145-
/* Comparison operator codes (argument to COMPARE_OP) */
146-
enum cmp_op {LT=Py_LT, LE=Py_LE, EQ=Py_EQ, NE=Py_NE, GT=Py_GT, GE=Py_GE,
147-
IN, NOT_IN, IS, IS_NOT, EXC_MATCH, BAD};
145+
146+
enum cmp_op {PyCmp_LT=Py_LT, PyCmp_LE=Py_LE, PyCmp_EQ=Py_EQ, PyCmp_NE=Py_NE, PyCmp_GT=Py_GT, PyCmp_GE=Py_GE,
147+
PyCmp_IN, PyCmp_NOT_IN, PyCmp_IS, PyCmp_IS_NOT, PyCmp_EXC_MATCH, PyCmp_BAD};
148148

149149
#define HAS_ARG(op) ((op) >= HAVE_ARGUMENT)
150150

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Tom Christiansen
8585
Vadim Chugunov
8686
David Cinege
8787
Mike Clarkson
88+
Brad Clements
8889
Steve Clift
8990
Josh Cogliati
9091
Dave Cole

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Build
2424

2525
C API
2626

27+
- The enumerators of cmp_op have been renamed to use the prefix PyCmp_.
28+
2729
- An old #define of ANY as void has been removed from pyport.h. This
2830
hasn't been used since Python's pre-ANSI days, and the #define has
2931
been marked as obsolete since then. SF bug 495548 says it created

Python/ceval.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,14 +1785,14 @@ eval_frame(PyFrameObject *f)
17851785
a = PyInt_AS_LONG(v);
17861786
b = PyInt_AS_LONG(w);
17871787
switch (oparg) {
1788-
case LT: res = a < b; break;
1789-
case LE: res = a <= b; break;
1790-
case EQ: res = a == b; break;
1791-
case NE: res = a != b; break;
1792-
case GT: res = a > b; break;
1793-
case GE: res = a >= b; break;
1794-
case IS: res = v == w; break;
1795-
case IS_NOT: res = v != w; break;
1788+
case PyCmp_LT: res = a < b; break;
1789+
case PyCmp_LE: res = a <= b; break;
1790+
case PyCmp_EQ: res = a == b; break;
1791+
case PyCmp_NE: res = a != b; break;
1792+
case PyCmp_GT: res = a > b; break;
1793+
case PyCmp_GE: res = a >= b; break;
1794+
case PyCmp_IS: res = v == w; break;
1795+
case PyCmp_IS_NOT: res = v != w; break;
17961796
default: goto slow_compare;
17971797
}
17981798
x = res ? Py_True : Py_False;
@@ -2986,6 +2986,10 @@ PyEval_MergeCompilerFlags(PyCompilerFlags *cf)
29862986
result = 1;
29872987
cf->cf_flags |= compilerflags;
29882988
}
2989+
if (codeflags & CO_GENERATOR_ALLOWED) {
2990+
result = 1;
2991+
cf->cf_flags |= CO_GENERATOR_ALLOWED;
2992+
}
29892993
}
29902994
return result;
29912995
}
@@ -3470,21 +3474,21 @@ cmp_outcome(int op, register PyObject *v, register PyObject *w)
34703474
{
34713475
int res = 0;
34723476
switch (op) {
3473-
case IS:
3474-
case IS_NOT:
3477+
case PyCmp_IS:
3478+
case PyCmp_IS_NOT:
34753479
res = (v == w);
3476-
if (op == (int) IS_NOT)
3480+
if (op == (int) PyCmp_IS_NOT)
34773481
res = !res;
34783482
break;
3479-
case IN:
3480-
case NOT_IN:
3483+
case PyCmp_IN:
3484+
case PyCmp_NOT_IN:
34813485
res = PySequence_Contains(w, v);
34823486
if (res < 0)
34833487
return NULL;
3484-
if (op == (int) NOT_IN)
3488+
if (op == (int) PyCmp_NOT_IN)
34853489
res = !res;
34863490
break;
3487-
case EXC_MATCH:
3491+
case PyCmp_EXC_MATCH:
34883492
res = PyErr_GivenExceptionMatches(v, w);
34893493
break;
34903494
default:

Python/compile.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ com_addbyte(struct compiling *c, int byte)
702702
{
703703
/*fprintf(stderr, "%3d: %3d\n", c->c_nexti, byte);*/
704704
assert(byte >= 0 && byte <= 255);
705-
assert(c->c_code);
705+
assert(c->c_code != 0);
706706
if (com_check_size(&c->c_code, c->c_nexti)) {
707707
c->c_errors++;
708708
return;
@@ -2138,26 +2138,26 @@ cmp_type(node *n)
21382138
if (NCH(n) == 1) {
21392139
n = CHILD(n, 0);
21402140
switch (TYPE(n)) {
2141-
case LESS: return LT;
2142-
case GREATER: return GT;
2141+
case LESS: return PyCmp_LT;
2142+
case GREATER: return PyCmp_GT;
21432143
case EQEQUAL: /* == */
2144-
case EQUAL: return EQ;
2145-
case LESSEQUAL: return LE;
2146-
case GREATEREQUAL: return GE;
2147-
case NOTEQUAL: return NE; /* <> or != */
2148-
case NAME: if (strcmp(STR(n), "in") == 0) return IN;
2149-
if (strcmp(STR(n), "is") == 0) return IS;
2144+
case EQUAL: return PyCmp_EQ;
2145+
case LESSEQUAL: return PyCmp_LE;
2146+
case GREATEREQUAL: return PyCmp_GE;
2147+
case NOTEQUAL: return PyCmp_NE; /* <> or != */
2148+
case NAME: if (strcmp(STR(n), "in") == 0) return PyCmp_IN;
2149+
if (strcmp(STR(n), "is") == 0) return PyCmp_IS;
21502150
}
21512151
}
21522152
else if (NCH(n) == 2) {
21532153
switch (TYPE(CHILD(n, 0))) {
21542154
case NAME: if (strcmp(STR(CHILD(n, 1)), "in") == 0)
2155-
return NOT_IN;
2155+
return PyCmp_NOT_IN;
21562156
if (strcmp(STR(CHILD(n, 0)), "is") == 0)
2157-
return IS_NOT;
2157+
return PyCmp_IS_NOT;
21582158
}
21592159
}
2160-
return BAD;
2160+
return PyCmp_BAD;
21612161
}
21622162

21632163
static void
@@ -2214,7 +2214,7 @@ com_comparison(struct compiling *c, node *n)
22142214
com_addbyte(c, ROT_THREE);
22152215
}
22162216
op = cmp_type(CHILD(n, i-1));
2217-
if (op == BAD) {
2217+
if (op == PyCmp_BAD) {
22182218
com_error(c, PyExc_SystemError,
22192219
"com_comparison: unknown comparison op");
22202220
}
@@ -3247,7 +3247,7 @@ com_try_except(struct compiling *c, node *n)
32473247
com_addbyte(c, DUP_TOP);
32483248
com_push(c, 1);
32493249
com_node(c, CHILD(ch, 1));
3250-
com_addoparg(c, COMPARE_OP, EXC_MATCH);
3250+
com_addoparg(c, COMPARE_OP, PyCmp_EXC_MATCH);
32513251
com_pop(c, 1);
32523252
com_addfwref(c, JUMP_IF_FALSE, &except_anchor);
32533253
com_addbyte(c, POP_TOP);

0 commit comments

Comments
 (0)