summaryrefslogtreecommitdiff
path: root/Modules/mathmodule.c
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-01-03 12:03:03 +0000
committerMark Dickinson <dickinsm@gmail.com>2010-01-03 12:03:03 +0000
commit74e7822fa9112bf476b685c6a84f54b080b2d7b9 (patch)
tree7ada94aa334452b92ca00a84de9405ec5d0aad58 /Modules/mathmodule.c
parentd0c6c8bd7bea7e254cf6c526b5201ccd58f8ac0e (diff)
downloadcpython-74e7822fa9112bf476b685c6a84f54b080b2d7b9.tar.gz
Make use of PyLong_AsLongAndOverflow in math_ldexp.
Diffstat (limited to 'Modules/mathmodule.c')
-rw-r--r--Modules/mathmodule.c27
1 files changed, 7 insertions, 20 deletions
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index 849f7f0f01..2dd7a66032 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -1175,31 +1175,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)) {
+ if (PyLong_Check(oexp) || PyInt_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;
- }
- }
- }
- else if (PyInt_Check(oexp)) {
- exp = PyInt_AS_LONG(oexp);
+ 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,