diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2010-01-03 12:16:06 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2010-01-03 12:16:06 (GMT) |
commit | fbbb9bdeffe964b7ec3d6144faa9c46a307721fe (patch) | |
tree | da8e5df0cb874e9da6e9552ff067270d53d8ded6 /Modules | |
parent | 479def3fc29710ab3d1ec71e6a0b64df33b6f4ec (diff) | |
download | cpython-fbbb9bdeffe964b7ec3d6144faa9c46a307721fe.zip cpython-fbbb9bdeffe964b7ec3d6144faa9c46a307721fe.tar.gz cpython-fbbb9bdeffe964b7ec3d6144faa9c46a307721fe.tar.bz2 |
Merged revisions 77275 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77275 | mark.dickinson | 2010-01-03 12:03:03 +0000 (Sun, 03 Jan 2010) | 1 line
Make use of PyLong_AsLongAndOverflow in math_ldexp.
........
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/mathmodule.c | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index ee479ea..87afdab 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -1251,28 +1251,18 @@ math_ldexp(PyObject *self, PyObject *args) double x, r; PyObject *oexp; long exp; + int overflow; if (! PyArg_ParseTuple(args, "dO:ldexp", &x, &oexp)) return NULL; if (PyLong_Check(oexp)) { /* on overflow, replace exponent with either LONG_MAX or LONG_MIN, depending on the sign. */ - exp = PyLong_AsLong(oexp); - if (exp == -1 && PyErr_Occurred()) { - if (PyErr_ExceptionMatches(PyExc_OverflowError)) { - if (Py_SIZE(oexp) < 0) { - exp = LONG_MIN; - } - else { - exp = LONG_MAX; - } - PyErr_Clear(); - } - else { - /* propagate any unexpected exception */ - return NULL; - } - } + exp = PyLong_AsLongAndOverflow(oexp, &overflow); + if (exp == -1 && PyErr_Occurred()) + return NULL; + if (overflow) + exp = overflow < 0 ? LONG_MIN : LONG_MAX; } else { PyErr_SetString(PyExc_TypeError, |