annotate test/include/python2.7/pyfpe.h @ 3:7d1a9a91b989 draft

planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
author yating-l
date Thu, 18 May 2017 18:37:28 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
1 #ifndef Py_PYFPE_H
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
2 #define Py_PYFPE_H
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
3 #ifdef __cplusplus
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
4 extern "C" {
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
5 #endif
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
6 /*
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
7 ---------------------------------------------------------------------
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
8 / Copyright (c) 1996. \
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
9 | The Regents of the University of California. |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
10 | All rights reserved. |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
11 | |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
12 | Permission to use, copy, modify, and distribute this software for |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
13 | any purpose without fee is hereby granted, provided that this en- |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
14 | tire notice is included in all copies of any software which is or |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
15 | includes a copy or modification of this software and in all |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
16 | copies of the supporting documentation for such software. |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
17 | |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
18 | This work was produced at the University of California, Lawrence |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
19 | Livermore National Laboratory under contract no. W-7405-ENG-48 |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
20 | between the U.S. Department of Energy and The Regents of the |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
21 | University of California for the operation of UC LLNL. |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
22 | |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
23 | DISCLAIMER |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
24 | |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
25 | This software was prepared as an account of work sponsored by an |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
26 | agency of the United States Government. Neither the United States |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
27 | Government nor the University of California nor any of their em- |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
28 | ployees, makes any warranty, express or implied, or assumes any |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
29 | liability or responsibility for the accuracy, completeness, or |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
30 | usefulness of any information, apparatus, product, or process |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
31 | disclosed, or represents that its use would not infringe |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
32 | privately-owned rights. Reference herein to any specific commer- |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
33 | cial products, process, or service by trade name, trademark, |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
34 | manufacturer, or otherwise, does not necessarily constitute or |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
35 | imply its endorsement, recommendation, or favoring by the United |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
36 | States Government or the University of California. The views and |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
37 | opinions of authors expressed herein do not necessarily state or |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
38 | reflect those of the United States Government or the University |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
39 | of California, and shall not be used for advertising or product |
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
40 \ endorsement purposes. /
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
41 ---------------------------------------------------------------------
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
42 */
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
43
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
44 /*
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
45 * Define macros for handling SIGFPE.
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
46 * Lee Busby, LLNL, November, 1996
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
47 * busby1@llnl.gov
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
48 *
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
49 *********************************************
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
50 * Overview of the system for handling SIGFPE:
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
51 *
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
52 * This file (Include/pyfpe.h) defines a couple of "wrapper" macros for
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
53 * insertion into your Python C code of choice. Their proper use is
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
54 * discussed below. The file Python/pyfpe.c defines a pair of global
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
55 * variables PyFPE_jbuf and PyFPE_counter which are used by the signal
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
56 * handler for SIGFPE to decide if a particular exception was protected
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
57 * by the macros. The signal handler itself, and code for enabling the
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
58 * generation of SIGFPE in the first place, is in a (new) Python module
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
59 * named fpectl. This module is standard in every respect. It can be loaded
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
60 * either statically or dynamically as you choose, and like any other
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
61 * Python module, has no effect until you import it.
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
62 *
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
63 * In the general case, there are three steps toward handling SIGFPE in any
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
64 * Python code:
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
65 *
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
66 * 1) Add the *_PROTECT macros to your C code as required to protect
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
67 * dangerous floating point sections.
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
68 *
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
69 * 2) Turn on the inclusion of the code by adding the ``--with-fpectl''
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
70 * flag at the time you run configure. If the fpectl or other modules
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
71 * which use the *_PROTECT macros are to be dynamically loaded, be
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
72 * sure they are compiled with WANT_SIGFPE_HANDLER defined.
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
73 *
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
74 * 3) When python is built and running, import fpectl, and execute
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
75 * fpectl.turnon_sigfpe(). This sets up the signal handler and enables
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
76 * generation of SIGFPE whenever an exception occurs. From this point
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
77 * on, any properly trapped SIGFPE should result in the Python
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
78 * FloatingPointError exception.
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
79 *
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
80 * Step 1 has been done already for the Python kernel code, and should be
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
81 * done soon for the NumPy array package. Step 2 is usually done once at
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
82 * python install time. Python's behavior with respect to SIGFPE is not
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
83 * changed unless you also do step 3. Thus you can control this new
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
84 * facility at compile time, or run time, or both.
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
85 *
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
86 ********************************
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
87 * Using the macros in your code:
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
88 *
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
89 * static PyObject *foobar(PyObject *self,PyObject *args)
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
90 * {
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
91 * ....
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
92 * PyFPE_START_PROTECT("Error in foobar", return 0)
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
93 * result = dangerous_op(somearg1, somearg2, ...);
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
94 * PyFPE_END_PROTECT(result)
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
95 * ....
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
96 * }
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
97 *
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
98 * If a floating point error occurs in dangerous_op, foobar returns 0 (NULL),
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
99 * after setting the associated value of the FloatingPointError exception to
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
100 * "Error in foobar". ``Dangerous_op'' can be a single operation, or a block
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
101 * of code, function calls, or any combination, so long as no alternate
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
102 * return is possible before the PyFPE_END_PROTECT macro is reached.
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
103 *
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
104 * The macros can only be used in a function context where an error return
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
105 * can be recognized as signaling a Python exception. (Generally, most
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
106 * functions that return a PyObject * will qualify.)
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
107 *
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
108 * Guido's original design suggestion for PyFPE_START_PROTECT and
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
109 * PyFPE_END_PROTECT had them open and close a local block, with a locally
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
110 * defined jmp_buf and jmp_buf pointer. This would allow recursive nesting
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
111 * of the macros. The Ansi C standard makes it clear that such local
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
112 * variables need to be declared with the "volatile" type qualifier to keep
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
113 * setjmp from corrupting their values. Some current implementations seem
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
114 * to be more restrictive. For example, the HPUX man page for setjmp says
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
115 *
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
116 * Upon the return from a setjmp() call caused by a longjmp(), the
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
117 * values of any non-static local variables belonging to the routine
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
118 * from which setjmp() was called are undefined. Code which depends on
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
119 * such values is not guaranteed to be portable.
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
120 *
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
121 * I therefore decided on a more limited form of nesting, using a counter
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
122 * variable (PyFPE_counter) to keep track of any recursion. If an exception
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
123 * occurs in an ``inner'' pair of macros, the return will apparently
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
124 * come from the outermost level.
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
125 *
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
126 */
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
127
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
128 #ifdef WANT_SIGFPE_HANDLER
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
129 #include <signal.h>
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
130 #include <setjmp.h>
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
131 #include <math.h>
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
132 extern jmp_buf PyFPE_jbuf;
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
133 extern int PyFPE_counter;
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
134 extern double PyFPE_dummy(void *);
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
135
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
136 #define PyFPE_START_PROTECT(err_string, leave_stmt) \
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
137 if (!PyFPE_counter++ && setjmp(PyFPE_jbuf)) { \
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
138 PyErr_SetString(PyExc_FloatingPointError, err_string); \
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
139 PyFPE_counter = 0; \
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
140 leave_stmt; \
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
141 }
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
142
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
143 /*
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
144 * This (following) is a heck of a way to decrement a counter. However,
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
145 * unless the macro argument is provided, code optimizers will sometimes move
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
146 * this statement so that it gets executed *before* the unsafe expression
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
147 * which we're trying to protect. That pretty well messes things up,
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
148 * of course.
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
149 *
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
150 * If the expression(s) you're trying to protect don't happen to return a
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
151 * value, you will need to manufacture a dummy result just to preserve the
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
152 * correct ordering of statements. Note that the macro passes the address
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
153 * of its argument (so you need to give it something which is addressable).
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
154 * If your expression returns multiple results, pass the last such result
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
155 * to PyFPE_END_PROTECT.
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
156 *
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
157 * Note that PyFPE_dummy returns a double, which is cast to int.
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
158 * This seeming insanity is to tickle the Floating Point Unit (FPU).
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
159 * If an exception has occurred in a preceding floating point operation,
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
160 * some architectures (notably Intel 80x86) will not deliver the interrupt
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
161 * until the *next* floating point operation. This is painful if you've
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
162 * already decremented PyFPE_counter.
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
163 */
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
164 #define PyFPE_END_PROTECT(v) PyFPE_counter -= (int)PyFPE_dummy(&(v));
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
165
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
166 #else
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
167
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
168 #define PyFPE_START_PROTECT(err_string, leave_stmt)
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
169 #define PyFPE_END_PROTECT(v)
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
170
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
171 #endif
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
172
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
173 #ifdef __cplusplus
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
174 }
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
175 #endif
7d1a9a91b989 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
yating-l
parents:
diff changeset
176 #endif /* !Py_PYFPE_H */