]> granicus.if.org Git - python/commitdiff
Changes for Lee Busby's SIGFPE patch set.
authorGuido van Rossum <guido@python.org>
Fri, 14 Feb 1997 22:58:07 +0000 (22:58 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 14 Feb 1997 22:58:07 +0000 (22:58 +0000)
New file pyfpe.c and exception FloatingPointError.
Surround some f.p. operations with PyFPE macro brackets.

Python/Makefile.in
Python/bltinmodule.c
Python/compile.c
Python/marshal.c
Python/pyfpe.c [new file with mode: 0644]

index 5be2532c4d6d9728d05950774324acaa3f0e09ab..e8cc39f355c06a74b9bd14e2447c9c95c6403d40 100644 (file)
@@ -41,7 +41,7 @@ OBJS=         \
                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)
@@ -107,6 +107,7 @@ marshal.o: marshal.c
 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
index d1dc9a5bdaf9103a3e53347a572044f568203295..29e33939b30ddbefb511cd9f7f52ea2ac5abcd5f 100644 (file)
@@ -1621,6 +1621,7 @@ object *AccessError;
 object *AttributeError;
 object *ConflictError;
 object *EOFError;
+object *FloatingPointError;
 object *IOError;
 object *ImportError;
 object *IndexError;
@@ -1654,6 +1655,7 @@ initerrors()
        AttributeError = newstdexception("AttributeError");
        ConflictError = newstdexception("ConflictError");
        EOFError = newstdexception("EOFError");
+       FloatingPointError = newstdexception("FloatingPointError");
        IOError = newstdexception("IOError");
        ImportError = newstdexception("ImportError");
        IndexError = newstdexception("IndexError");
index e06f345358ea6c681fab71f8b0a2d5f526019bba..0ee55195322a8a39492ba4ea4e0522a5fa52cc16 100644 (file)
@@ -782,6 +782,7 @@ parsenumber(co, s)
        extern double atof PROTO((const char *));
        char *end;
        long x;
+       double dx;
 #ifndef WITHOUT_COMPLEX
        Py_complex c;
        int imflag;
@@ -810,12 +811,18 @@ parsenumber(co, s)
 #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 *
index 0ad493a3db687766f2c2b6928d009ad1e9ee3813..f4634f013b5daccff332c86175b7cbefdfc0b918 100644 (file)
@@ -412,6 +412,7 @@ r_object(p)
                {
                        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,
@@ -419,7 +420,10 @@ r_object(p)
                                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
@@ -435,7 +439,9 @@ r_object(p)
                                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,
@@ -443,7 +449,9 @@ r_object(p)
                                return NULL;
                        }
                        buf[n] = '\0';
+                       PyFPE_START_PROTECT("atof", return 0)
                        c.imag = atof(buf);
+                       PyFPE_END_PROTECT
                        return newcomplexobject(c);
                }
 #endif
diff --git a/Python/pyfpe.c b/Python/pyfpe.c
new file mode 100644 (file)
index 0000000..0b38997
--- /dev/null
@@ -0,0 +1,16 @@
+#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