File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ OBJS= \
4141 getplatform.o getversion.o graminit.o \
4242 import.o importdl.o \
4343 marshal.o modsupport.o mystrtoul.o \
44- pythonrun.o \
44+ pyfpe.o pythonrun.o \
4545 sigcheck.o structmember.o sysmodule.o \
4646 traceback.o \
4747 $(LIBOBJS )
@@ -107,6 +107,7 @@ marshal.o: marshal.c
107107memmove.o : memmove.c
108108modsupport.o : modsupport.c
109109mystrtoul.o : mystrtoul.c
110+ pyfpe.o : pyfpe.c
110111pythonrun.o : pythonrun.c
111112sigcheck.o : sigcheck.c
112113strerror.o : strerror.c
Original file line number Diff line number Diff line change @@ -1621,6 +1621,7 @@ object *AccessError;
16211621object * AttributeError ;
16221622object * ConflictError ;
16231623object * EOFError ;
1624+ object * FloatingPointError ;
16241625object * IOError ;
16251626object * ImportError ;
16261627object * IndexError ;
@@ -1654,6 +1655,7 @@ initerrors()
16541655 AttributeError = newstdexception ("AttributeError" );
16551656 ConflictError = newstdexception ("ConflictError" );
16561657 EOFError = newstdexception ("EOFError" );
1658+ FloatingPointError = newstdexception ("FloatingPointError" );
16571659 IOError = newstdexception ("IOError" );
16581660 ImportError = newstdexception ("ImportError" );
16591661 IndexError = newstdexception ("IndexError" );
Original file line number Diff line number Diff line change @@ -782,6 +782,7 @@ parsenumber(co, s)
782782 extern double atof PROTO ((const char * ) );
783783 char * end ;
784784 long x ;
785+ double dx ;
785786#ifndef WITHOUT_COMPLEX
786787 Py_complex c ;
787788 int imflag ;
@@ -810,12 +811,18 @@ parsenumber(co, s)
810811#ifndef WITHOUT_COMPLEX
811812 if (imflag ) {
812813 c .real = 0. ;
814+ PyFPE_START_PROTECT ("atof" , return 0 )
813815 c .imag = atof (s );
816+ PyFPE_END_PROTECT
814817 return newcomplexobject (c );
815818 }
816- else
819+ else {
817820#endif
818- return newfloatobject (atof (s ));
821+ PyFPE_START_PROTECT ("atof" , return 0 )
822+ dx = atof (s );
823+ PyFPE_END_PROTECT
824+ return newfloatobject (dx );
825+ }
819826}
820827
821828static object *
Original file line number Diff line number Diff line change @@ -412,14 +412,18 @@ r_object(p)
412412 {
413413 extern double atof PROTO ((const char * ) );
414414 char buf [256 ];
415+ double dx ;
415416 n = r_byte (p );
416417 if (r_string (buf , (int )n , p ) != n ) {
417418 err_setstr (EOFError ,
418419 "EOF read where object expected" );
419420 return NULL ;
420421 }
421422 buf [n ] = '\0' ;
422- return newfloatobject (atof (buf ));
423+ PyFPE_START_PROTECT ("atof" , return 0 )
424+ dx = atof (buf );
425+ PyFPE_END_PROTECT
426+ return newfloatobject (dx );
423427 }
424428
425429#ifndef WITHOUT_COMPLEX
@@ -435,15 +439,19 @@ r_object(p)
435439 return NULL ;
436440 }
437441 buf [n ] = '\0' ;
442+ PyFPE_START_PROTECT ("atof" , return 0 )
438443 c .real = atof (buf );
444+ PyFPE_END_PROTECT
439445 n = r_byte (p );
440446 if (r_string (buf , (int )n , p ) != n ) {
441447 err_setstr (EOFError ,
442448 "EOF read where object expected" );
443449 return NULL ;
444450 }
445451 buf [n ] = '\0' ;
452+ PyFPE_START_PROTECT ("atof" , return 0 )
446453 c .imag = atof (buf );
454+ PyFPE_END_PROTECT
447455 return newcomplexobject (c );
448456 }
449457#endif
Original file line number Diff line number Diff line change 1+ #include "config.h"
2+ #include "pyfpe.h"
3+
4+ /*
5+ * The signal handler for SIGFPE is actually declared in an external
6+ * module fpectl, or as preferred by the user. These variable
7+ * definitions are required in order to compile Python without
8+ * getting missing externals, but to actually handle SIGFPE requires
9+ * defining a handler and enabling generation of SIGFPE.
10+ */
11+
12+ #ifdef WANT_SIGFPE_HANDLER
13+ jmp_buf PyFPE_jbuf ;
14+ int PyFPE_counter = 0 ;
15+ double PyFPE_dummy (void ){return (1.0 );}
16+ #endif
You can’t perform that action at this time.
0 commit comments