annotate Modules/fpectlmodule.c @ 25838:8540887bcec6 2.2

Backport of 2.183: Fix memory leak in add_subclass() found by NealN with valgrind.
author Guido van Rossum <guido@python.org>
date Fri, 18 Oct 2002 13:42:21 +0000
parents 9ba011138831
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /*
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 ---------------------------------------------------------------------
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 / Copyright (c) 1996. \
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 | The Regents of the University of California. |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 | All rights reserved. |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 | |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 | Permission to use, copy, modify, and distribute this software for |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 | any purpose without fee is hereby granted, provided that this en- |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 | tire notice is included in all copies of any software which is or |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 | includes a copy or modification of this software and in all |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 | copies of the supporting documentation for such software. |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 | |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 | This work was produced at the University of California, Lawrence |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 | Livermore National Laboratory under contract no. W-7405-ENG-48 |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 | between the U.S. Department of Energy and The Regents of the |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 | University of California for the operation of UC LLNL. |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 | |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 | DISCLAIMER |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 | |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 | This software was prepared as an account of work sponsored by an |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 | agency of the United States Government. Neither the United States |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 | Government nor the University of California nor any of their em- |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 | ployees, makes any warranty, express or implied, or assumes any |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 | liability or responsibility for the accuracy, completeness, or |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 | usefulness of any information, apparatus, product, or process |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 | disclosed, or represents that its use would not infringe |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 | privately-owned rights. Reference herein to any specific commer- |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 | cial products, process, or service by trade name, trademark, |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 | manufacturer, or otherwise, does not necessarily constitute or |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 | imply its endorsement, recommendation, or favoring by the United |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 | States Government or the University of California. The views and |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 | opinions of authors expressed herein do not necessarily state or |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 | reflect those of the United States Government or the University |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 | of California, and shall not be used for advertising or product |
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 \ endorsement purposes. /
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 ---------------------------------------------------------------------
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 */
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
38
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 /*
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 Floating point exception control module.
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
41
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 This Python module provides bare-bones control over floating point
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 units from several hardware manufacturers. Specifically, it allows
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 the user to turn on the generation of SIGFPE whenever any of the
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 three serious IEEE 754 exceptions (Division by Zero, Overflow,
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 Invalid Operation) occurs. We currently ignore Underflow and
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 Inexact Result exceptions, although those could certainly be added
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 if desired.
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
49
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 The module also establishes a signal handler for SIGFPE during
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 initialization. This builds on code found in the Python
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 distribution at Include/pyfpe.h and Python/pyfpe.c. If those files
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 are not in your Python distribution, find them in a patch at
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 ftp://icf.llnl.gov/pub/python/busby/patches.961108.tgz.
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
55
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 This module is only useful to you if it happens to include code
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 specific for your hardware and software environment. If you can
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 contribute OS-specific code for new platforms, or corrections for
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 the code provided, it will be greatly appreciated.
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
60
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 ** Version 1.0: September 20, 1996. Lee Busby, LLNL.
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 */
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
63
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 #ifdef __cplusplus
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 extern "C" {
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 #endif
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
67
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 #include "Python.h"
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 #include <signal.h>
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
70
14683
edf1e15c671a Randall Hopper: Add fpectl functionality patch for FreeBSD.
Guido van Rossum <guido@python.org>
parents: 13676
diff changeset
71 #if defined(__FreeBSD__)
edf1e15c671a Randall Hopper: Add fpectl functionality patch for FreeBSD.
Guido van Rossum <guido@python.org>
parents: 13676
diff changeset
72 # include <ieeefp.h>
edf1e15c671a Randall Hopper: Add fpectl functionality patch for FreeBSD.
Guido van Rossum <guido@python.org>
parents: 13676
diff changeset
73 #endif
edf1e15c671a Randall Hopper: Add fpectl functionality patch for FreeBSD.
Guido van Rossum <guido@python.org>
parents: 13676
diff changeset
74
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 #ifndef WANT_SIGFPE_HANDLER
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 /* Define locally if they are not defined in Python. This gives only
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 * the limited control to induce a core dump in case of an exception.
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 */
5196
8ee81ef4e982 Include setjmp.h so it compiles if WANT_SIGFPE_HANDLER is undefined.
Guido van Rossum <guido@python.org>
parents: 5120
diff changeset
79 #include <setjmp.h>
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 static jmp_buf PyFPE_jbuf;
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 static int PyFPE_counter = 0;
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 #endif
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
83
13676
5423b132bc97 Removed all instances of RETSIGTYPE from the source code: signal
Tim Peters <tim.peters@gmail.com>
parents: 10617
diff changeset
84 typedef void Sigfunc(int);
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 static Sigfunc sigfpe_handler;
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 static void fpe_reset(Sigfunc *);
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
87
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 static PyObject *fpe_error;
9620
179fb63b1554 Needed to add DL_EXPORT to (redundant?) extern decl of module init function.
Guido van Rossum <guido@python.org>
parents: 9588
diff changeset
89 DL_EXPORT(void) initfpectl(void);
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 static PyObject *turnon_sigfpe (PyObject *self,PyObject *args);
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 static PyObject *turnoff_sigfpe (PyObject *self,PyObject *args);
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
92
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 static PyMethodDef fpectl_methods[] = {
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 {"turnon_sigfpe", (PyCFunction) turnon_sigfpe, 1},
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 {"turnoff_sigfpe", (PyCFunction) turnoff_sigfpe, 1},
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 {0,0}
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 };
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
98
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 static PyObject *turnon_sigfpe(PyObject *self,PyObject *args)
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 {
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 /* Do any architecture-specific one-time only initialization here. */
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
102
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 fpe_reset(sigfpe_handler);
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 Py_INCREF (Py_None);
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 return Py_None;
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 }
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
107
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 static void fpe_reset(Sigfunc *handler)
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 {
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 /* Reset the exception handling machinery, and reset the signal
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 * handler for SIGFPE to the given handler.
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 */
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
113
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 /*-- IRIX -----------------------------------------------------------------*/
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 #if defined(sgi)
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 /* See man page on handle_sigfpes -- must link with -lfpe
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 * My usage doesn't follow the man page exactly. Maybe somebody
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 * else can explain handle_sigfpes to me....
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 * cc -c -I/usr/local/python/include fpectlmodule.c
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 * ld -shared -o fpectlmodule.so fpectlmodule.o -lfpe
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 */
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 #include <sigfpe.h>
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 typedef void user_routine (unsigned[5], int[2]);
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 typedef void abort_routine (unsigned long);
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 handle_sigfpes(_OFF, 0,
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 (user_routine *)0,
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 _TURN_OFF_HANDLER_ON_ERROR,
5380
2d4c6cba01bf Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 5196
diff changeset
128 NULL);
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 handle_sigfpes(_ON, _EN_OVERFL | _EN_DIVZERO | _EN_INVALID,
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 (user_routine *)0,
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 _ABORT_ON_ERROR,
5380
2d4c6cba01bf Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 5196
diff changeset
132 NULL);
14719
870237089ba2 Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents: 14683
diff changeset
133 PyOS_setsig(SIGFPE, handler);
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
134
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 /*-- SunOS and Solaris ----------------------------------------------------*/
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 #elif defined(sun)
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 /* References: ieee_handler, ieee_sun, ieee_functions, and ieee_flags
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 man pages (SunOS or Solaris)
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 cc -c -I/usr/local/python/include fpectlmodule.c
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 ld -G -o fpectlmodule.so -L/opt/SUNWspro/lib fpectlmodule.o -lsunmath -lm
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 */
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 #include <math.h>
17009
99de4bf2b9e5 Define sunmath prototypes if sunmath.h was not included.
Martin v. Löwis <martin@v.loewis.de>
parents: 15713
diff changeset
143 #ifndef _SUNMATH_H
99de4bf2b9e5 Define sunmath prototypes if sunmath.h was not included.
Martin v. Löwis <martin@v.loewis.de>
parents: 15713
diff changeset
144 extern void nonstandard_arithmetic(void);
99de4bf2b9e5 Define sunmath prototypes if sunmath.h was not included.
Martin v. Löwis <martin@v.loewis.de>
parents: 15713
diff changeset
145 extern int ieee_flags(const char*, const char*, const char*, char **);
99de4bf2b9e5 Define sunmath prototypes if sunmath.h was not included.
Martin v. Löwis <martin@v.loewis.de>
parents: 15713
diff changeset
146 extern long ieee_handler(const char*, const char*, sigfpe_handler_type);
99de4bf2b9e5 Define sunmath prototypes if sunmath.h was not included.
Martin v. Löwis <martin@v.loewis.de>
parents: 15713
diff changeset
147 #endif
99de4bf2b9e5 Define sunmath prototypes if sunmath.h was not included.
Martin v. Löwis <martin@v.loewis.de>
parents: 15713
diff changeset
148
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 char *mode="exception", *in="all", *out;
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 (void) nonstandard_arithmetic();
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 (void) ieee_flags("clearall",mode,in,&out);
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 (void) ieee_handler("set","common",(sigfpe_handler_type)handler);
14719
870237089ba2 Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents: 14683
diff changeset
153 PyOS_setsig(SIGFPE, handler);
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
154
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 /*-- HPUX -----------------------------------------------------------------*/
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 #elif defined(__hppa) || defined(hppa)
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 /* References: fpsetmask man page */
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 /* cc -Aa +z -c -I/usr/local/python/include fpectlmodule.c */
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 /* ld -b -o fpectlmodule.sl fpectlmodule.o -lm */
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 #include <math.h>
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 fpsetdefaults();
14719
870237089ba2 Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents: 14683
diff changeset
162 PyOS_setsig(SIGFPE, handler);
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
163
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 /*-- IBM AIX --------------------------------------------------------------*/
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 #elif defined(__AIX) || defined(_AIX)
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 /* References: fp_trap, fp_enable man pages */
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
167 #include <fptrap.h>
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 fp_trap(FP_TRAP_SYNC);
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 fp_enable(TRP_INVALID | TRP_DIV_BY_ZERO | TRP_OVERFLOW);
14719
870237089ba2 Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents: 14683
diff changeset
170 PyOS_setsig(SIGFPE, handler);
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
171
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 /*-- DEC ALPHA OSF --------------------------------------------------------*/
10617
012d361fdf23 Avoid triggering Alpha OSF/1 specific code on Alpha NT or Linux.
Guido van Rossum <guido@python.org>
parents: 9620
diff changeset
173 #elif defined(__alpha) && defined(__osf__)
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 /* References: exception_intro, ieee man pages */
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 /* cc -c -I/usr/local/python/include fpectlmodule.c */
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 /* ld -shared -o fpectlmodule.so fpectlmodule.o */
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 #include <machine/fpu.h>
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 unsigned long fp_control =
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 IEEE_TRAP_ENABLE_INV | IEEE_TRAP_ENABLE_DZE | IEEE_TRAP_ENABLE_OVF;
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 ieee_set_fp_control(fp_control);
14719
870237089ba2 Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents: 14683
diff changeset
181 PyOS_setsig(SIGFPE, handler);
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
182
25446
9ba011138831 Backport of 2.18:
Guido van Rossum <guido@python.org>
parents: 17009
diff changeset
183 /*-- DEC ALPHA LINUX ------------------------------------------------------*/
9ba011138831 Backport of 2.18:
Guido van Rossum <guido@python.org>
parents: 17009
diff changeset
184 #elif defined(__alpha) && defined(linux)
9ba011138831 Backport of 2.18:
Guido van Rossum <guido@python.org>
parents: 17009
diff changeset
185 #include <asm/fpu.h>
9ba011138831 Backport of 2.18:
Guido van Rossum <guido@python.org>
parents: 17009
diff changeset
186 unsigned long fp_control =
9ba011138831 Backport of 2.18:
Guido van Rossum <guido@python.org>
parents: 17009
diff changeset
187 IEEE_TRAP_ENABLE_INV | IEEE_TRAP_ENABLE_DZE | IEEE_TRAP_ENABLE_OVF;
9ba011138831 Backport of 2.18:
Guido van Rossum <guido@python.org>
parents: 17009
diff changeset
188 ieee_set_fp_control(fp_control);
9ba011138831 Backport of 2.18:
Guido van Rossum <guido@python.org>
parents: 17009
diff changeset
189 PyOS_setsig(SIGFPE, handler);
9ba011138831 Backport of 2.18:
Guido van Rossum <guido@python.org>
parents: 17009
diff changeset
190
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 /*-- Cray Unicos ----------------------------------------------------------*/
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
192 #elif defined(cray)
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 /* UNICOS delivers SIGFPE by default, but no matherr */
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 #ifdef HAS_LIBMSET
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 libmset(-1);
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 #endif
14719
870237089ba2 Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents: 14683
diff changeset
197 PyOS_setsig(SIGFPE, handler);
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
198
14683
edf1e15c671a Randall Hopper: Add fpectl functionality patch for FreeBSD.
Guido van Rossum <guido@python.org>
parents: 13676
diff changeset
199 /*-- FreeBSD ----------------------------------------------------------------*/
edf1e15c671a Randall Hopper: Add fpectl functionality patch for FreeBSD.
Guido van Rossum <guido@python.org>
parents: 13676
diff changeset
200 #elif defined(__FreeBSD__)
14719
870237089ba2 Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents: 14683
diff changeset
201 fpresetsticky(fpgetsticky());
870237089ba2 Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents: 14683
diff changeset
202 fpsetmask(FP_X_INV | FP_X_DZ | FP_X_OFL);
870237089ba2 Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents: 14683
diff changeset
203 PyOS_setsig(SIGFPE, handler);
14683
edf1e15c671a Randall Hopper: Add fpectl functionality patch for FreeBSD.
Guido van Rossum <guido@python.org>
parents: 13676
diff changeset
204
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 /*-- Linux ----------------------------------------------------------------*/
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 #elif defined(linux)
6855
1ab307951f4e Patch by Oliver Andrich for Lunix using glibc.
Guido van Rossum <guido@python.org>
parents: 6507
diff changeset
207 #ifdef __GLIBC__
1ab307951f4e Patch by Oliver Andrich for Lunix using glibc.
Guido van Rossum <guido@python.org>
parents: 6507
diff changeset
208 #include <fpu_control.h>
1ab307951f4e Patch by Oliver Andrich for Lunix using glibc.
Guido van Rossum <guido@python.org>
parents: 6507
diff changeset
209 #else
6507
a00073f2e087 Some patches to Lee Busby's fpectl mods that accidentally didn't make it
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
210 #include <i386/fpu_control.h>
6855
1ab307951f4e Patch by Oliver Andrich for Lunix using glibc.
Guido van Rossum <guido@python.org>
parents: 6507
diff changeset
211 #endif
15713
3693abd0eac1 Patch #103012: Update fpectlmodule for current glibc;
Andrew M. Kuchling <amk@amk.ca>
parents: 14719
diff changeset
212 #ifdef _FPU_SETCW
3693abd0eac1 Patch #103012: Update fpectlmodule for current glibc;
Andrew M. Kuchling <amk@amk.ca>
parents: 14719
diff changeset
213 {
3693abd0eac1 Patch #103012: Update fpectlmodule for current glibc;
Andrew M. Kuchling <amk@amk.ca>
parents: 14719
diff changeset
214 fpu_control_t cw = 0x1372;
3693abd0eac1 Patch #103012: Update fpectlmodule for current glibc;
Andrew M. Kuchling <amk@amk.ca>
parents: 14719
diff changeset
215 _FPU_SETCW(cw);
3693abd0eac1 Patch #103012: Update fpectlmodule for current glibc;
Andrew M. Kuchling <amk@amk.ca>
parents: 14719
diff changeset
216 }
3693abd0eac1 Patch #103012: Update fpectlmodule for current glibc;
Andrew M. Kuchling <amk@amk.ca>
parents: 14719
diff changeset
217 #else
6507
a00073f2e087 Some patches to Lee Busby's fpectl mods that accidentally didn't make it
Guido van Rossum <guido@python.org>
parents: 6367
diff changeset
218 __setfpucw(0x1372);
15713
3693abd0eac1 Patch #103012: Update fpectlmodule for current glibc;
Andrew M. Kuchling <amk@amk.ca>
parents: 14719
diff changeset
219 #endif
14719
870237089ba2 Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents: 14683
diff changeset
220 PyOS_setsig(SIGFPE, handler);
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
221
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
222 /*-- NeXT -----------------------------------------------------------------*/
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
223 #elif defined(NeXT) && defined(m68k) && defined(__GNUC__)
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
224 /* NeXT needs explicit csr set to generate SIGFPE */
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 asm("fmovel #0x1400,fpcr"); /* set OVFL and ZD bits */
14719
870237089ba2 Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents: 14683
diff changeset
226 PyOS_setsig(SIGFPE, handler);
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
227
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 /*-- Microsoft Windows, NT ------------------------------------------------*/
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
229 #elif defined(_MSC_VER)
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 /* Reference: Visual C++ Books Online 4.2,
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 Run-Time Library Reference, _control87, _controlfp */
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
232 #include <float.h>
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 unsigned int cw = _EM_INVALID | _EM_ZERODIVIDE | _EM_OVERFLOW;
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
234 (void)_controlfp(0, cw);
14719
870237089ba2 Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents: 14683
diff changeset
235 PyOS_setsig(SIGFPE, handler);
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
236
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 /*-- Give Up --------------------------------------------------------------*/
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 #else
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 fputs("Operation not implemented\n", stderr);
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
240 #endif
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
241
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
242 }
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
243
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 static PyObject *turnoff_sigfpe(PyObject *self,PyObject *args)
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
245 {
14683
edf1e15c671a Randall Hopper: Add fpectl functionality patch for FreeBSD.
Guido van Rossum <guido@python.org>
parents: 13676
diff changeset
246 #ifdef __FreeBSD__
14719
870237089ba2 Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents: 14683
diff changeset
247 fpresetsticky(fpgetsticky());
870237089ba2 Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents: 14683
diff changeset
248 fpsetmask(0);
14683
edf1e15c671a Randall Hopper: Add fpectl functionality patch for FreeBSD.
Guido van Rossum <guido@python.org>
parents: 13676
diff changeset
249 #else
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
250 fputs("Operation not implemented\n", stderr);
14683
edf1e15c671a Randall Hopper: Add fpectl functionality patch for FreeBSD.
Guido van Rossum <guido@python.org>
parents: 13676
diff changeset
251 #endif
14719
870237089ba2 Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents: 14683
diff changeset
252 Py_INCREF(Py_None);
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
253 return Py_None;
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
254 }
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
255
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
256 static void sigfpe_handler(int signo)
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
257 {
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
258 fpe_reset(sigfpe_handler);
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
259 if(PyFPE_counter) {
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 longjmp(PyFPE_jbuf, 1);
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
261 } else {
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
262 Py_FatalError("Unprotected floating point exception");
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
263 }
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
264 }
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
265
9588
38023a425e48 Add DL_EXPORT() to all modules that could possibly be used
Guido van Rossum <guido@python.org>
parents: 6855
diff changeset
266 DL_EXPORT(void) initfpectl(void)
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
267 {
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
268 PyObject *m, *d;
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
269 m = Py_InitModule("fpectl", fpectl_methods);
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
270 d = PyModule_GetDict(m);
6367
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 5380
diff changeset
271 fpe_error = PyErr_NewException("fpectl.error", NULL, NULL);
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 5380
diff changeset
272 if (fpe_error != NULL)
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 5380
diff changeset
273 PyDict_SetItemString(d, "error", fpe_error);
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
274 }
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
275
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
276 #ifdef __cplusplus
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
277 }
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
278 #endif