This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tromey
Recipients tromey
Date 2012-07-31.19:59:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1343764780.71.0.604975878578.issue15516@psf.upfronthosting.co.za>
In-reply-to
Content
In gdb we supply a class whose nb_int method can throw
an exception.

A user wrote code like this:

    return '%x' % value

... where "value" was an instance of this class.
This caused funny exception behavior later on.
You can see the original report here:

http://sourceware.org/bugzilla/show_bug.cgi?id=14320

I tracked down the odd behavior to this code in
stringobject.c:PyString_Format:

                        iobj = PyNumber_Int(v);
                        if (iobj==NULL) iobj = PyNumber_Long(v);

Here, PyNumber_Int fails and sets the exception.
I think this ought to be cleared before calling
PyNumber_Long.  In our case, PyNumber_Long succeeds,
and the program keeps executing until something happens
to call PyErr_Occurred.

I think this patch ought to fix the problem:

diff -r e0eb7dea245f Objects/stringobject.c
--- a/Objects/stringobject.c	Mon Jul 30 04:07:49 2012 -0700
+++ b/Objects/stringobject.c	Tue Jul 31 13:58:07 2012 -0600
@@ -4489,7 +4489,10 @@
                     }
                     else {
                         iobj = PyNumber_Int(v);
-                        if (iobj==NULL) iobj = PyNumber_Long(v);
+                        if (iobj==NULL) {
+			    PyErr_Clear();
+			    iobj = PyNumber_Long(v);
+			}
                     }
                     if (iobj!=NULL) {
                         if (PyInt_Check(iobj)) {

I haven't written a test case yet; David Malcolm suggested I file
a bug here first.
History
Date User Action Args
2012-07-31 19:59:40tromeysetrecipients: + tromey
2012-07-31 19:59:40tromeysetmessageid: <1343764780.71.0.604975878578.issue15516@psf.upfronthosting.co.za>
2012-07-31 19:59:39tromeylinkissue15516 messages
2012-07-31 19:59:36tromeycreate