summaryrefslogtreecommitdiffstats
path: root/Objects/classobject.c
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2006-08-12 18:44:06 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2006-08-12 18:44:06 (GMT)
commit1872b1c01f343f4cbfa7696ce95beae8278ce210 (patch)
tree382d8080c87b1484d3449b9108f65b023ccdaef8 /Objects/classobject.c
parent8a87f5d37e6aab91ddc4c6491877b6cbd48a12cf (diff)
downloadcpython-1872b1c01f343f4cbfa7696ce95beae8278ce210.zip
cpython-1872b1c01f343f4cbfa7696ce95beae8278ce210.tar.gz
cpython-1872b1c01f343f4cbfa7696ce95beae8278ce210.tar.bz2
Fix a couple of bugs exposed by the new __index__ code. The 64-bit buildbots
were failing due to inappropriate clipping of numbers larger than 2**31 with new-style classes. (typeobject.c) In reviewing the code for classic classes, there were 2 problems. Any negative value return could be returned. Always return -1 if there was an error. Also make the checks similar with the new-style classes. I believe this is correct for 32 and 64 bit boxes, including Windows64. Add a test of classic classes too.
Diffstat (limited to 'Objects/classobject.c')
-rw-r--r--Objects/classobject.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c
index 1e93908..e8bac91 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -974,24 +974,25 @@ instance_length(PyInstanceObject *inst)
if (res == NULL)
return -1;
if (PyInt_Check(res)) {
- Py_ssize_t temp = PyInt_AsSsize_t(res);
- if (temp == -1 && PyErr_Occurred()) {
+ outcome = PyInt_AsSsize_t(res);
+ if (outcome == -1 && PyErr_Occurred()) {
Py_DECREF(res);
return -1;
}
- outcome = (Py_ssize_t)temp;
-#if SIZEOF_SIZE_T < SIZEOF_LONG
+#if SIZEOF_SIZE_T < SIZEOF_INT
/* Overflow check -- range of PyInt is more than C int */
- if (outcome != temp) {
+ if (outcome != (int)outcome) {
PyErr_SetString(PyExc_OverflowError,
"__len__() should return 0 <= outcome < 2**31");
outcome = -1;
}
else
#endif
- if (outcome < 0)
+ if (outcome < 0) {
PyErr_SetString(PyExc_ValueError,
"__len__() should return >= 0");
+ outcome = -1;
+ }
}
else {
PyErr_SetString(PyExc_TypeError,