Message167043
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. |
|
Date |
User |
Action |
Args |
2012-07-31 19:59:40 | tromey | set | recipients:
+ tromey |
2012-07-31 19:59:40 | tromey | set | messageid: <1343764780.71.0.604975878578.issue15516@psf.upfronthosting.co.za> |
2012-07-31 19:59:39 | tromey | link | issue15516 messages |
2012-07-31 19:59:36 | tromey | create | |
|