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

Skip to content

Commit f4aca75

Browse files
committed
A static swapped_op[] array was defined in 3 different C files, & I think
I need to define it again. Bite the bullet and define it once as an extern, _Py_SwappedOp[].
1 parent 7790c3b commit f4aca75

4 files changed

Lines changed: 11 additions & 12 deletions

File tree

Include/object.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,11 @@ PyAPI_DATA(PyObject) _Py_NotImplementedStruct; /* Don't use this directly */
667667
#define Py_GT 4
668668
#define Py_GE 5
669669

670+
/* Maps Py_LT to Py_GT, ..., Py_GE to Py_LE.
671+
* Defined in object.c.
672+
*/
673+
PyAPI_DATA(int) _Py_SwappedOp[];
674+
670675
/*
671676
Define staticforward and statichere for source compatibility with old
672677
C extensions.

Objects/classobject.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,9 +1873,6 @@ half_richcompare(PyObject *v, PyObject *w, int op)
18731873
return res;
18741874
}
18751875

1876-
/* Map rich comparison operators to their swapped version, e.g. LT --> GT */
1877-
static int swapped_op[] = {Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE};
1878-
18791876
static PyObject *
18801877
instance_richcompare(PyObject *v, PyObject *w, int op)
18811878
{
@@ -1889,7 +1886,7 @@ instance_richcompare(PyObject *v, PyObject *w, int op)
18891886
}
18901887

18911888
if (PyInstance_Check(w)) {
1892-
res = half_richcompare(w, v, swapped_op[op]);
1889+
res = half_richcompare(w, v, _Py_SwappedOp[op]);
18931890
if (res != Py_NotImplemented)
18941891
return res;
18951892
Py_DECREF(res);

Objects/object.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ adjust_tp_compare(int c)
476476
? (t)->tp_richcompare : NULL)
477477

478478
/* Map rich comparison operators to their swapped version, e.g. LT --> GT */
479-
static int swapped_op[] = {Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE};
479+
extern int _Py_SwappedOp[] = {Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE};
480480

481481
/* Try a genuine rich comparison, returning an object. Return:
482482
NULL for exception;
@@ -494,7 +494,7 @@ try_rich_compare(PyObject *v, PyObject *w, int op)
494494
if (v->ob_type != w->ob_type &&
495495
PyType_IsSubtype(w->ob_type, v->ob_type) &&
496496
(f = RICHCOMPARE(w->ob_type)) != NULL) {
497-
res = (*f)(w, v, swapped_op[op]);
497+
res = (*f)(w, v, _Py_SwappedOp[op]);
498498
if (res != Py_NotImplemented)
499499
return res;
500500
Py_DECREF(res);
@@ -506,7 +506,7 @@ try_rich_compare(PyObject *v, PyObject *w, int op)
506506
Py_DECREF(res);
507507
}
508508
if ((f = RICHCOMPARE(w->ob_type)) != NULL) {
509-
return (*f)(w, v, swapped_op[op]);
509+
return (*f)(w, v, _Py_SwappedOp[op]);
510510
}
511511
res = Py_NotImplemented;
512512
Py_INCREF(res);
@@ -1703,7 +1703,7 @@ PyObject_Dir(PyObject *arg)
17031703

17041704
assert(result);
17051705
if (!PyList_Check(result)) {
1706-
PyErr_SetString(PyExc_TypeError,
1706+
PyErr_SetString(PyExc_TypeError,
17071707
"Expected keys() to be a list.");
17081708
goto error;
17091709
}

Objects/typeobject.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4638,9 +4638,6 @@ half_richcompare(PyObject *self, PyObject *other, int op)
46384638
return res;
46394639
}
46404640

4641-
/* Map rich comparison operators to their swapped version, e.g. LT --> GT */
4642-
static int swapped_op[] = {Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE};
4643-
46444641
static PyObject *
46454642
slot_tp_richcompare(PyObject *self, PyObject *other, int op)
46464643
{
@@ -4653,7 +4650,7 @@ slot_tp_richcompare(PyObject *self, PyObject *other, int op)
46534650
Py_DECREF(res);
46544651
}
46554652
if (other->ob_type->tp_richcompare == slot_tp_richcompare) {
4656-
res = half_richcompare(other, self, swapped_op[op]);
4653+
res = half_richcompare(other, self, _Py_SwappedOp[op]);
46574654
if (res != Py_NotImplemented) {
46584655
return res;
46594656
}

0 commit comments

Comments
 (0)