Skip to content

bpo-38835: Don't use PyFPE_START_PROTECT and PyFPE_END_PROTECT #17231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The ``PyFPE_START_PROTECT()`` and ``PyFPE_END_PROTECT()`` macros are empty:
they have been doing nothing for the last year, so stop using them.
2 changes: 0 additions & 2 deletions Modules/_tkinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -2166,11 +2166,9 @@ _tkinter_tkapp_exprdouble_impl(TkappObject *self, const char *s)

CHECK_STRING_LENGTH(s);
CHECK_TCL_APPARTMENT;
PyFPE_START_PROTECT("Tkapp_ExprDouble", return 0)
ENTER_TCL
retval = Tcl_ExprDouble(Tkapp_Interp(self), s, &v);
ENTER_OVERLAP
PyFPE_END_PROTECT(retval)
if (retval == TCL_ERROR)
res = Tkinter_Error(self);
else
Expand Down
47 changes: 16 additions & 31 deletions Modules/clinic/cmathmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 2 additions & 11 deletions Modules/cmathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module cmath
/*[python input]
class Py_complex_protected_converter(Py_complex_converter):
def modify(self):
return 'errno = 0; PyFPE_START_PROTECT("complex function", goto exit);'
return 'errno = 0;'


class Py_complex_protected_return_converter(CReturnConverter):
Expand All @@ -26,7 +26,6 @@ class Py_complex_protected_return_converter(CReturnConverter):
def render(self, function, data):
self.declare(data)
data.return_conversion.append("""
PyFPE_END_PROTECT(_return_value);
if (errno == EDOM) {
PyErr_SetString(PyExc_ValueError, "math domain error");
goto exit;
Expand All @@ -40,7 +39,7 @@ else {
}
""".strip())
[python start generated code]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=345daa075b1028e7]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=8b27adb674c08321]*/

#if (FLT_RADIX != 2 && FLT_RADIX != 16)
#error "Modules/cmathmodule.c expects FLT_RADIX to be 2 or 16"
Expand Down Expand Up @@ -960,7 +959,6 @@ cmath_log_impl(PyObject *module, Py_complex x, PyObject *y_obj)
Py_complex y;

errno = 0;
PyFPE_START_PROTECT("complex function", return 0)
x = c_log(x);
if (y_obj != NULL) {
y = PyComplex_AsCComplex(y_obj);
Expand All @@ -970,7 +968,6 @@ cmath_log_impl(PyObject *module, Py_complex x, PyObject *y_obj)
y = c_log(y);
x = _Py_c_quot(x, y);
}
PyFPE_END_PROTECT(x)
if (errno != 0)
return math_error();
return PyComplex_FromCComplex(x);
Expand Down Expand Up @@ -1008,9 +1005,7 @@ cmath_phase_impl(PyObject *module, Py_complex z)
double phi;

errno = 0;
PyFPE_START_PROTECT("arg function", return 0)
phi = c_atan2(z);
PyFPE_END_PROTECT(phi)
if (errno != 0)
return math_error();
else
Expand All @@ -1035,10 +1030,8 @@ cmath_polar_impl(PyObject *module, Py_complex z)
double r, phi;

