diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2005-03-03 12:26:20 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2005-03-03 12:26:20 (GMT) |
commit | 77c8402c97092b5520ac13ad4ffa4417a08a8db9 (patch) | |
tree | 488524c4d07c4ac0b4b1c1db7e17984504502d6c /Objects | |
parent | 86509d1ba61ae0d3739abef79ba97eeeeab8fd1b (diff) | |
download | cpython-77c8402c97092b5520ac13ad4ffa4417a08a8db9.zip cpython-77c8402c97092b5520ac13ad4ffa4417a08a8db9.tar.gz cpython-77c8402c97092b5520ac13ad4ffa4417a08a8db9.tar.bz2 |
Revert previous checkin on getargs 'L' code. Try to convert all
numbers in PyLong_AsLongLong, and update test suite accordingly.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/longobject.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c index 0ee9a69..11a7024 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -783,9 +783,30 @@ PyLong_AsLongLong(PyObject *vv) return -1; } if (!PyLong_Check(vv)) { + PyNumberMethods *nb; + PyObject *io; if (PyInt_Check(vv)) return (PY_LONG_LONG)PyInt_AsLong(vv); - PyErr_BadInternalCall(); + if ((nb = vv->ob_type->tp_as_number) == NULL || + nb->nb_int == NULL) { + PyErr_SetString(PyExc_TypeError, "an integer is required"); + return -1; + } + io = (*nb->nb_int) (vv); + if (io == NULL) + return -1; + if (PyInt_Check(io)) { + bytes = PyInt_AsLong(io); + Py_DECREF(io); + return bytes; + } + if (PyLong_Check(io)) { + bytes = PyLong_AsLongLong(io); + Py_DECREF(io); + return bytes; + } + Py_DECREF(io); + PyErr_SetString(PyExc_TypeError, "integer conversion failed"); return -1; } |