summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrent Nelson <trent.nelson@snakebite.org>2008-04-11 23:02:37 (GMT)
committerTrent Nelson <trent.nelson@snakebite.org>2008-04-11 23:02:37 (GMT)
commit7179220b57faca4606430b97847308b34f45f623 (patch)
tree8d50a92a88bb6569baae5fd557adbf80a7509615
parentdd21912cd01f60434cb2e91fabd466d94a630244 (diff)
downloadcpython-7179220b57faca4606430b97847308b34f45f623.zip
cpython-7179220b57faca4606430b97847308b34f45f623.tar.gz
cpython-7179220b57faca4606430b97847308b34f45f623.tar.bz2
Issue 2440: revert r62269 and r62279. These changes were made in an effort to fix test_args2.Signed_TestCase.test_n(), which was failing on Windows x64 on the following line: 'self.failUnlessEqual(99, getargs_n(Long()))'. Although the two commits *did* fix the test on Windows x64, it's become clear that it's the test that's incorrect, and the changes to PyNumber_Index() in particular were not warranted (and actually violate PEP 357). This commit will get us back to where we were at r62268, before I started butchering things.
-rw-r--r--Lib/test/test_getargs2.py5
-rw-r--r--Objects/abstract.c16
-rw-r--r--Python/getargs.c6
3 files changed, 6 insertions, 21 deletions
diff --git a/Lib/test/test_getargs2.py b/Lib/test/test_getargs2.py
index d8f6309..1918386 100644
--- a/Lib/test/test_getargs2.py
+++ b/Lib/test/test_getargs2.py
@@ -63,10 +63,6 @@ class Int:
def __int__(self):
return 99
-class InvalidLongAsString:
- def __int__(self):
- return 'foobar'
-
class Unsigned_TestCase(unittest.TestCase):
def test_b(self):
from _testcapi import getargs_b
@@ -203,7 +199,6 @@ class Signed_TestCase(unittest.TestCase):
self.failUnlessEqual(42, getargs_n(42))
self.assertRaises(OverflowError, getargs_n, VERY_LARGE)
- self.assertRaises(TypeError, getargs_n, InvalidLongAsString())
class LongLong_TestCase(unittest.TestCase):
def test_L(self):
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 684b0b4..dac80d9 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -1220,7 +1220,6 @@ PyNumber_Absolute(PyObject *o)
PyObject *
PyNumber_Index(PyObject *item)
{
- PyNumberMethods *m;
PyObject *result = NULL;
if (item == NULL)
return null_error();
@@ -1228,9 +1227,8 @@ PyNumber_Index(PyObject *item)
Py_INCREF(item);
return item;
}
- m = item->ob_type->tp_as_number;
if (PyIndex_Check(item)) {
- result = m->nb_index(item);
+ result = item->ob_type->tp_as_number->nb_index(item);
if (result && !PyLong_Check(result)) {
PyErr_Format(PyExc_TypeError,
"__index__ returned non-int "
@@ -1240,17 +1238,7 @@ PyNumber_Index(PyObject *item)
return NULL;
}
}
- else if (m && m->nb_int != NULL && m->nb_float == NULL) {
- result = m->nb_int(item);
- if (result && !PyLong_Check(result)) {
- PyErr_Format(PyExc_TypeError,
- "__int__ returned non-int "
- "(type %.200s)",
- result->ob_type->tp_name);
- Py_DECREF(result);
- return NULL;
- }
- } else {
+ else {
PyErr_Format(PyExc_TypeError,
"'%.200s' object cannot be interpreted "
"as an integer", item->ob_type->tp_name);
diff --git a/Python/getargs.c b/Python/getargs.c
index 960c68c..1370e09 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -663,6 +663,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
}
case 'n': /* Py_ssize_t */
+#if SIZEOF_SIZE_T != SIZEOF_LONG
{
PyObject *iobj;
Py_ssize_t *p = va_arg(*p_va, Py_ssize_t *);
@@ -671,13 +672,14 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
return converterr("integer<n>", arg, msgbuf, bufsize);
iobj = PyNumber_Index(arg);
if (iobj != NULL)
- ival = PyLong_AsSsize_t(iobj);
+ ival = PyLong_AsSsize_t(arg);
if (ival == -1 && PyErr_Occurred())
return converterr("integer<n>", arg, msgbuf, bufsize);
*p = ival;
break;
}
-
+#endif
+ /* Fall through from 'n' to 'l' if Py_ssize_t is int */
case 'l': {/* long int */
long *p = va_arg(*p_va, long *);
long ival;