annotate Modules/fpectlmodule.c @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents 15b090c9442a
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 /*
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
2 ---------------------------------------------------------------------
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
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 |
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
35 \ endorsement purposes. /
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
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 /*
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
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>
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 36324
diff changeset
73 #elif defined(__VMS)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 36324
diff changeset
74 #define __NEW_STARLET
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 36324
diff changeset
75 #include <starlet.h>
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
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;
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 39442
diff changeset
93
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 39442
diff changeset
94 PyMODINIT_FUNC PyInit_fpectl(void);
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 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
96 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
97
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 static PyMethodDef fpectl_methods[] = {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
99 {"turnon_sigfpe", (PyCFunction) turnon_sigfpe, METH_VARARGS},
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
100 {"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
101 {0,0}
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
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 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
105 {
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 /* 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
107
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 fpe_reset(sigfpe_handler);
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 Py_INCREF (Py_None);
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 return Py_None;
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
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 static void fpe_reset(Sigfunc *handler)
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 {
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 /* 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
116 * 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
117 */
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
118
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 /*-- IRIX -----------------------------------------------------------------*/
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 #if defined(sgi)
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 /* 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
122 * 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
123 * 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
124 * cc -c -I/usr/local/python/include fpectlmodule.c
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
125 * 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
126 */
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 #include <sigfpe.h>
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 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
129 typedef void abort_routine (unsigned long);
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 handle_sigfpes(_OFF, 0,
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
131 (user_routine *)0,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
132 _TURN_OFF_HANDLER_ON_ERROR,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
133 NULL);
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 handle_sigfpes(_ON, _EN_OVERFL | _EN_DIVZERO | _EN_INVALID,
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
135 (user_routine *)0,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
136 _ABORT_ON_ERROR,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
137 NULL);
14719
870237089ba2 Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents: 14683
diff changeset
138 PyOS_setsig(SIGFPE, handler);
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
139
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 /*-- SunOS and Solaris ----------------------------------------------------*/
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 #elif defined(sun)
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 /* 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
143 man pages (SunOS or Solaris)
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 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
145 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
146 */
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 #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
148 #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
149 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
150 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
151 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
152 #endif
99de4bf2b9e5 Define sunmath prototypes if sunmath.h was not included.
Martin v. Löwis <martin@v.loewis.de>
parents: 15713
diff changeset
153
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 char *mode="exception", *in="all", *out;
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 (void) nonstandard_arithmetic();
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 (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
157 (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
158 PyOS_setsig(SIGFPE, handler);
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
159
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 /*-- HPUX -----------------------------------------------------------------*/
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 #elif defined(__hppa) || defined(hppa)
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 /* References: fpsetmask man page */
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 /* 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
164 /* 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
165 #include <math.h>
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 fpsetdefaults();
14719
870237089ba2 Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents: 14683
diff changeset
167 PyOS_setsig(SIGFPE, handler);
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
168
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 /*-- IBM AIX --------------------------------------------------------------*/
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 #elif defined(__AIX) || defined(_AIX)
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 /* 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
172 #include <fptrap.h>
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 fp_trap(FP_TRAP_SYNC);
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 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
175 PyOS_setsig(SIGFPE, handler);
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
176
25445
db5f1db7b34e Patch for the DEC Alpha under Linux, by Lee Busby.
Guido van Rossum <guido@python.org>
parents: 24471
diff changeset
177 /*-- DEC ALPHA LINUX ------------------------------------------------------*/
db5f1db7b34e Patch for the DEC Alpha under Linux, by Lee Busby.
Guido van Rossum <guido@python.org>
parents: 24471
diff changeset
178 #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
179 #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
180 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
181 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
182 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
183 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
184
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25445
diff changeset
185 /*-- DEC ALPHA VMS --------------------------------------------------------*/
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25445
diff changeset
186 #elif defined(__ALPHA) && defined(__VMS)
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
187 IEEE clrmsk;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
188 IEEE setmsk;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
189 clrmsk.ieee$q_flags =
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
190 IEEE$M_TRAP_ENABLE_UNF | IEEE$M_TRAP_ENABLE_INE |
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
191 IEEE$M_MAP_UMZ;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
192 setmsk.ieee$q_flags =
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
193 IEEE$M_TRAP_ENABLE_INV | IEEE$M_TRAP_ENABLE_DZE |
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
194 IEEE$M_TRAP_ENABLE_OVF;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
195 sys$ieee_set_fp_control(&clrmsk, &setmsk, 0);
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
196 PyOS_setsig(SIGFPE, handler);
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 36324
diff changeset
197
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 36324
diff changeset
198 /*-- HP IA64 VMS --------------------------------------------------------*/
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 36324
diff changeset
199 #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
200 PyOS_setsig(SIGFPE, handler);
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25445
diff changeset
201
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 /*-- Cray Unicos ----------------------------------------------------------*/
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
203 #elif defined(cray)
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 /* 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
205 #ifdef HAS_LIBMSET
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 libmset(-1);
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 #endif
14719
870237089ba2 Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents: 14683
diff changeset
208 PyOS_setsig(SIGFPE, handler);
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
209
14683
edf1e15c671a Randall Hopper: Add fpectl functionality patch for FreeBSD.
Guido van Rossum <guido@python.org>
parents: 13676
diff changeset
210 /*-- FreeBSD ----------------------------------------------------------------*/
edf1e15c671a Randall Hopper: Add fpectl functionality patch for FreeBSD.
Guido van Rossum <guido@python.org>
parents: 13676
diff changeset
211 #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
212 fpresetsticky(fpgetsticky());
870237089ba2 Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents: 14683
diff changeset
213 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
214 PyOS_setsig(SIGFPE, handler);
14683
edf1e15c671a Randall Hopper: Add fpectl functionality patch for FreeBSD.
Guido van Rossum <guido@python.org>
parents: 13676
diff changeset
215
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
216 /*-- Linux ----------------------------------------------------------------*/
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 #elif defined(linux)
6855
1ab307951f4e Patch by Oliver Andrich for Lunix using glibc.
Guido van Rossum <guido@python.org>
parents: 6507
diff changeset
218 #ifdef __GLIBC__
1ab307951f4e Patch by Oliver Andrich for Lunix using glibc.
Guido van Rossum <guido@python.org>
parents: 6507
diff changeset
219 #include <fpu_control.h>
1ab307951f4e Patch by Oliver Andrich for Lunix using glibc.
Guido van Rossum <guido@python.org>
parents: 6507
diff changeset
220 #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
221 #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
222 #endif
15713
3693abd0eac1 Patch #103012: Update fpectlmodule for current glibc;
Andrew M. Kuchling <amk@amk.ca>
parents: 14719
diff changeset
223 #ifdef _FPU_SETCW
3693abd0eac1 Patch #103012: Update fpectlmodule for current glibc;
Andrew M. Kuchling <amk@amk.ca>
parents: 14719
diff changeset
224 {
3693abd0eac1 Patch #103012: Update fpectlmodule for current glibc;
Andrew M. Kuchling <amk@amk.ca>
parents: 14719
diff changeset
225 fpu_control_t cw = 0x1372;
3693abd0eac1 Patch #103012: Update fpectlmodule for current glibc;
Andrew M. Kuchling <amk@amk.ca>
parents: 14719
diff changeset
226 _FPU_SETCW(cw);
3693abd0eac1 Patch #103012: Update fpectlmodule for current glibc;
Andrew M. Kuchling <amk@amk.ca>
parents: 14719
diff changeset
227 }
3693abd0eac1 Patch #103012: Update fpectlmodule for current glibc;
Andrew M. Kuchling <amk@amk.ca>
parents: 14719
diff changeset
228 #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
229 __setfpucw(0x1372);
15713
3693abd0eac1 Patch #103012: Update fpectlmodule for current glibc;
Andrew M. Kuchling <amk@amk.ca>
parents: 14719
diff changeset
230 #endif
14719
870237089ba2 Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents: 14683
diff changeset
231 PyOS_setsig(SIGFPE, handler);
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
232
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 /*-- Microsoft Windows, NT ------------------------------------------------*/
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
234 #elif defined(_MSC_VER)
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
235 /* 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
236 Run-Time Library Reference, _control87, _controlfp */
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 #include <float.h>
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 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
239 (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
240 PyOS_setsig(SIGFPE, handler);
5120
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 /*-- Give Up --------------------------------------------------------------*/
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 #else
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 fputs("Operation not implemented\n", stderr);
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
245 #endif
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
246
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
247 }
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
248
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 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
250 {
14683
edf1e15c671a Randall Hopper: Add fpectl functionality patch for FreeBSD.
Guido van Rossum <guido@python.org>
parents: 13676
diff changeset
251 #ifdef __FreeBSD__
14719
870237089ba2 Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents: 14683
diff changeset
252 fpresetsticky(fpgetsticky());
870237089ba2 Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents: 14683
diff changeset
253 fpsetmask(0);
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 36324
diff changeset
254 #elif defined(__VMS)
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
255 IEEE clrmsk;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
256 clrmsk.ieee$q_flags =
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
257 IEEE$M_TRAP_ENABLE_UNF | IEEE$M_TRAP_ENABLE_INE |
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
258 IEEE$M_MAP_UMZ | IEEE$M_TRAP_ENABLE_INV |
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
259 IEEE$M_TRAP_ENABLE_DZE | IEEE$M_TRAP_ENABLE_OVF |
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
260 IEEE$M_INHERIT;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
261 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
262 #else
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
263 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
264 #endif
14719
870237089ba2 Use PyOS_setsig() instead of signal(). Also remove redundant spaces
Guido van Rossum <guido@python.org>
parents: 14683
diff changeset
265 Py_INCREF(Py_None);
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
266 return Py_None;
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
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
269 static void sigfpe_handler(int signo)
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
270 {
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
271 fpe_reset(sigfpe_handler);
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
272 if(PyFPE_counter) {
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
273 longjmp(PyFPE_jbuf, 1);
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
274 } else {
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
275 Py_FatalError("Unprotected floating point exception");
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
276 }
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
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 39442
diff changeset
279 static struct PyModuleDef fpectlmodule = {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
280 PyModuleDef_HEAD_INIT,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
281 "fpectl",
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
282 NULL,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
283 -1,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
284 fpectl_methods,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
285 NULL,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
286 NULL,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
287 NULL,
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
288 NULL
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 39442
diff changeset
289 };
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 39442
diff changeset
290
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 39442
diff changeset
291 PyMODINIT_FUNC PyInit_fpectl(void)
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
292 {
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
293 PyObject *m, *d;
49855
9fd9cd852631 - fix build failure in Modules/fpectlmodule.c (not built by default)
Matthias Klose <doko@ubuntu.com>
parents: 47580
diff changeset
294 m = PyModule_Create(&fpectlmodule);
36324
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 28949
diff changeset
295 if (m == NULL)
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
296 return NULL;
5120
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
297 d = PyModule_GetDict(m);
6367
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 5380
diff changeset
298 fpe_error = PyErr_NewException("fpectl.error", NULL, NULL);
2c29b8982643 Apply two changes, systematically:
Guido van Rossum <guido@python.org>
parents: 5380
diff changeset
299 if (fpe_error != NULL)
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 49855
diff changeset
300 PyDict_SetItemString(d, "error", fpe_error);
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 39442
diff changeset
301 return m;
5120
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
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
304 #ifdef __cplusplus
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
305 }
a48f3678f9e1 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
diff changeset
306 #endif