[Python-checkins] r51505 - python/branches/int_unification/Objects/longobject.c
martin.v.loewis
python-checkins at python.org
Wed Aug 23 16:58:10 CEST 2006
Author: martin.v.loewis
Date: Wed Aug 23 16:58:09 2006
New Revision: 51505
Modified:
python/branches/int_unification/Objects/longobject.c
Log:
Invoke nb_int in PyLong_AsLong.
Copy the object (to the base class) in long_int/long_long.
Modified: python/branches/int_unification/Objects/longobject.c
==============================================================================
--- python/branches/int_unification/Objects/longobject.c (original)
+++ python/branches/int_unification/Objects/longobject.c Wed Aug 23 16:58:09 2006
@@ -204,11 +204,32 @@
unsigned long x, prev;
Py_ssize_t i;
int sign;
+ int do_decref = 0; /* if nb_int was called */
- if (vv == NULL || !PyLong_Check(vv)) {
+ if (vv == NULL) {
PyErr_BadInternalCall();
return -1;
}
+
+ if (!PyLong_Check(vv)) {
+ PyNumberMethods *nb;
+ if ((nb = vv->ob_type->tp_as_number) == NULL ||
+ nb->nb_int == NULL) {
+ PyErr_SetString(PyExc_TypeError, "an integer is required");
+ return -1;
+ }
+ vv = (*nb->nb_int) (vv);
+ if (vv == NULL)
+ return -1;
+ do_decref = 1;
+ if (!PyLong_Check(vv)) {
+ Py_DECREF(vv);
+ PyErr_SetString(PyExc_TypeError,
+ "nb_int should return int object");
+ return -1;
+ }
+ }
+
v = (PyLongObject *)vv;
i = v->ob_size;
sign = 1;
@@ -230,9 +251,15 @@
*/
if ((long)x < 0 && (sign > 0 || (x << 1) != 0))
goto overflow;
+ if (do_decref) {
+ Py_DECREF(vv);
+ }
return (long)x * sign;
overflow:
+ if (do_decref) {
+ Py_DECREF(vv);
+ }
PyErr_SetString(PyExc_OverflowError,
"long int too large to convert to long");
return -1;
@@ -3178,8 +3205,7 @@
static PyObject *
long_int(PyObject *v)
{
- Py_INCREF(v);
- return v;
+ return long_long(v);
}
static PyObject *
More information about the Python-checkins
mailing list