]> granicus.if.org Git - python/commitdiff
make_pair(): When comparing the pointers, they must be cast to integer
authorBarry Warsaw <barry@python.org>
Fri, 18 Aug 2000 05:01:19 +0000 (05:01 +0000)
committerBarry Warsaw <barry@python.org>
Fri, 18 Aug 2000 05:01:19 +0000 (05:01 +0000)
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.

Objects/object.c

index 99fea99bc63a0076b70757896b2ebf839cac0b8c..f61a1dda655aa5e09f3ca775af49ed23c8651296 100644 (file)
@@ -371,12 +371,14 @@ static PyObject *
 make_pair(PyObject *v, PyObject *w)
 {
        PyObject *pair;
+       Py_uintptr_t iv = (Py_uintptr_t)v;
+       Py_uintptr_t iw = (Py_uintptr_t)w;
 
        pair = PyTuple_New(2);
        if (pair == NULL) {
                return NULL;
        }
-       if (v <= w) {
+       if (iv <= iw) {
                PyTuple_SET_ITEM(pair, 0, PyLong_FromVoidPtr((void *)v));
                PyTuple_SET_ITEM(pair, 1, PyLong_FromVoidPtr((void *)w));
        } else {
@@ -487,7 +489,9 @@ PyObject_Compare(PyObject *v, PyObject *w)
                return strcmp(vname, wname);
        }
        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++;
        if (_PyCompareState_nesting > NESTING_LIMIT