[Zope-Coders] Re: BTrees, Unicode, and Python 2.2

Guido van Rossum guido@python.org
Thu, 18 Oct 2001 13:50:31 -0400


> I tracked the problem down to the TEST_KEY macro in
> BucketTemplace.c/bucket_get().
> TEST_KEY is only a macro for PyObject_Compare(). Putting
> PyObject_Compare inside a wrapper function shows me that it returns
> -1 (instead of 0) when trying to compare
> u'dreit\xe4gigen' with u'dreit\xe4gigen'.

To the author of BucketTemplate.c: PyObject_Compare() can return an
exception since, oh, Python 1.4 at least, but the code in
BucketTemplate.c doesn't check for an error.  This is what causes
Andreas's problem.  I would suggest a specific fix except I don't
understand the code well enough.  The pattern is easy though: if
PyObject_Compare() returns a negative value, use PyErr_Occurred() to
check if an exception happened, and if so, do whatever you do on an
error (cleanup and return NULL, usually).

--Guido van Rossum (home page: http://www.python.org/~guido/)