Commit 9d23a4eb authored by Barry Warsaw's avatar Barry Warsaw

make_pair(): When comparing the pointers, they must be cast to integer

types (i.e. Py_uintptr_t, our spelling of C9X's uintptr_t).  ANSI
specifies that pointer compares other than == and != to non-related
structures are undefined.  This quiets an Insure portability warning.
parent 67c1a04b
...@@ -371,12 +371,14 @@ static PyObject * ...@@ -371,12 +371,14 @@ static PyObject *
make_pair(PyObject *v, PyObject *w) make_pair(PyObject *v, PyObject *w)
{ {
PyObject *pair; PyObject *pair;
Py_uintptr_t iv = (Py_uintptr_t)v;
Py_uintptr_t iw = (Py_uintptr_t)w;
pair = PyTuple_New(2); pair = PyTuple_New(2);
if (pair == NULL) { if (pair == NULL) {
return NULL; return NULL;
} }
if (v <= w) { if (iv <= iw) {
PyTuple_SET_ITEM(pair, 0, PyLong_FromVoidPtr((void *)v)); PyTuple_SET_ITEM(pair, 0, PyLong_FromVoidPtr((void *)v));
PyTuple_SET_ITEM(pair, 1, PyLong_FromVoidPtr((void *)w)); PyTuple_SET_ITEM(pair, 1, PyLong_FromVoidPtr((void *)w));
} else { } else {
...@@ -487,7 +489,9 @@ PyObject_Compare(PyObject *v, PyObject *w) ...@@ -487,7 +489,9 @@ PyObject_Compare(PyObject *v, PyObject *w)
return strcmp(vname, wname); return strcmp(vname, wname);
} }
if (vtp->tp_compare == NULL) { if (vtp->tp_compare == NULL) {
return (v < w) ? -1 : 1; Py_uintptr_t iv = (Py_uintptr_t)v;
Py_uintptr_t iw = (Py_uintptr_t)w;
return (iv < iw) ? -1 : 1;
} }
_PyCompareState_nesting++; _PyCompareState_nesting++;
if (_PyCompareState_nesting > NESTING_LIMIT if (_PyCompareState_nesting > NESTING_LIMIT
......
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