Mercurial > cpython-lru_cache-weakref
annotate Modules/fpectlmodule.c @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | fd25030223b0 |
| children |
| rev | line source |
|---|---|
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 /* |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
2 --------------------------------------------------------------------- |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
3 / Copyright (c) 1996. \ |
|
5120
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 | |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
35 \ endorsement purposes. / |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
36 --------------------------------------------------------------------- |
|
5120
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 /* |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
40 Floating point exception control module. |
|
5120
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> |
|
39043
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
73 #elif defined(__VMS) |
|
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
74 #define __NEW_STARLET |
|
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
75 #include <starlet.h> |
|
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
76 #include <ieeedef.h> |
|
14683
edf1e15c671a
Randall Hopper: Add fpectl functionality patch for FreeBSD.
Guido van Rossum <guido@python.org>
parents:
13676
diff
changeset
|
77 #endif |
|
edf1e15c671a
Randall Hopper: Add fpectl functionality patch for FreeBSD.
Guido van Rossum <guido@python.org>
parents:
13676
diff
changeset
|
78 |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 #ifndef WANT_SIGFPE_HANDLER |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 /* 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
|
81 * 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
|
82 */ |
|
5196
8ee81ef4e982
Include setjmp.h so it compiles if WANT_SIGFPE_HANDLER is undefined.
Guido van Rossum <guido@python.org>
parents:
5120
diff
changeset
|
83 #include <setjmp.h> |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 static jmp_buf PyFPE_jbuf; |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
85 static int PyFPE_counter = 0; |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 #endif |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
87 |
|
13676
5423b132bc97
Removed all instances of RETSIGTYPE from the source code: signal
Tim Peters <tim.peters@gmail.com>
parents:
10617
diff
changeset
|
88 typedef void Sigfunc(int); |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
89 static Sigfunc sigfpe_handler; |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
90 static void fpe_reset(Sigfunc *); |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 static PyObject *fpe_error; |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
21859
diff
changeset
|
93 PyMODINIT_FUNC initfpectl(void); |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 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
|
95 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
|
96 |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
97 static PyMethodDef fpectl_methods[] = { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
98 {"turnon_sigfpe", (PyCFunction) turnon_sigfpe, METH_VARARGS}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
99 {"turnoff_sigfpe", (PyCFunction) turnoff_sigfpe, METH_VARARGS}, |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
100 {0,0} |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
101 }; |
|
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 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
|
104 { |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
105 /* 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
|
106 |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
107 fpe_reset(sigfpe_handler); |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
108 Py_INCREF (Py_None); |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 return Py_None; |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 } |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
111 |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 static void fpe_reset(Sigfunc *handler) |
|
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 /* 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
|
115 * 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
|
116 */ |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
117 |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
118 /*-- IRIX -----------------------------------------------------------------*/ |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
119 #if defined(sgi) |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
120 /* 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
|
121 * 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
|
122 * 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
|
123 * cc -c -I/usr/local/python/include fpectlmodule.c |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
124 * ld -shared -o fpectlmodule.so fpectlmodule.o -lfpe |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
125 */ |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
126 #include <sigfpe.h> |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
127 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
|
128 typedef void abort_routine (unsigned long); |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
129 handle_sigfpes(_OFF, 0, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
130 (user_routine *)0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
131 _TURN_OFF_HANDLER_ON_ERROR, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
132 NULL); |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
133 handle_sigfpes(_ON, _EN_OVERFL | _EN_DIVZERO | _EN_INVALID, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
134 (user_routine *)0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
135 _ABORT_ON_ERROR, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
136 NULL); |
|
14719
870237089ba2
Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents:
14683
diff
changeset
|
137 PyOS_setsig(SIGFPE, handler); |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
139 /*-- SunOS and Solaris ----------------------------------------------------*/ |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 #elif defined(sun) |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
141 /* 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
|
142 man pages (SunOS or Solaris) |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
143 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
|
144 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
|
145 */ |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
146 #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
|
147 #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
|
148 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
|
149 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
|
150 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
|
151 #endif |
|
99de4bf2b9e5
Define sunmath prototypes if sunmath.h was not included.
Martin v. Löwis <martin@v.loewis.de>
parents:
15713
diff
changeset
|
152 |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
153 char *mode="exception", *in="all", *out; |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
154 (void) nonstandard_arithmetic(); |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
155 (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
|
156 (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
|
157 PyOS_setsig(SIGFPE, handler); |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
158 |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
159 /*-- HPUX -----------------------------------------------------------------*/ |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
160 #elif defined(__hppa) || defined(hppa) |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
161 /* References: fpsetmask man page */ |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
162 /* 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
|
163 /* 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
|
164 #include <math.h> |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
165 fpsetdefaults(); |
|
14719
870237089ba2
Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents:
14683
diff
changeset
|
166 PyOS_setsig(SIGFPE, handler); |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
167 |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
168 /*-- IBM AIX --------------------------------------------------------------*/ |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
169 #elif defined(__AIX) || defined(_AIX) |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
170 /* 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
|
171 #include <fptrap.h> |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
172 fp_trap(FP_TRAP_SYNC); |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
173 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
|
174 PyOS_setsig(SIGFPE, handler); |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
175 |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
176 /*-- 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
|
177 #elif defined(__alpha) && defined(__osf__) |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
178 /* References: exception_intro, ieee man pages */ |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
179 /* 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
|
180 /* 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
|
181 #include <machine/fpu.h> |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
182 unsigned long fp_control = |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
183 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
|
184 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
|
185 PyOS_setsig(SIGFPE, handler); |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
186 |
|
25445
db5f1db7b34e
Patch for the DEC Alpha under Linux, by Lee Busby.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
187 /*-- DEC ALPHA LINUX ------------------------------------------------------*/ |
|
db5f1db7b34e
Patch for the DEC Alpha under Linux, by Lee Busby.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
188 #elif defined(__alpha) && defined(linux) |
|
db5f1db7b34e
Patch for the DEC Alpha under Linux, by Lee Busby.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
189 #include <asm/fpu.h> |
|
db5f1db7b34e
Patch for the DEC Alpha under Linux, by Lee Busby.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
190 unsigned long fp_control = |
|
db5f1db7b34e
Patch for the DEC Alpha under Linux, by Lee Busby.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
191 IEEE_TRAP_ENABLE_INV | IEEE_TRAP_ENABLE_DZE | IEEE_TRAP_ENABLE_OVF; |
|
db5f1db7b34e
Patch for the DEC Alpha under Linux, by Lee Busby.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
192 ieee_set_fp_control(fp_control); |
|
db5f1db7b34e
Patch for the DEC Alpha under Linux, by Lee Busby.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
193 PyOS_setsig(SIGFPE, handler); |
|
db5f1db7b34e
Patch for the DEC Alpha under Linux, by Lee Busby.
Guido van Rossum <guido@python.org>
parents:
24471
diff
changeset
|
194 |
|
28949
ac487a7f7f2c
Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25445
diff
changeset
|
195 /*-- DEC ALPHA VMS --------------------------------------------------------*/ |
|
ac487a7f7f2c
Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25445
diff
changeset
|
196 #elif defined(__ALPHA) && defined(__VMS) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
197 IEEE clrmsk; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
198 IEEE setmsk; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
199 clrmsk.ieee$q_flags = |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
200 IEEE$M_TRAP_ENABLE_UNF | IEEE$M_TRAP_ENABLE_INE | |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
201 IEEE$M_MAP_UMZ; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
202 setmsk.ieee$q_flags = |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
203 IEEE$M_TRAP_ENABLE_INV | IEEE$M_TRAP_ENABLE_DZE | |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
204 IEEE$M_TRAP_ENABLE_OVF; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
205 sys$ieee_set_fp_control(&clrmsk, &setmsk, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
206 PyOS_setsig(SIGFPE, handler); |
|
39043
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
207 |
|
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
208 /*-- HP IA64 VMS --------------------------------------------------------*/ |
|
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
209 #elif defined(__ia64) && defined(__VMS) |
|
28949
ac487a7f7f2c
Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25445
diff
changeset
|
210 PyOS_setsig(SIGFPE, handler); |
|
ac487a7f7f2c
Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents:
25445
diff
changeset
|
211 |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
212 /*-- Cray Unicos ----------------------------------------------------------*/ |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
213 #elif defined(cray) |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
214 /* 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
|
215 #ifdef HAS_LIBMSET |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
216 libmset(-1); |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
217 #endif |
|
14719
870237089ba2
Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents:
14683
diff
changeset
|
218 PyOS_setsig(SIGFPE, handler); |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
219 |
|
14683
edf1e15c671a
Randall Hopper: Add fpectl functionality patch for FreeBSD.
Guido van Rossum <guido@python.org>
parents:
13676
diff
changeset
|
220 /*-- FreeBSD ----------------------------------------------------------------*/ |
|
edf1e15c671a
Randall Hopper: Add fpectl functionality patch for FreeBSD.
Guido van Rossum <guido@python.org>
parents:
13676
diff
changeset
|
221 #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
|
222 fpresetsticky(fpgetsticky()); |
|
870237089ba2
Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents:
14683
diff
changeset
|
223 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
|
224 PyOS_setsig(SIGFPE, handler); |
|
14683
edf1e15c671a
Randall Hopper: Add fpectl functionality patch for FreeBSD.
Guido van Rossum <guido@python.org>
parents:
13676
diff
changeset
|
225 |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
226 /*-- Linux ----------------------------------------------------------------*/ |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
227 #elif defined(linux) |
|
6855
1ab307951f4e
Patch by Oliver Andrich for Lunix using glibc.
Guido van Rossum <guido@python.org>
parents:
6507
diff
changeset
|
228 #ifdef __GLIBC__ |
|
1ab307951f4e
Patch by Oliver Andrich for Lunix using glibc.
Guido van Rossum <guido@python.org>
parents:
6507
diff
changeset
|
229 #include <fpu_control.h> |
|
1ab307951f4e
Patch by Oliver Andrich for Lunix using glibc.
Guido van Rossum <guido@python.org>
parents:
6507
diff
changeset
|
230 #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
|
231 #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
|
232 #endif |
|
15713
3693abd0eac1
Patch #103012: Update fpectlmodule for current glibc;
Andrew M. Kuchling <amk@amk.ca>
parents:
14719
diff
changeset
|
233 #ifdef _FPU_SETCW |
|
3693abd0eac1
Patch #103012: Update fpectlmodule for current glibc;
Andrew M. Kuchling <amk@amk.ca>
parents:
14719
diff
changeset
|
234 { |
|
3693abd0eac1
Patch #103012: Update fpectlmodule for current glibc;
Andrew M. Kuchling <amk@amk.ca>
parents:
14719
diff
changeset
|
235 fpu_control_t cw = 0x1372; |
|
3693abd0eac1
Patch #103012: Update fpectlmodule for current glibc;
Andrew M. Kuchling <amk@amk.ca>
parents:
14719
diff
changeset
|
236 _FPU_SETCW(cw); |
|
3693abd0eac1
Patch #103012: Update fpectlmodule for current glibc;
Andrew M. Kuchling <amk@amk.ca>
parents:
14719
diff
changeset
|
237 } |
|
3693abd0eac1
Patch #103012: Update fpectlmodule for current glibc;
Andrew M. Kuchling <amk@amk.ca>
parents:
14719
diff
changeset
|
238 #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
|
239 __setfpucw(0x1372); |
|
15713
3693abd0eac1
Patch #103012: Update fpectlmodule for current glibc;
Andrew M. Kuchling <amk@amk.ca>
parents:
14719
diff
changeset
|
240 #endif |
|
14719
870237089ba2
Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents:
14683
diff
changeset
|
241 PyOS_setsig(SIGFPE, handler); |
|
5120
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 /*-- Microsoft Windows, NT ------------------------------------------------*/ |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
244 #elif defined(_MSC_VER) |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
245 /* 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
|
246 Run-Time Library Reference, _control87, _controlfp */ |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
247 #include <float.h> |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
248 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
|
249 (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
|
250 PyOS_setsig(SIGFPE, handler); |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
251 |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
252 /*-- Give Up --------------------------------------------------------------*/ |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
253 #else |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
254 fputs("Operation not implemented\n", stderr); |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
255 #endif |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
256 |
|
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 |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
259 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
|
260 { |
|
14683
edf1e15c671a
Randall Hopper: Add fpectl functionality patch for FreeBSD.
Guido van Rossum <guido@python.org>
parents:
13676
diff
changeset
|
261 #ifdef __FreeBSD__ |
|
14719
870237089ba2
Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents:
14683
diff
changeset
|
262 fpresetsticky(fpgetsticky()); |
|
870237089ba2
Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents:
14683
diff
changeset
|
263 fpsetmask(0); |
|
39043
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36324
diff
changeset
|
264 #elif defined(__VMS) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
265 IEEE clrmsk; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
266 clrmsk.ieee$q_flags = |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
267 IEEE$M_TRAP_ENABLE_UNF | IEEE$M_TRAP_ENABLE_INE | |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
268 IEEE$M_MAP_UMZ | IEEE$M_TRAP_ENABLE_INV | |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
269 IEEE$M_TRAP_ENABLE_DZE | IEEE$M_TRAP_ENABLE_OVF | |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
270 IEEE$M_INHERIT; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
271 sys$ieee_set_fp_control(&clrmsk, 0, 0); |
|
14683
edf1e15c671a
Randall Hopper: Add fpectl functionality patch for FreeBSD.
Guido van Rossum <guido@python.org>
parents:
13676
diff
changeset
|
272 #else |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
273 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
|
274 #endif |
|
14719
870237089ba2
Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents:
14683
diff
changeset
|
275 Py_INCREF(Py_None); |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
276 return Py_None; |
|
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 |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
279 static void sigfpe_handler(int signo) |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
280 { |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
281 fpe_reset(sigfpe_handler); |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
282 if(PyFPE_counter) { |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
283 longjmp(PyFPE_jbuf, 1); |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
284 } else { |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
285 Py_FatalError("Unprotected floating point exception"); |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
286 } |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
287 } |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
288 |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
21859
diff
changeset
|
289 PyMODINIT_FUNC initfpectl(void) |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
290 { |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
291 PyObject *m, *d; |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
292 m = Py_InitModule("fpectl", fpectl_methods); |
|
36324
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
28949
diff
changeset
|
293 if (m == NULL) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
294 return; |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
295 d = PyModule_GetDict(m); |
|
6367
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5380
diff
changeset
|
296 fpe_error = PyErr_NewException("fpectl.error", NULL, NULL); |
|
2c29b8982643
Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents:
5380
diff
changeset
|
297 if (fpe_error != NULL) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39043
diff
changeset
|
298 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
|
299 } |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
300 |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
301 #ifdef __cplusplus |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
302 } |
|
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
303 #endif |
