[Patches] [Patch #101277] Catch errors raised by comparisons during dictionary lookup.

noreply@sourceforge.net noreply@sourceforge.net
Thu, 24 Aug 2000 10:01:34 -0700


Patch #101277 has been updated. 

Project: 
Category: core (C code)
Status: Open
Summary: Catch errors raised by comparisons during dictionary lookup.

Follow-Ups:

Date: 2000-Aug-24 15:44
By: fdrake

Comment:
THIS PATCH IS NOT READY!

This attempts to fix the bug described in SourceForge bug #112558.

In attempting to catch and ignore errors raised by PyObject_Compare(), it checks for those errors, and, if found, clears them and continues to search for another entry.  

Unfortunately, this doesn't quite work.  It fixes the specific case presented in the bug report, but causes other cases to fail.  Running the regression tests for compile, getopt, sre, strftime, and tokenize all fail when PyEval_CallObjectWithKeywords() or eval_code2() detect an error return without an exception being set.

Is should note that errors are detected in these cases when PyObject_Compare() is returning 0; I'm not actually seeing any cases where the comparison is returning non-zero other than the test case in the bug report.

I'd really appreciate some help on this one!
-------------------------------------------------------

Date: 2000-Aug-24 16:00
By: gvanrossum

Comment:
Fine, except that there are two fprintf statements that should be taken out!
After that, check it in and close it, presuming "make test" succeeds.
(I would hope that you have tried this before submitting.)
-------------------------------------------------------

Date: 2000-Aug-24 16:33
By: fdrake

Comment:
(Yes, I knew about the fprintf()s; I figured that's fine as long as the patch was in a testing phase and clearly declared not yet ready.)

Here's a new version of the patch that makes a change to the error detection: it only checks PyErr_Occurred() if PyObject_Compare() returns non-zero.  The regression test passes and the test case in the bug report now does the right thing.

This is based on my vague recollection that the tp_compare function is supposed to return non-zero on errors.  I can't find any documentation about that however.  It would mean that the documentation needs to be updated to state that PyObject_Compare() will return non-zero on errors as well, and code elsewhere that checks for errors after calling PyObject_Compare() may need to be adjusted.

There is a question lurking here:  if an exception is getting set before lookdict() is called or by a comparison returning 0, there's some broken code somewhere else that may need revision.  I'm also led to believe that PyObject_Cmp() may not always report correctly.

So I think this patch is better than no change, but I'm not convinced it's really right.
-------------------------------------------------------

Date: 2000-Aug-24 17:01
By: gvanrossum

Comment:
I don't think this is any better -- it can still call PyErr_Clear when there was a previously existing exception.

Unfortunately you can't use PyObject_Cmp() either, because it does the same thing: just calls PyErr_Occurred().

So the solution is really to use PyErr_Fetch and _Restore...
-------------------------------------------------------

-------------------------------------------------------
For more info, visit:

http://sourceforge.net/patch/?func=detailpatch&patch_id=101277&group_id=5470