errno = 0;
PyFPE_START_PROTECT("polar function", return 0)
phi = c_atan2(z); /* should not cause any exception */
r = _Py_c_abs(z); /* sets errno to ERANGE on overflow */
PyFPE_END_PROTECT(r)
if (errno != 0)
return math_error();
else
Expand Down Expand Up @@ -1074,7 +1067,6 @@ cmath_rect_impl(PyObject *module, double r, double phi)
{
Py_complex z;
errno = 0;
PyFPE_START_PROTECT("rect function", return 0)

/* deal with special values */
if (!Py_IS_FINITE(r) || !Py_IS_FINITE(phi)) {
Expand Down Expand Up @@ -1116,7 +1108,6 @@ cmath_rect_impl(PyObject *module, double r, double phi)
errno = 0;
}

PyFPE_END_PROTECT(z)
if (errno != 0)
return math_error();
else
Expand Down
19 changes: 0 additions & 19 deletions Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -936,9 +936,7 @@ math_1_to_whatever(PyObject *arg, double (*func) (double),
if (x == -1.0 && PyErr_Occurred())
return NULL;
errno = 0;
PyFPE_START_PROTECT("in math_1", return 0);
r = (*func)(x);
PyFPE_END_PROTECT(r);
if (Py_IS_NAN(r) && !Py_IS_NAN(x)) {
PyErr_SetString(PyExc_ValueError,
"math domain error"); /* invalid arg */
Expand Down Expand Up @@ -972,9 +970,7 @@ math_1a(PyObject *arg, double (*func) (double))
if (x == -1.0 && PyErr_Occurred())
return NULL;
errno = 0;
PyFPE_START_PROTECT("in math_1a", return 0);
r = (*func)(x);
PyFPE_END_PROTECT(r);
if (errno && is_error(r))
return NULL;
return PyFloat_FromDouble(r);
Expand Down Expand Up @@ -1025,9 +1021,7 @@ math_2(PyObject *const *args, Py_ssize_t nargs,
if ((x == -1.0 || y == -1.0) && PyErr_Occurred())
return NULL;
errno = 0;
PyFPE_START_PROTECT("in math_2", return 0);
r = (*func)(x, y);
PyFPE_END_PROTECT(r);
if (Py_IS_NAN(r)) {
if (!Py_IS_NAN(x) && !Py_IS_NAN(y))
errno = EDOM;
Expand Down Expand Up @@ -1340,8 +1334,6 @@ math_fsum(PyObject *module, PyObject *seq)
if (iter == NULL)
return NULL;

PyFPE_START_PROTECT("fsum", Py_DECREF(iter); return NULL)

for(;;) { /* for x in iterable */
assert(0 <= n && n <= m);
assert((m == NUM_PARTIALS && p == ps) ||
Expand Down Expand Up @@ -1436,7 +1428,6 @@ math_fsum(PyObject *module, PyObject *seq)
sum = PyFloat_FromDouble(hi);

_fsum_error:
PyFPE_END_PROTECT(hi)
Py_DECREF(iter);
if (p != ps)
PyMem_Free(p);
Expand Down Expand Up @@ -2111,9 +2102,7 @@ math_frexp_impl(PyObject *module, double x)
i = 0;
}
else {
PyFPE_START_PROTECT("in math_frexp", return 0);
x = frexp(x, &i);
PyFPE_END_PROTECT(x);
}
return Py_BuildValue("(di)", x, i);
}
Expand Down Expand Up @@ -2168,9 +2157,7 @@ math_ldexp_impl(PyObject *module, double x, PyObject *i)
errno = 0;
} else {
errno = 0;
PyFPE_START_PROTECT("in math_ldexp", return 0);
r = ldexp(x, (int)exp);
PyFPE_END_PROTECT(r);
if (Py_IS_INFINITY(r))
errno = ERANGE;
}
Expand Down Expand Up @@ -2207,9 +2194,7 @@ math_modf_impl(PyObject *module, double x)
}

errno = 0;
PyFPE_START_PROTECT("in math_modf", return 0);
x = modf(x, &y);
PyFPE_END_PROTECT(x);
return Py_BuildValue("(dd)", x, y);
}

Expand Down Expand Up @@ -2356,9 +2341,7 @@ math_fmod_impl(PyObject *module, double x, double y)
if (Py_IS_INFINITY(y) && Py_IS_FINITE(x))
return PyFloat_FromDouble(x);
errno = 0;
PyFPE_START_PROTECT("in math_fmod", return 0);
r = fmod(x, y);
PyFPE_END_PROTECT(r);
if (Py_IS_NAN(r)) {
if (!Py_IS_NAN(x) && !Py_IS_NAN(y))
errno = EDOM;
Expand Down Expand Up @@ -2646,9 +2629,7 @@ math_pow_impl(PyObject *module, double x, double y)
else {
/* let libm handle finite**finite */
errno = 0;
PyFPE_START_PROTECT("in math_pow", return 0);
r = pow(x, y);
PyFPE_END_PROTECT(r);
/* a NaN result should arise only from (-ve)**(finite
non-integer); in this case we want to raise ValueError. */
if (!Py_IS_FINITE(r)) {
Expand Down
Loading