[Python-checkins] r77276 - in python/branches/py3k: Modules/mathmodule.c

mark.dickinson python-checkins at python.org
Sun Jan 3 13:16:06 CET 2010


Author: mark.dickinson
Date: Sun Jan  3 13:16:06 2010
New Revision: 77276

Log:
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.
........


Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Modules/mathmodule.c

Modified: python/branches/py3k/Modules/mathmodule.c
==============================================================================
--- python/branches/py3k/Modules/mathmodule.c	(original)
+++ python/branches/py3k/Modules/mathmodule.c	Sun Jan  3 13:16:06 2010
@@ -1251,28 +1251,18 @@
 	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,


More information about the Python-checkins mailing list