[ZODB-Dev] ExtensionClass tp_compare fix

Tim Peters tim at zope.com
Fri Aug 15 15:49:17 EDT 2003


[Neil Schemenauer]
> The attached patch to ExtensionClass.c is necessary to prevent a
> RuntimeWarning from Python 2.3 when comparing to ExtensionClass
> instances.
>
>   Neil
>
>
> --- ExtensionClass.c~	2003-07-30 17:36:05.000000000 -0400
> +++ ExtensionClass.c	2003-07-30 17:41:24.000000000 -0400 @@ -2298,8
> +2298,10 @@
>
>    UNLESS(m=subclass_getspecial(self,py__cmp__))
>      {
> +      Py_uintptr_t iself = (Py_uintptr_t)self;
> +      Py_uintptr_t iv = (Py_uintptr_t)v;
>        PyErr_Clear();
> -      return self-v;
> +      return (iself < iv) ? -1 : (iself > iv) ? 1 : 0;      }
>
>    if (UnboundCMethod_Check(m)

Thanks for the report, Neil!  This is fixed in ZODB3-3_1-branch,
ZODB3-3_2-branch, and ZODB3 HEAD now.  Since Python.h in Python 2.1 didn't
define Py_uintptr_t, I fixed it in a different way.

Note that there was a worse problem here:  casting a pointer difference to
int (the cast is implicit here because of the function's return type) loses
the most important bit of info on 64-bit boxes.  So comparison results on
fat boxes could be inconsistent among a set of objects, provided the objects
lived "far enough apart" in memory.  That would be a miserably rare bug to
track down!




More information about the ZODB-Dev mailing list