diff options
author | Nathaniel J. Smith <njs@pobox.com> | 2018-01-06 07:15:34 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2018-01-06 07:15:34 (GMT) |
commit | 735ae8d139a673b30b321dc10acfd3d14f0d633b (patch) | |
tree | 027e039ce309a5617d15cdf7f2ef8a1f711fcaaa /Modules | |
parent | 502d551c6d782963d26957a9e5ff1588946f233f (diff) | |
download | cpython-735ae8d139a673b30b321dc10acfd3d14f0d633b.zip cpython-735ae8d139a673b30b321dc10acfd3d14f0d633b.tar.gz cpython-735ae8d139a673b30b321dc10acfd3d14f0d633b.tar.bz2 |
bpo-29137: Remove fpectl module (#4789)
This module has never been enabled by default, never worked correctly
on x86-64, and caused ABI problems that caused C extension
compatibility. See bpo-29137 for details/discussion.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/Setup.dist | 14 | ||||
-rw-r--r-- | Modules/fpectlmodule.c | 255 | ||||
-rw-r--r-- | Modules/fpetestmodule.c | 199 |
3 files changed, 0 insertions, 468 deletions
diff --git a/Modules/Setup.dist b/Modules/Setup.dist index 9c3e1be..1f2d56c 100644 --- a/Modules/Setup.dist +++ b/Modules/Setup.dist @@ -334,20 +334,6 @@ _symtable symtablemodule.c #parser parsermodule.c -# Lee Busby's SIGFPE modules. -# The library to link fpectl with is platform specific. -# Choose *one* of the options below for fpectl: - -# For Solaris with SunPro compiler (tested on Solaris 2.5 with SunPro C 4.2): -# (Without the compiler you don't have -lsunmath.) -#fpectl fpectlmodule.c -R/opt/SUNWspro/lib -lsunmath -lm - -# For other systems: see instructions in fpectlmodule.c. -#fpectl fpectlmodule.c ... - -# Test module for fpectl. No extra libraries needed. -#fpetest fpetestmodule.c - # Andrew Kuchling's zlib module. # This require zlib 1.1.3 (or later). # See http://www.gzip.org/zlib/ diff --git a/Modules/fpectlmodule.c b/Modules/fpectlmodule.c deleted file mode 100644 index 42ef0f6..0000000 --- a/Modules/fpectlmodule.c +++ /dev/null @@ -1,255 +0,0 @@ -/* - --------------------------------------------------------------------- - / Copyright (c) 1996. \ - | The Regents of the University of California. | - | All rights reserved. | - | | - | Permission to use, copy, modify, and distribute this software for | - | any purpose without fee is hereby granted, provided that this en- | - | tire notice is included in all copies of any software which is or | - | includes a copy or modification of this software and in all | - | copies of the supporting documentation for such software. | - | | - | This work was produced at the University of California, Lawrence | - | Livermore National Laboratory under contract no. W-7405-ENG-48 | - | between the U.S. Department of Energy and The Regents of the | - | University of California for the operation of UC LLNL. | - | | - | DISCLAIMER | - | | - | This software was prepared as an account of work sponsored by an | - | agency of the United States Government. Neither the United States | - | Government nor the University of California nor any of their em- | - | ployees, makes any warranty, express or implied, or assumes any | - | liability or responsibility for the accuracy, completeness, or | - | usefulness of any information, apparatus, product, or process | - | disclosed, or represents that its use would not infringe | - | privately-owned rights. Reference herein to any specific commer- | - | cial products, process, or service by trade name, trademark, | - | manufacturer, or otherwise, does not necessarily constitute or | - | imply its endorsement, recommendation, or favoring by the United | - | States Government or the University of California. The views and | - | opinions of authors expressed herein do not necessarily state or | - | reflect those of the United States Government or the University | - | of California, and shall not be used for advertising or product | - \ endorsement purposes. / - --------------------------------------------------------------------- -*/ - -/* - Floating point exception control module. - - This Python module provides bare-bones control over floating point - units from several hardware manufacturers. Specifically, it allows - the user to turn on the generation of SIGFPE whenever any of the - three serious IEEE 754 exceptions (Division by Zero, Overflow, - Invalid Operation) occurs. We currently ignore Underflow and - Inexact Result exceptions, although those could certainly be added - if desired. - - The module also establishes a signal handler for SIGFPE during - initialization. This builds on code found in the Python - distribution at Include/pyfpe.h and Python/pyfpe.c. If those files - are not in your Python distribution, find them in a patch at - ftp://icf.llnl.gov/pub/python/busby/patches.961108.tgz. - - This module is only useful to you if it happens to include code - specific for your hardware and software environment. If you can - contribute OS-specific code for new platforms, or corrections for - the code provided, it will be greatly appreciated. - - ** Version 1.0: September 20, 1996. Lee Busby, LLNL. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "Python.h" -#include <signal.h> - -#if defined(__FreeBSD__) -# include <ieeefp.h> -#endif - -#ifndef WANT_SIGFPE_HANDLER -/* Define locally if they are not defined in Python. This gives only - * the limited control to induce a core dump in case of an exception. - */ -#include <setjmp.h> -static jmp_buf PyFPE_jbuf; -static int PyFPE_counter = 0; -#endif - -typedef void Sigfunc(int); -static Sigfunc sigfpe_handler; -static void fpe_reset(Sigfunc *); - -static PyObject *fpe_error; - -PyMODINIT_FUNC PyInit_fpectl(void); -static PyObject *turnon_sigfpe (PyObject *self,PyObject *args); -static PyObject *turnoff_sigfpe (PyObject *self,PyObject *args); - -static PyMethodDef fpectl_methods[] = { - {"turnon_sigfpe", (PyCFunction) turnon_sigfpe, METH_VARARGS}, - {"turnoff_sigfpe", (PyCFunction) turnoff_sigfpe, METH_VARARGS}, - {0,0} -}; - -static PyObject *turnon_sigfpe(PyObject *self,PyObject *args) -{ - /* Do any architecture-specific one-time only initialization here. */ - - fpe_reset(sigfpe_handler); - Py_RETURN_NONE; -} - -static void fpe_reset(Sigfunc *handler) -{ - /* Reset the exception handling machinery, and reset the signal - * handler for SIGFPE to the given handler. - */ - -/*-- SunOS and Solaris ----------------------------------------------------*/ -#if defined(sun) - /* References: ieee_handler, ieee_sun, ieee_functions, and ieee_flags - man pages (SunOS or Solaris) - cc -c -I/usr/local/python/include fpectlmodule.c - ld -G -o fpectlmodule.so -L/opt/SUNWspro/lib fpectlmodule.o -lsunmath -lm - */ -#include <math.h> -#ifndef _SUNMATH_H - extern void nonstandard_arithmetic(void); - extern int ieee_flags(const char*, const char*, const char*, char **); - extern long ieee_handler(const char*, const char*, sigfpe_handler_type); -#endif - - const char *mode="exception", *in="all"; - char *out; - (void) nonstandard_arithmetic(); - (void) ieee_flags("clearall",mode,in,&out); - (void) ieee_handler("set","common",(sigfpe_handler_type)handler); - PyOS_setsig(SIGFPE, handler); - -/*-- HPUX -----------------------------------------------------------------*/ -#elif defined(__hppa) || defined(hppa) - /* References: fpsetmask man page */ - /* cc -Aa +z -c -I/usr/local/python/include fpectlmodule.c */ - /* ld -b -o fpectlmodule.sl fpectlmodule.o -lm */ -#include <math.h> - fpsetdefaults(); - PyOS_setsig(SIGFPE, handler); - -/*-- IBM AIX --------------------------------------------------------------*/ -#elif defined(__AIX) || defined(_AIX) - /* References: fp_trap, fp_enable man pages */ -#include <fptrap.h> - fp_trap(FP_TRAP_SYNC); - fp_enable(TRP_INVALID | TRP_DIV_BY_ZERO | TRP_OVERFLOW); - PyOS_setsig(SIGFPE, handler); - -/*-- DEC ALPHA LINUX ------------------------------------------------------*/ -#elif defined(__alpha) && defined(linux) -#include <asm/fpu.h> - unsigned long fp_control = - IEEE_TRAP_ENABLE_INV | IEEE_TRAP_ENABLE_DZE | IEEE_TRAP_ENABLE_OVF; - ieee_set_fp_control(fp_control); - PyOS_setsig(SIGFPE, handler); - -/*-- Cray Unicos ----------------------------------------------------------*/ -#elif defined(cray) - /* UNICOS delivers SIGFPE by default, but no matherr */ -#ifdef HAS_LIBMSET - libmset(-1); -#endif - PyOS_setsig(SIGFPE, handler); - -/*-- FreeBSD ----------------------------------------------------------------*/ -#elif defined(__FreeBSD__) - fpresetsticky(fpgetsticky()); - fpsetmask(FP_X_INV | FP_X_DZ | FP_X_OFL); - PyOS_setsig(SIGFPE, handler); - -/*-- Linux ----------------------------------------------------------------*/ -#elif defined(linux) -#ifdef __GLIBC__ -#include <fpu_control.h> -#else -#include <i386/fpu_control.h> -#endif -#ifdef _FPU_SETCW - { - fpu_control_t cw = 0x1372; - _FPU_SETCW(cw); - } -#else - __setfpucw(0x1372); -#endif - PyOS_setsig(SIGFPE, handler); - -/*-- Microsoft Windows, NT ------------------------------------------------*/ -#elif defined(_MSC_VER) - /* Reference: Visual C++ Books Online 4.2, - Run-Time Library Reference, _control87, _controlfp */ -#include <float.h> - unsigned int cw = _EM_INVALID | _EM_ZERODIVIDE | _EM_OVERFLOW; - (void)_controlfp(0, cw); - PyOS_setsig(SIGFPE, handler); - -/*-- Give Up --------------------------------------------------------------*/ -#else - fputs("Operation not implemented\n", stderr); -#endif - -} - -static PyObject *turnoff_sigfpe(PyObject *self,PyObject *args) -{ -#ifdef __FreeBSD__ - fpresetsticky(fpgetsticky()); - fpsetmask(0); -#else - fputs("Operation not implemented\n", stderr); -#endif - Py_RETURN_NONE; -} - -static void sigfpe_handler(int signo) -{ - fpe_reset(sigfpe_handler); - if(PyFPE_counter) { - longjmp(PyFPE_jbuf, 1); - } else { - Py_FatalError("Unprotected floating point exception"); - } -} - -static struct PyModuleDef fpectlmodule = { - PyModuleDef_HEAD_INIT, - "fpectl", - NULL, - -1, - fpectl_methods, - NULL, - NULL, - NULL, - NULL -}; - -PyMODINIT_FUNC PyInit_fpectl(void) -{ - PyObject *m, *d; - m = PyModule_Create(&fpectlmodule); - if (m == NULL) - return NULL; - d = PyModule_GetDict(m); - fpe_error = PyErr_NewException("fpectl.error", NULL, NULL); - if (fpe_error != NULL) - PyDict_SetItemString(d, "error", fpe_error); - return m; -} - -#ifdef __cplusplus -} -#endif diff --git a/Modules/fpetestmodule.c b/Modules/fpetestmodule.c deleted file mode 100644 index 1c232c9..0000000 --- a/Modules/fpetestmodule.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - --------------------------------------------------------------------- - / Copyright (c) 1996. \ - | The Regents of the University of California. | - | All rights reserved. | - | | - | Permission to use, copy, modify, and distribute this software for | - | any purpose without fee is hereby granted, provided that this en- | - | tire notice is included in all copies of any software which is or | - | includes a copy or modification of this software and in all | - | copies of the supporting documentation for such software. | - | | - | This work was produced at the University of California, Lawrence | - | Livermore National Laboratory under contract no. W-7405-ENG-48 | - | between the U.S. Department of Energy and The Regents of the | - | University of California for the operation of UC LLNL. | - | | - | DISCLAIMER | - | | - | This software was prepared as an account of work sponsored by an | - | agency of the United States Government. Neither the United States | - | Government nor the University of California nor any of their em- | - | ployees, makes any warranty, express or implied, or assumes any | - | liability or responsibility for the accuracy, completeness, or | - | usefulness of any information, apparatus, product, or process | - | disclosed, or represents that its use would not infringe | - | privately-owned rights. Reference herein to any specific commer- | - | cial products, process, or service by trade name, trademark, | - | manufacturer, or otherwise, does not necessarily constitute or | - | imply its endorsement, recommendation, or favoring by the United | - | States Government or the University of California. The views and | - | opinions of authors expressed herein do not necessarily state or | - | reflect those of the United States Government or the University | - | of California, and shall not be used for advertising or product | - \ endorsement purposes. / - --------------------------------------------------------------------- -*/ - -/* - Floating point exception test module. - - */ - -#include "Python.h" - -static PyObject *fpe_error; - -PyMODINIT_FUNC PyInit_fpetest(void); -static PyObject *test(PyObject *self,PyObject *args); -static double db0(double); -static double overflow(double); -static double nest1(int, double); -static double nest2(int, double); -static double nest3(double); -static void printerr(double); - -static PyMethodDef fpetest_methods[] = { - {"test", (PyCFunction) test, METH_VARARGS}, - {0,0} -}; - -static PyObject *test(PyObject *self,PyObject *args) -{ - double r; - - fprintf(stderr,"overflow"); - r = overflow(1.e160); - printerr(r); - - fprintf(stderr,"\ndiv by 0"); - r = db0(0.0); - printerr(r); - - fprintf(stderr,"\nnested outer"); - r = nest1(0, 0.0); - printerr(r); - - fprintf(stderr,"\nnested inner"); - r = nest1(1, 1.0); - printerr(r); - - fprintf(stderr,"\ntrailing outer"); - r = nest1(2, 2.0); - printerr(r); - - fprintf(stderr,"\nnested prior"); - r = nest2(0, 0.0); - printerr(r); - - fprintf(stderr,"\nnested interior"); - r = nest2(1, 1.0); - printerr(r); - - fprintf(stderr,"\nnested trailing"); - r = nest2(2, 2.0); - printerr(r); - - Py_RETURN_NONE; -} - -static void printerr(double r) -{ - if(r == 3.1416){ - fprintf(stderr,"\tPASS\n"); - PyErr_Print(); - }else{ - fprintf(stderr,"\tFAIL\n"); - } - PyErr_Clear(); -} - -static double nest1(int i, double x) -{ - double a = 1.0; - - PyFPE_START_PROTECT("Division by zero, outer zone", return 3.1416) - if(i == 0){ - a = 1./x; - }else if(i == 1){ - /* This (following) message is never seen. */ - PyFPE_START_PROTECT("Division by zero, inner zone", return 3.1416) - a = 1./(1. - x); - PyFPE_END_PROTECT(a) - }else if(i == 2){ - a = 1./(2. - x); - } - PyFPE_END_PROTECT(a) - - return a; -} - -static double nest2(int i, double x) -{ - double a = 1.0; - PyFPE_START_PROTECT("Division by zero, prior error", return 3.1416) - if(i == 0){ - a = 1./x; - }else if(i == 1){ - a = nest3(x); - }else if(i == 2){ - a = 1./(2. - x); - } - PyFPE_END_PROTECT(a) - return a; -} - -static double nest3(double x) -{ - double result; - /* This (following) message is never seen. */ - PyFPE_START_PROTECT("Division by zero, nest3 error", return 3.1416) - result = 1./(1. - x); - PyFPE_END_PROTECT(result) - return result; -} - -static double db0(double x) -{ - double a; - PyFPE_START_PROTECT("Division by zero", return 3.1416) - a = 1./x; - PyFPE_END_PROTECT(a) - return a; -} - -static double overflow(double b) -{ - double a; - PyFPE_START_PROTECT("Overflow", return 3.1416) - a = b*b; - PyFPE_END_PROTECT(a) - return a; -} - -static struct PyModuleDef fpetestmodule = { - PyModuleDef_HEAD_INIT, - "fpetest", - NULL, - -1, - fpetest_methods, - NULL, - NULL, - NULL, - NULL -}; - -PyMODINIT_FUNC PyInit_fpetest(void) -{ - PyObject *m, *d; - - m = PyModule_Create(&fpetestmodule); - if (m == NULL) - return NULL; - d = PyModule_GetDict(m); - fpe_error = PyErr_NewException("fpetest.error", NULL, NULL); - if (fpe_error != NULL) - PyDict_SetItemString(d, "error", fpe_error); - return m; -} |