Commit 3e5baefe authored by Stefan Behnel's avatar Stefan Behnel

safely handle SIGFPE in optimised float adding code

parent 08474c9f
...@@ -524,8 +524,12 @@ static PyObject* __Pyx_PyInt_{{op}}{{order}}(PyObject *op1, PyObject *op2, long ...@@ -524,8 +524,12 @@ static PyObject* __Pyx_PyInt_{{op}}{{order}}(PyObject *op1, PyObject *op2, long
#endif #endif
if (PyFloat_CheckExact({{pyval}})) { if (PyFloat_CheckExact({{pyval}})) {
double result;
double {{ival}} = PyFloat_AS_DOUBLE({{pyval}}); double {{ival}} = PyFloat_AS_DOUBLE({{pyval}});
return PyFloat_FromDouble(((double)a) {{ '+' if op == 'Add' else '-' }} (double)b); PyFPE_START_PROTECT("{{op.lower()}}", return NULL)
result = ((double)a) {{ '+' if op == 'Add' else '-' }} (double)b;
PyFPE_END_PROTECT(result)
return PyFloat_FromDouble(result);
} }
return (inplace ? PyNumber_InPlace{{op}} : PyNumber_{{op}})(op1, op2); return (inplace ? PyNumber_InPlace{{op}} : PyNumber_{{op}})(op1, op2);
} }
...@@ -548,7 +552,7 @@ static PyObject* __Pyx_PyFloat_{{op}}{{order}}(PyObject *op1, PyObject *op2, dou ...@@ -548,7 +552,7 @@ static PyObject* __Pyx_PyFloat_{{op}}{{order}}(PyObject *op1, PyObject *op2, dou
static PyObject* __Pyx_PyFloat_{{op}}{{order}}(PyObject *op1, PyObject *op2, double floatval, int inplace) { static PyObject* __Pyx_PyFloat_{{op}}{{order}}(PyObject *op1, PyObject *op2, double floatval, int inplace) {
const double {{'a' if order == 'CObj' else 'b'}} = floatval; const double {{'a' if order == 'CObj' else 'b'}} = floatval;
double {{fval}}; double result, {{fval}};
if (likely(PyFloat_CheckExact({{pyval}}))) { if (likely(PyFloat_CheckExact({{pyval}}))) {
{{fval}} = PyFloat_AS_DOUBLE({{pyval}}); {{fval}} = PyFloat_AS_DOUBLE({{pyval}});
...@@ -576,6 +580,10 @@ static PyObject* __Pyx_PyFloat_{{op}}{{order}}(PyObject *op1, PyObject *op2, dou ...@@ -576,6 +580,10 @@ static PyObject* __Pyx_PyFloat_{{op}}{{order}}(PyObject *op1, PyObject *op2, dou
#endif #endif
} else } else
return (inplace ? PyNumber_InPlace{{op}} : PyNumber_{{op}})(op1, op2); return (inplace ? PyNumber_InPlace{{op}} : PyNumber_{{op}})(op1, op2);
return PyFloat_FromDouble(a {{ '+' if op == 'Add' else '-' }} b);
PyFPE_START_PROTECT("{{op.lower()}}", return NULL)
result = a {{ '+' if op == 'Add' else '-' }} b;
PyFPE_END_PROTECT(result)
return PyFloat_FromDouble(result);
} }
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment