summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-02-14 22:54:21 (GMT)
committerGuido van Rossum <guido@python.org>1997-02-14 22:54:21 (GMT)
commit09e6ad0c1e1c7b3c6132ab2d5dd85c5cc376721d (patch)
tree14e706bc51e07d8056abfcd70f542c0cb009591b /Objects
parent7d4266ed5a68e4434a86a11eb771abb28d13322e (diff)
downloadcpython-09e6ad0c1e1c7b3c6132ab2d5dd85c5cc376721d.zip
cpython-09e6ad0c1e1c7b3c6132ab2d5dd85c5cc376721d.tar.gz
cpython-09e6ad0c1e1c7b3c6132ab2d5dd85c5cc376721d.tar.bz2
Changes for Lee Busby's SIGFPE patch set.
Surround various f.p. operations with PyFPE_{START,END}_PROTECT macros.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/complexobject.c28
-rw-r--r--Objects/floatobject.c37
-rw-r--r--Objects/longobject.c8
3 files changed, 63 insertions, 10 deletions
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index 14661f1..212fd34 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -364,7 +364,11 @@ complex_add(v, w)
complexobject *v;
complexobject *w;
{
- return newcomplexobject(c_sum(v->cval,w->cval));
+ Py_complex result;
+ PyFPE_START_PROTECT("complex_add", return 0)
+ result = c_sum(v->cval,w->cval);
+ PyFPE_END_PROTECT
+ return newcomplexobject(result);
}
static object *
@@ -372,7 +376,11 @@ complex_sub(v, w)
complexobject *v;
complexobject *w;
{
- return newcomplexobject(c_diff(v->cval,w->cval));
+ Py_complex result;
+ PyFPE_START_PROTECT("complex_sub", return 0)
+ result = c_diff(v->cval,w->cval);
+ PyFPE_END_PROTECT
+ return newcomplexobject(result);
}
static object *
@@ -380,7 +388,11 @@ complex_mul(v, w)
complexobject *v;
complexobject *w;
{
- return newcomplexobject(c_prod(v->cval,w->cval));
+ Py_complex result;
+ PyFPE_START_PROTECT("complex_mul", return 0)
+ result = c_prod(v->cval,w->cval);
+ PyFPE_END_PROTECT
+ return newcomplexobject(result);
}
static object *
@@ -389,8 +401,10 @@ complex_div(v, w)
complexobject *w;
{
Py_complex quot;
+ PyFPE_START_PROTECT("complex_div", return 0)
c_error = 0;
quot = c_quot(v->cval,w->cval);
+ PyFPE_END_PROTECT
if (c_error == 1) {
err_setstr(ZeroDivisionError, "complex division");
return NULL;
@@ -457,6 +471,7 @@ complex_pow(v, w, z)
return NULL;
}
+ PyFPE_START_PROTECT("complex_pow", return 0)
c_error = 0;
exponent = ((complexobject*)w)->cval;
int_exponent = (long)exponent.real;
@@ -465,6 +480,7 @@ complex_pow(v, w, z)
else
p = c_pow(v->cval,exponent);
+ PyFPE_END_PROTECT
if (c_error == 2) {
err_setstr(ValueError, "0.0 to a negative or complex power");
return NULL;
@@ -495,7 +511,11 @@ static object *
complex_abs(v)
complexobject *v;
{
- return newfloatobject(hypot(v->cval.real,v->cval.imag));
+ double result;
+ PyFPE_START_PROTECT("complex_abs", return 0)
+ result = hypot(v->cval.real,v->cval.imag);
+ PyFPE_END_PROTECT
+ return newfloatobject(result);
}
static int
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 1cebf8c..e8d0d68 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -257,7 +257,11 @@ float_add(v, w)
floatobject *v;
floatobject *w;
{
- return newfloatobject(v->ob_fval + w->ob_fval);
+ double result;
+ PyFPE_START_PROTECT("add", return 0)
+ result = v->ob_fval + w->ob_fval;
+ PyFPE_END_PROTECT
+ return newfloatobject(result);
}
static object *
@@ -265,7 +269,11 @@ float_sub(v, w)
floatobject *v;
floatobject *w;
{
- return newfloatobject(v->ob_fval - w->ob_fval);
+ double result;
+ PyFPE_START_PROTECT("subtract", return 0)
+ result = v->ob_fval - w->ob_fval;
+ PyFPE_END_PROTECT
+ return newfloatobject(result);
}
static object *
@@ -273,7 +281,12 @@ float_mul(v, w)
floatobject *v;
floatobject *w;
{
- return newfloatobject(v->ob_fval * w->ob_fval);
+ double result;
+
+ PyFPE_START_PROTECT("multiply", return 0)
+ result = v->ob_fval * w->ob_fval;
+ PyFPE_END_PROTECT
+ return newfloatobject(result);
}
static object *
@@ -281,11 +294,15 @@ float_div(v, w)
floatobject *v;
floatobject *w;
{
+ double result;
if (w->ob_fval == 0) {
err_setstr(ZeroDivisionError, "float division");
return NULL;
}
- return newfloatobject(v->ob_fval / w->ob_fval);
+ PyFPE_START_PROTECT("divide", return 0)
+ result = v->ob_fval / w->ob_fval;
+ PyFPE_END_PROTECT
+ return newfloatobject(result);
}
static object *
@@ -300,6 +317,7 @@ float_rem(v, w)
err_setstr(ZeroDivisionError, "float modulo");
return NULL;
}
+ PyFPE_START_PROTECT("modulo", return 0)
vx = v->ob_fval;
mod = fmod(vx, wx);
/* div = (vx - mod) / wx; */
@@ -307,6 +325,7 @@ float_rem(v, w)
mod += wx;
/* div -= 1.0; */
}
+ PyFPE_END_PROTECT
return newfloatobject(mod);
}
@@ -322,6 +341,7 @@ float_divmod(v, w)
err_setstr(ZeroDivisionError, "float divmod()");
return NULL;
}
+ PyFPE_START_PROTECT("divmod", return 0)
vx = v->ob_fval;
mod = fmod(vx, wx);
div = (vx - mod) / wx;
@@ -329,6 +349,7 @@ float_divmod(v, w)
mod += wx;
div -= 1.0;
}
+ PyFPE_END_PROTECT
return mkvalue("(dd)", div, mod);
}
@@ -367,18 +388,22 @@ float_pow(v, w, z)
if (iw == intw && -10000 < intw && intw < 10000) {
/* Sort out special cases here instead of relying on pow() */
if (intw == 0) { /* x**0 is 1, even 0**0 */
+ PyFPE_START_PROTECT("pow", return 0)
if ((object *)z!=None) {
ix=fmod(1.0, z->ob_fval);
if (ix!=0 && z->ob_fval<0) ix+=z->ob_fval;
}
else ix=1.0;
+ PyFPE_END_PROTECT
return newfloatobject(ix);
}
errno = 0;
+ PyFPE_START_PROTECT("pow", return 0)
if (intw > 0)
ix = powu(iv, intw);
else
ix = 1./powu(iv, -intw);
+ PyFPE_END_PROTECT
}
else {
/* Sort out special cases here instead of relying on pow() */
@@ -396,7 +421,9 @@ float_pow(v, w, z)
return NULL;
}
errno = 0;
+ PyFPE_START_PROTECT("pow", return 0)
ix = pow(iv, iw);
+ PyFPE_END_PROTECT
}
CHECK(ix);
if (errno != 0) {
@@ -405,11 +432,13 @@ float_pow(v, w, z)
return NULL;
}
if ((object *)z!=None) {
+ PyFPE_START_PROTECT("pow", return 0)
ix=fmod(ix, z->ob_fval); /* XXX To Be Rewritten */
if ( ix!=0 &&
((iv<0 && z->ob_fval>0) || (iv>0 && z->ob_fval<0) )) {
ix+=z->ob_fval;
}
+ PyFPE_END_PROTECT
}
return newfloatobject(ix);
}
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 36f2a26..e0255e9 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -237,7 +237,7 @@ PyLong_AsUnsignedLong(vv)
return x;
}
-/* Get a C double from a long int object. No overflow check. */
+/* Get a C double from a long int object. */
double
dgetlongvalue(vv)
@@ -1418,7 +1418,11 @@ static object *
long_float(v)
object *v;
{
- return newfloatobject(dgetlongvalue(v));
+ double result;
+ PyFPE_START_PROTECT("long_float", return 0)
+ result = dgetlongvalue(v);
+ PyFPE_END_PROTECT
+ return newfloatobject(result);
}
static object *