mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
Issue #24489: ensure a previously set C errno doesn't disturb cmath.polar().
This commit is contained in:
parent
03863d2b29
commit
6bc217dd3d
4 changed files with 58 additions and 11 deletions
|
|
@ -1783,6 +1783,18 @@ 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 PyObject *
|
||||
test_set_exc_info(PyObject *self, PyObject *args)
|
||||
{
|
||||
|
|
@ -3208,6 +3220,7 @@ pymarshal_read_object_from_file(PyObject* self, PyObject *args)
|
|||
static PyMethodDef TestMethods[] = {
|
||||
{"raise_exception", raise_exception, METH_VARARGS},
|
||||
{"raise_memoryerror", (PyCFunction)raise_memoryerror, METH_NOARGS},
|
||||
{"set_errno", set_errno, METH_VARARGS},
|
||||
{"test_config", (PyCFunction)test_config, METH_NOARGS},
|
||||
{"test_sizeof_c_types", (PyCFunction)test_sizeof_c_types, METH_NOARGS},
|
||||
{"test_datetime_capi", test_datetime_capi, METH_NOARGS},
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue