summaryrefslogtreecommitdiff
path: root/Objects/complexobject.c
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2009-05-03 20:33:40 +0000
committerMark Dickinson <dickinsm@gmail.com>2009-05-03 20:33:40 +0000
commit9273205133f7fa6042028967655232d12dc3af73 (patch)
treeeb9e1492ab772670053b453da64d619ee7d15946 /Objects/complexobject.c
parent38f3db02dc2d31cd2959d72aeae966ffb4bc9a07 (diff)
downloadcpython-9273205133f7fa6042028967655232d12dc3af73.tar.gz
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.
Diffstat (limited to 'Objects/complexobject.c')
-rw-r--r--Objects/complexobject.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index 691809f134..4dd6151ef9 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -799,25 +799,26 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v)
*/
/* first look for forms starting with <float> */
- errno = 0;
- z = PyOS_ascii_strtod(s, &end);
- if (end == s && errno == ENOMEM)
- return PyErr_NoMemory();
- if (errno == ERANGE && fabs(z) >= 1.0)
- goto overflow;
-
+ z = PyOS_string_to_double(s, &end, PyExc_OverflowError);
+ if (z == -1.0 && PyErr_Occurred()) {
+ if (PyErr_ExceptionMatches(PyExc_ValueError))
+ PyErr_Clear();
+ else
+ return NULL;
+ }
if (end != s) {
/* all 4 forms starting with <float> land here */
s = end;
if (*s == '+' || *s == '-') {
/* <float><signed-float>j | <float><sign>j */
x = z;
- errno = 0;
- y = PyOS_ascii_strtod(s, &end);
- if (end == s && errno == ENOMEM)
- return PyErr_NoMemory();
- if (errno == ERANGE && fabs(y) >= 1.0)
- goto overflow;
+ y = PyOS_string_to_double(s, &end, PyExc_OverflowError);
+ if (y == -1.0 && PyErr_Occurred()) {
+ if (PyErr_ExceptionMatches(PyExc_ValueError))
+ PyErr_Clear();
+ else
+ return NULL;
+ }
if (end != s)
/* <float><signed-float>j */
s = end;
@@ -877,11 +878,6 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v)
PyErr_SetString(PyExc_ValueError,
"complex() arg is a malformed string");
return NULL;
-
- overflow:
- PyErr_SetString(PyExc_OverflowError,
- "complex() arg overflow");
- return NULL;
}
static PyObject *