[Python-checkins] python/dist/src/Objects classobject.c, 2.178, 2.179
gvanrossum@users.sourceforge.net
gvanrossum at users.sourceforge.net
Tue Sep 20 00:42:46 CEST 2005
Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13311/Objects
Modified Files:
classobject.c
Log Message:
A minor fix for 64-bit platforms: when __len__() returns Python int
containing a value that doesn't fit in a C int, raise OverflowError
rather than truncating silently (and having 50% chance of hitting the
"it should be >= 0" error).
Index: classobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/classobject.c,v
retrieving revision 2.178
retrieving revision 2.179
diff -u -d -r2.178 -r2.179
--- classobject.c 19 Jun 2005 08:42:20 -0000 2.178
+++ classobject.c 19 Sep 2005 22:42:41 -0000 2.179
@@ -1013,7 +1013,17 @@
if (res == NULL)
return -1;
if (PyInt_Check(res)) {
- outcome = PyInt_AsLong(res);
+ long temp = PyInt_AsLong(res);
+ outcome = (int)temp;
+#if SIZEOF_INT < SIZEOF_LONG
+ /* Overflow check -- range of PyInt is more than C int */
+ if (outcome != temp) {
+ PyErr_SetString(PyExc_OverflowError,
+ "__len__() should return 0 <= outcome < 2**32");
+ outcome = -1;
+ }
+ else
+#endif
if (outcome < 0)
PyErr_SetString(PyExc_ValueError,
"__len__() should return >= 0");
More information about the Python-checkins
mailing list