summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2015-06-23 12:31:11 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2015-06-23 12:31:11 (GMT)
commit0d2fac1fba893a8af7324a698589d7db43114825 (patch)
tree1a60ba6b0245a65ec8f51e5343d3ef8a2875a9fb /Modules
parent9487043453622047ba39abb36f55f4e43bf3e749 (diff)
downloadcpython-0d2fac1fba893a8af7324a698589d7db43114825.zip
cpython-0d2fac1fba893a8af7324a698589d7db43114825.tar.gz
cpython-0d2fac1fba893a8af7324a698589d7db43114825.tar.bz2
Issue #24489: ensure a previously set C errno doesn't disturb cmath.polar().
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testcapimodule.c12
-rw-r--r--Modules/cmathmodule.c3
2 files changed, 14 insertions, 1 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 7ce3b78..5896e48 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -1373,6 +1373,17 @@ raise_exception(PyObject *self, PyObject *args)
return NULL;
}
+static PyObject *
+set_errno(PyObject *self, PyObject *args)
+{
+ int new_errno;
+
+ if (!PyArg_ParseTuple(args, "i:set_errno", &new_errno))
+ return NULL;
+
+ errno = new_errno;
+ Py_RETURN_NONE;
+}
static int test_run_counter = 0;
@@ -2032,6 +2043,7 @@ pymarshal_read_object_from_file(PyObject* self, PyObject *args)
static PyMethodDef TestMethods[] = {
{"raise_exception", raise_exception, METH_VARARGS},
+ {"set_errno", set_errno, METH_VARARGS},
{"test_config", (PyCFunction)test_config, METH_NOARGS},
{"test_datetime_capi", test_datetime_capi, METH_NOARGS},
{"test_list_api", (PyCFunction)test_list_api, METH_NOARGS},
diff --git a/Modules/cmathmodule.c b/Modules/cmathmodule.c
index 26e7aba..a674d41 100644
--- a/Modules/cmathmodule.c
+++ b/Modules/cmathmodule.c
@@ -941,9 +941,10 @@ cmath_polar(PyObject *self, PyObject *args)
double r, phi;
if (!PyArg_ParseTuple(args, "D:polar", &z))
return NULL;
+ errno = 0;
PyFPE_START_PROTECT("polar function", return 0)
phi = c_atan2(z); /* should not cause any exception */
- r = c_abs(z); /* sets errno to ERANGE on overflow; otherwise 0 */
+ r = c_abs(z); /* sets errno to ERANGE on overflow */
PyFPE_END_PROTECT(r)
if (errno != 0)
return math_error();