New file pyfpe.c and exception FloatingPointError.
Surround some f.p. operations with PyFPE macro brackets.
getplatform.o getversion.o graminit.o \
import.o importdl.o \
marshal.o modsupport.o mystrtoul.o \
- pythonrun.o \
+ pyfpe.o pythonrun.o \
sigcheck.o structmember.o sysmodule.o \
traceback.o \
$(LIBOBJS)
memmove.o: memmove.c
modsupport.o: modsupport.c
mystrtoul.o: mystrtoul.c
+pyfpe.o: pyfpe.c
pythonrun.o: pythonrun.c
sigcheck.o: sigcheck.c
strerror.o: strerror.c
object *AttributeError;
object *ConflictError;
object *EOFError;
+object *FloatingPointError;
object *IOError;
object *ImportError;
object *IndexError;
AttributeError = newstdexception("AttributeError");
ConflictError = newstdexception("ConflictError");
EOFError = newstdexception("EOFError");
+ FloatingPointError = newstdexception("FloatingPointError");
IOError = newstdexception("IOError");
ImportError = newstdexception("ImportError");
IndexError = newstdexception("IndexError");
extern double atof PROTO((const char *));
char *end;
long x;
+ double dx;
#ifndef WITHOUT_COMPLEX
Py_complex c;
int imflag;
#ifndef WITHOUT_COMPLEX
if (imflag) {
c.real = 0.;
+ PyFPE_START_PROTECT("atof", return 0)
c.imag = atof(s);
+ PyFPE_END_PROTECT
return newcomplexobject(c);
}
- else
+ else {
#endif
- return newfloatobject(atof(s));
+ PyFPE_START_PROTECT("atof", return 0)
+ dx = atof(s);
+ PyFPE_END_PROTECT
+ return newfloatobject(dx);
+ }
}
static object *
{
extern double atof PROTO((const char *));
char buf[256];
+ double dx;
n = r_byte(p);
if (r_string(buf, (int)n, p) != n) {
err_setstr(EOFError,
return NULL;
}
buf[n] = '\0';
- return newfloatobject(atof(buf));
+ PyFPE_START_PROTECT("atof", return 0)
+ dx = atof(buf);
+ PyFPE_END_PROTECT
+ return newfloatobject(dx);
}
#ifndef WITHOUT_COMPLEX
return NULL;
}
buf[n] = '\0';
+ PyFPE_START_PROTECT("atof", return 0)
c.real = atof(buf);
+ PyFPE_END_PROTECT
n = r_byte(p);
if (r_string(buf, (int)n, p) != n) {
err_setstr(EOFError,
return NULL;
}
buf[n] = '\0';
+ PyFPE_START_PROTECT("atof", return 0)
c.imag = atof(buf);
+ PyFPE_END_PROTECT
return newcomplexobject(c);
}
#endif
--- /dev/null
+#include "config.h"
+#include "pyfpe.h"
+
+/*
+ * The signal handler for SIGFPE is actually declared in an external
+ * module fpectl, or as preferred by the user. These variable
+ * definitions are required in order to compile Python without
+ * getting missing externals, but to actually handle SIGFPE requires
+ * defining a handler and enabling generation of SIGFPE.
+ */
+
+#ifdef WANT_SIGFPE_HANDLER
+jmp_buf PyFPE_jbuf;
+int PyFPE_counter = 0;
+double PyFPE_dummy(void){return(1.0);}
+#endif