FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Changes for Lee Busby's SIGFPE patch set. · python/cpython@0ae748d · GitHub

/ cpython Public

Commit 0ae748d

Browse files
committed
Changes for Lee Busby's SIGFPE patch set.
New file pyfpe.c and exception FloatingPointError. Surround some f.p. operations with PyFPE macro brackets.
1 parent 09e6ad0 commit 0ae748d

5 files changed

Lines changed: 38 additions & 4 deletions

File tree

‎Python/Makefile.in‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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
107107
memmove.o: memmove.c
108108
modsupport.o: modsupport.c
109109
mystrtoul.o: mystrtoul.c
110+
pyfpe.o: pyfpe.c
110111
pythonrun.o: pythonrun.c
111112
sigcheck.o: sigcheck.c
112113
strerror.o: strerror.c

‎Python/bltinmodule.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,6 +1621,7 @@ object *AccessError;
16211621
object *AttributeError;
16221622
object *ConflictError;
16231623
object *EOFError;
1624+
object *FloatingPointError;
16241625
object *IOError;
16251626
object *ImportError;
16261627
object *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");

‎Python/compile.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff 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

821828
static object *

‎Python/marshal.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff 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

‎Python/pyfpe.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL