diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2009-12-21 12:37:06 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2009-12-21 12:37:06 (GMT) |
commit | 309aa2dcb488074161c86257d4ddfe104d1ec53a (patch) | |
tree | 50fea960f2f61c80b404fe826b52d1fd9a2fb01e /Objects/longobject.c | |
parent | 6193aeee32e12654b41b4130f59ce1c63aa8afa5 (diff) | |
download | cpython-309aa2dcb488074161c86257d4ddfe104d1ec53a.zip cpython-309aa2dcb488074161c86257d4ddfe104d1ec53a.tar.gz cpython-309aa2dcb488074161c86257d4ddfe104d1ec53a.tar.bz2 |
Keep PyLong_AsLongAndOverflow documentation and implementation in sync
between py3k and trunk; merge new tests from trunk to py3k.
(See issue #7528.)
Diffstat (limited to 'Objects/longobject.c')
-rw-r--r-- | Objects/longobject.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c index b46ce4e..8e4093c 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -346,9 +346,10 @@ PyLong_AsLongAndOverflow(PyObject *vv, int *overflow) 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"); + nb = vv->ob_type->tp_as_number; + if (nb == NULL || nb->nb_int == NULL) { + PyErr_SetString(PyExc_TypeError, + "an integer is required"); return -1; } vv = (*nb->nb_int) (vv); @@ -388,13 +389,13 @@ PyLong_AsLongAndOverflow(PyObject *vv, int *overflow) prev = x; x = (x << PyLong_SHIFT) | v->ob_digit[i]; if ((x >> PyLong_SHIFT) != prev) { - *overflow = Py_SIZE(v) > 0 ? 1 : -1; + *overflow = sign; goto exit; } } - /* Haven't lost any bits, but casting to long requires extra care - * (see comment above). - */ + /* Haven't lost any bits, but casting to long requires extra + * care (see comment above). + */ if (x <= (unsigned long)LONG_MAX) { res = (long)x * sign; } @@ -402,9 +403,9 @@ PyLong_AsLongAndOverflow(PyObject *vv, int *overflow) res = LONG_MIN; } else { - *overflow = Py_SIZE(v) > 0 ? 1 : -1; + *overflow = sign; /* res is already set to -1 */ - } + } } exit: if (do_decref) { |