diff Python/ast.c @ 53707:13a82a710f19

Issue #5914: Add new C-API function PyOS_string_to_double, to complement PyOS_double_to_string, and deprecate PyOS_ascii_strtod and PyOS_ascii_atof.
author Mark Dickinson <dickinsm@gmail.com>
date Sun, 03 May 2009 20:33:40 +0000
parents 581d8602f3f7
children 287ce30d08b5
line wrap: on
line diff
--- a/Python/ast.c	Sun May 03 19:38:29 2009 +0000
+++ b/Python/ast.c	Sun May 03 20:33:40 2009 +0000
@@ -3162,18 +3162,18 @@
 #ifndef WITHOUT_COMPLEX
     if (imflag) {
         compl.real = 0.;
-        PyFPE_START_PROTECT("atof", return 0)
-            compl.imag = PyOS_ascii_atof(s);
-        PyFPE_END_PROTECT(c)
-            return PyComplex_FromCComplex(compl);
+        compl.imag = PyOS_string_to_double(s, (char **)&end, NULL);
+        if (compl.imag == -1.0 && PyErr_Occurred())
+            return NULL;
+        return PyComplex_FromCComplex(compl);
     }
     else
 #endif
     {
-        PyFPE_START_PROTECT("atof", return 0)
-            dx = PyOS_ascii_atof(s);
-        PyFPE_END_PROTECT(dx)
-            return PyFloat_FromDouble(dx);
+        dx = PyOS_string_to_double(s, NULL, NULL);
+        if (dx == -1.0 && PyErr_Occurred())
+            return NULL;
+        return PyFloat_FromDouble(dx);
     }
 }