double strtod_with_ovf_bug(const char *s, char **ep) { double ret; fpsetmask(entry_mask); /* traps off */ #undef strtod /* make real strtod visible */ ret = strtod(s, ep); fpsetmask(working_mask); /* traps on */ return ret; }
int test_settings(void) { int failures = 0; fp_except mask_orig; printf("Testing settings on the chip... "); fflush(stdout); fpsetround(FP_RM); if(fpgetround() != FP_RM) FAIL_TEST; fpsetround(FP_RP); if(fpgetround() != FP_RP) FAIL_TEST; fpsetround(FP_RZ); if(fpgetround() != FP_RZ) FAIL_TEST; fpsetround(FP_RN); if(fpgetround() != FP_RN) FAIL_TEST; fpsetsticky(FP_X_INV | FP_X_DZ | FP_X_IMP); if(fpgetsticky() != (FP_X_INV | FP_X_DZ | FP_X_IMP)) FAIL_TEST; fpsetsticky(FP_X_OFL | FP_X_IMP); if(fpgetsticky() != (FP_X_OFL | FP_X_IMP)) FAIL_TEST; fpsetsticky(FP_X_UFL | FP_X_DZ); if(fpgetsticky() != (FP_X_UFL | FP_X_DZ)) FAIL_TEST; fpsetsticky(0); if(fpgetsticky() != 0) FAIL_TEST; mask_orig = fpsetmask(FP_X_INV | FP_X_DZ); if(fpgetmask() != (FP_X_INV | FP_X_DZ)) FAIL_TEST; fpsetmask(FP_X_OFL | FP_X_IMP); if(fpgetmask() != (FP_X_OFL | FP_X_IMP)) FAIL_TEST; fpsetmask(FP_X_UFL | FP_X_DZ | FP_X_INV); if(fpgetmask() != (FP_X_UFL | FP_X_DZ | FP_X_INV)) FAIL_TEST; fpsetmask(mask_orig); if(fpgetmask() != mask_orig) FAIL_TEST; #ifdef __CYGWIN__ fpsetprecision(FP_PC_SGL); if(fpgetprecision() != FP_PC_SGL) FAIL_TEST; fpsetprecision(FP_PC_DBL); if(fpgetprecision() != FP_PC_DBL) FAIL_TEST; fpsetprecision(FP_PC_EXT); if(fpgetprecision() != FP_PC_EXT) FAIL_TEST; #endif if(failures == 0) { printf(" PASSED\n"); return 0; } else { printf(" %d failures\n", failures); return 1; } }
void TclpInitPlatform() { tclPlatform = TCL_PLATFORM_UNIX; /* * The code below causes SIGPIPE (broken pipe) errors to * be ignored. This is needed so that Tcl processes don't * die if they create child processes (e.g. using "exec" or * "open") that terminate prematurely. The signal handler * is only set up when the first interpreter is created; * after this the application can override the handler with * a different one of its own, if it wants. */ #ifdef SIGPIPE (void) signal(SIGPIPE, SIG_IGN); #endif /* SIGPIPE */ #ifdef __FreeBSD__ fpsetround(FP_RN); fpsetmask(0L); #endif #if defined(__bsdi__) && (_BSDI_VERSION > 199501) /* * Find local symbols. Don't report an error if we fail. */ (void) dlopen (NULL, RTLD_NOW); /* INTL: Native. */ #endif }
int nacl_main(int argc, char **argv) { if (nacl_startup_untar(argv[0], DATA_FILE, "/")) return -1; wchar_t **argv_copy; /* We need a second copy, as Python might modify the first one. */ wchar_t **argv_copy2; int i, res; char *oldloc; #ifdef __FreeBSD__ fp_except_t m; #endif argv_copy = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1)); argv_copy2 = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1)); if (!argv_copy || !argv_copy2) { fprintf(stderr, "out of memory\n"); return 1; } /* 754 requires that FP exceptions run in "no stop" mode by default, * and until C vendors implement C99's ways to control FP exceptions, * Python requires non-stop mode. Alas, some platforms enable FP * exceptions by default. Here we disable them. */ #ifdef __FreeBSD__ m = fpgetmask(); fpsetmask(m & ~FP_X_OFL); #endif oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL)); if (!oldloc) { fprintf(stderr, "out of memory\n"); return 1; } setlocale(LC_ALL, ""); for (i = 0; i < argc; i++) { argv_copy[i] = _Py_char2wchar(argv[i], NULL); if (!argv_copy[i]) { PyMem_RawFree(oldloc); fprintf(stderr, "Fatal Python error: " "unable to decode the command line argument #%i\n", i + 1); return 1; } argv_copy2[i] = argv_copy[i]; } argv_copy2[argc] = argv_copy[argc] = NULL; setlocale(LC_ALL, oldloc); PyMem_RawFree(oldloc); res = Py_Main(argc, argv_copy); for (i = 0; i < argc; i++) { PyMem_RawFree(argv_copy2[i]); } PyMem_RawFree(argv_copy); PyMem_RawFree(argv_copy2); return res; }
static void ieee0(bool enableTrap) { TEUCHOS_TEST_FOR_EXCEPTION( enableTrap == false, std::logic_error, "Error, don't know how to turn off trap for SUN!" ); fpsetmask(FP_X_INV); }
void init_ieee_floats(void) { #ifdef __i386__ #ifdef __FreeBSD__ fpsetmask(0); #endif #endif }
/* this enters native floating-point operation: */ void tme_float_enter(int rounding_mode, void (*exception_handler)(int, void *), void *exception_handler_private) { /* lock the native floating-point mutex: */ tme_mutex_lock(&_tme_float_mutex); /* set any user exception handler: */ _tme_float_exception_handler = exception_handler; _tme_float_exception_handler_private = exception_handler_private; /* establish a signal handler: */ /* XXX FIXME this assumes that a handler installed once in one thread will catch signals for all threads. obviously, whether or not this is true depends on how the threads package deals with signals: */ if (!_tme_float_sigfpe_handler_installed) { signal(SIGFPE, _tme_float_sigfpe_handler); _tme_float_sigfpe_handler_installed = TRUE; } /* set the rounding mode: */ #ifdef HAVE_FPSETROUND fpsetround(rounding_mode); #endif /* HAVE_FPSETROUND */ /* clear the exception status: */ _tme_float_exceptions = 0; #ifdef HAVE_FPSETSTICKY fpsetsticky(0); #endif /* HAVE_FPSETSTICKY */ /* unmask all exceptions: */ #ifdef HAVE_FPSETMASK fpsetmask(0 #ifdef FP_X_INV | FP_X_INV #endif #ifdef FP_X_DNML | FP_X_DNML #endif #ifdef FP_X_DZ | FP_X_DZ #endif #ifdef FP_X_OFL | FP_X_OFL #endif #ifdef FP_X_UFL | FP_X_UFL #endif #ifdef FP_X_IMP | FP_X_IMP #endif #ifdef FP_X_IOV | FP_X_IOV #endif ); #endif /* HAVE_FPSETMASK */ }
int main( int argc, char *argv[] ) { char *path; #ifdef __FreeBSD__ fpsetmask(0); #endif SystemInit(&argc, argv); path = getFullPath("settings.txt"); if(path != 0) initMainGameSettings(path); /* reads defaults from ~/.gltronrc */ else { printf("fatal: could not settings.txt, exiting...\n"); exit(1); } parse_args(argc, argv); /* sound */ #ifdef SOUND printf("initializing sound\n"); initSound(); path = getFullPath("gltron.it"); if(path == 0 || loadSound(path)) printf("error trying to load sound\n"); else { if(game->settings->playMusic) playSound(); free(path); } #endif printf("loading menu\n"); path = getFullPath("menu.txt"); if(path != 0) pMenuList = loadMenuFile(path); else { printf("fatal: could not load menu.txt, exiting...\n"); exit(1); } printf("menu loaded\n"); free(path); initGameStructures(); resetScores(); initData(); setupDisplay(game->screen); switchCallbacks(&guiCallbacks); switchCallbacks(&guiCallbacks); SystemMainLoop(); return 0; }
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 check_strtod_ovf(void) { #ifdef USE_IEEEFP_H fpsetmask(fpgetmask() | FP_X_OFL | FP_X_DZ); #endif checking_for_strtod_ovf_bug = 1; strtod(longstr, (char **) 0); exit(0); }
void fpu_setup(Rboolean start) { if (start) { #ifdef __FreeBSD__ fpsetmask(0); #endif #ifdef NEED___SETFPUCW __setfpucw(_FPU_IEEE); #endif } else { #ifdef __FreeBSD__ fpsetmask(~0); #endif #ifdef NEED___SETFPUCW __setfpucw(_FPU_DEFAULT); #endif } }
/* * The fesetenv() function shall attempt to establish the floating-point * environment represented by the object pointed to by envp. The fesetenv() * function does not raise floating-point exceptions, but only installs the * state of the floating-point status flags represented through its argument. */ int fesetenv(const fenv_t *envp) { #ifdef __SOFTFP__ (void)fpsetround(__SHIFTIN(*envp, VFP_FPSCR_RMODE)); (void)fpsetmask(__SHIFTOUT(*envp, VFP_FPSCR_ESUM)); (void)fpsetsticky(__SHIFTOUT(*envp, VFP_FPSCR_CSUM)); #else armreg_fpscr_write(*envp); #endif return 0; }
/* exported for Rembedded.h */ void fpu_setup(Rboolean start) { if (start) { #ifdef __FreeBSD__ fpsetmask(0); #endif #ifdef NEED___SETFPUCW __setfpucw(_FPU_IEEE); #endif #if (defined(__i386) || defined(__x86_64)) && defined(__INTEL_COMPILER) && __INTEL_COMPILER > 800 _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_OFF); _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_OFF); #endif } else { #ifdef __FreeBSD__ fpsetmask(~0); #endif #ifdef NEED___SETFPUCW __setfpucw(_FPU_DEFAULT); #endif } }
/* * The feholdexcept() function shall save the current floating-point * environment in the object pointed to by envp, clear the floating-point * status flags, and then install a non-stop (continue on floating-point * exceptions) mode, if available, for all floating-point exceptions. */ int feholdexcept(fenv_t *envp) { #ifdef __SOFTFP__ *envp = __SHIFTIN(fpgetround(), VFP_FPSCR_RMODE) | __SHIFTIN(fpgetmask(), VFP_FPSCR_ESUM) | __SHIFTIN(fpgetsticky(), VFP_FPSCR_CSUM); fpsetmask(0); fpsetsticky(0); #else *envp = armreg_fpscr_read(); armreg_fpscr_write((*envp) & ~(VFP_FPSCR_ESUM|VFP_FPSCR_CSUM)); #endif return 0; }
int fedisableexcept(int excepts) { #ifndef lint _DIAGASSERT((except & ~FE_ALL_EXCEPT) == 0); #endif #ifdef __SOFTFP__ int old = fpgetmask(); fpsetmask(old & ~excepts); return old; #else int fpscr = armreg_fpscr_read(); armreg_fpscr_write(fpscr & ~__SHIFTIN((excepts), VFP_FPSCR_ESUM)); return __SHIFTOUT(fpscr, VFP_FPSCR_ESUM) & FE_ALL_EXCEPT; #endif }
static PyObject *turnoff_sigfpe(PyObject *self,PyObject *args) { #ifdef __FreeBSD__ fpresetsticky(fpgetsticky()); fpsetmask(0); #elif defined(__VMS) IEEE clrmsk; clrmsk.ieee$q_flags = IEEE$M_TRAP_ENABLE_UNF | IEEE$M_TRAP_ENABLE_INE | IEEE$M_MAP_UMZ | IEEE$M_TRAP_ENABLE_INV | IEEE$M_TRAP_ENABLE_DZE | IEEE$M_TRAP_ENABLE_OVF | IEEE$M_INHERIT; sys$ieee_set_fp_control(&clrmsk, 0, 0); #else fputs("Operation not implemented\n", stderr); #endif Py_INCREF(Py_None); return Py_None; }
/* * The feupdateenv() function shall attempt to save the currently raised * floating-point exceptions in its automatic storage, attempt to install the * floating-point environment represented by the object pointed to by envp, * and then attempt to raise the saved floating-point exceptions. */ int feupdateenv(const fenv_t *envp) { #ifndef lint _DIAGASSERT(envp != NULL); #endif #ifdef __SOFTFP__ (void)fpsetround(__SHIFTIN(*envp, VFP_FPSCR_RMODE)); (void)fpsetmask(fpgetmask() | __SHIFTOUT(*envp, VFP_FPSCR_ESUM)); (void)fpsetsticky(fpgetsticky() | __SHIFTOUT(*envp, VFP_FPSCR_CSUM)); #else int fpscr = armreg_fpscr_read() & ~(VFP_FPSCR_ESUM|VFP_FPSCR_CSUM); fpscr |= *envp; armreg_fpscr_write(fpscr); #endif /* Success */ return 0; }
ATF_TC_BODY(sigfpe_int, tc) { struct sigaction sa; long l = strtol("0", NULL, 10); if (strcmp(atf_config_get("atf_arch"),"powerpc") == 0) atf_tc_skip("Test not valid on powerpc"); if (sigsetjmp(sigfpe_int_env, 0) == 0) { sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = sigfpe_int_action; sigemptyset(&sa.sa_mask); sigaction(SIGFPE, &sa, NULL); #ifdef _FLOAT_IEEE754 fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP); #endif printf("%ld\n", 1 / l); } if (intdiv_signalled == 0) atf_tc_fail("FPE signal handler was not invoked"); }
int main(int argc, char **argv) { wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc); /* We need a second copies, as Python might modify the first one. */ wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc); int i, res; char *oldloc; /* 754 requires that FP exceptions run in "no stop" mode by default, * and until C vendors implement C99's ways to control FP exceptions, * Python requires non-stop mode. Alas, some platforms enable FP * exceptions by default. Here we disable them. */ #ifdef __FreeBSD__ fp_except_t m; m = fpgetmask(); fpsetmask(m & ~FP_X_OFL); #endif if (!argv_copy || !argv_copy2) { fprintf(stderr, "out of memory\n"); return 1; } oldloc = strdup(setlocale(LC_ALL, NULL)); setlocale(LC_ALL, ""); for (i = 0; i < argc; i++) { argv_copy2[i] = argv_copy[i] = char2wchar(argv[i]); if (!argv_copy[i]) return 1; } setlocale(LC_ALL, oldloc); free(oldloc); res = Py_Main(argc, argv_copy); for (i = 0; i < argc; i++) { PyMem_Free(argv_copy2[i]); } PyMem_Free(argv_copy); PyMem_Free(argv_copy2); return res; }
ATF_TC_BODY(sigfpe_flt, tc) { struct sigaction sa; double d = strtod("0", NULL); if (isQEMU()) atf_tc_skip("Test does not run correctly under QEMU"); if (strcmp(atf_config_get("atf_arch"),"powerpc") == 0) atf_tc_skip("Test not valid on powerpc"); if (sigsetjmp(sigfpe_flt_env, 0) == 0) { sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = sigfpe_flt_action; sigemptyset(&sa.sa_mask); sigaction(SIGFPE, &sa, NULL); #ifdef _FLOAT_IEEE754 fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP); #endif printf("%g\n", 1 / d); } if (fltdiv_signalled == 0) atf_tc_fail("FPE signal handler was not invoked"); }
Env::Env() { strcpy(systemname, "unknown"); strcpy(releasename, "unknown"); strcpy(machinename, "unknown"); // Set some process attributes #ifdef DMALLOC_FUNC_CHECK //dmalloc_verify(0L); #endif #if HAVE_NICE nice(10); #endif #if HAVE_FPSETMASK fpsetmask(0L); // What is it for ? (BD) #endif #if HAVE_SETLOCALE setlocale(LC_ALL, "C"); // Unix traditionnal #endif sysinfo(); initDirs(); }
void RealArithmetic::Init(void) { /* Some compilers object to overflow in constants so we compute the values here. */ #if (HAVE_DECL_FPSETMASK && ! defined(__CYGWIN__)) /* In FreeBSD 3.4 at least, we sometimes get floating point exceptions if we don't clear the mask. Maybe need to do this on other platforms as well just to be sure. */ // N.B. fpsetmask is defined in the headers on Cygwin but there's no function! fpsetmask(0); #endif // NAN and INFINITY are defined in GCC but not in Visual C++. #if (defined(INFINITY)) posInf = INFINITY; negInf = -(INFINITY); #else { double zero = 0.0; posInf = 1.0 / zero; negInf = -1.0 / zero; } #endif #if (defined(NAN)) notANumber = NAN; #else { double zero = 0.0; notANumber = zero / zero; } #endif // Make sure this is a positive NaN since we return it from "abs". // "Positive" in this context is copysign(1.0, x) > 0.0 because that's // how we test the sign so we test it first and then try to change the // sign if it's wrong. if (copysign(1.0, notANumber) < 0) notANumber = copysign(notANumber, 1.0); }
int main( int argc, char *argv[]) { char **myargv; char *aLine; char *firstdir = ""; #ifdef MUST_DISABLE_SIGFPE signal(SIGFPE, SIG_IGN); #endif #ifdef MUST_DISABLE_FPMASK fpsetmask(0); #endif /* initialize locale settings according to localeconv(3) */ setlocale(LC_ALL, ""); #if defined(WIN32) && !defined(__CYGWIN__) setmode(fileno(stdout), O_BINARY); setmode(fileno(stdin), O_BINARY); #endif #if defined(HAVE_LIBINTL_H) && defined(BUILD_LIBINTL) bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); textdomain(GETTEXT_PACKAGE); #endif if (argc == 1) { PrintUsage(""); return 0; } if (((argc == 2) || (argc == 3)) && !strcmp("-", argv[1])) { #if HAVE_GETRUSAGE struct rusage myusage; struct timeval starttime; struct timeval currenttime; gettimeofday(&starttime, NULL); #endif RemoteMode = 1; if ((argc == 3) && strcmp("", argv[2])) { if ( #ifdef HAVE_GETUID getuid() #else 1 #endif == 0) { #ifdef HAVE_CHROOT if (chroot(argv[2]) != 0){ fprintf(stderr, "ERROR: chroot %s: %s\n", argv[2],rrd_strerror(errno)); exit(errno); } ChangeRoot = 1; firstdir = "/"; #else fprintf(stderr, "ERROR: change root is not supported by your OS " "or at least by this copy of rrdtool\n"); exit(1); #endif } else { firstdir = argv[2]; } } if (strcmp(firstdir, "")) { if (chdir(firstdir) != 0){ fprintf(stderr, "ERROR: chdir %s %s\n", firstdir,rrd_strerror(errno)); exit(errno); } } while (fgetslong(&aLine, stdin)) { char *aLineOrig = aLine; if ((argc = CountArgs(aLine)) == 0) { free(aLine); printf("ERROR: not enough arguments\n"); continue; } if ((myargv = (char **) malloc((argc + 1) * sizeof(char *))) == NULL) { perror("malloc"); exit(1); } if ((argc = CreateArgs(argv[0], aLine, myargv)) < 0) { printf("ERROR: creating arguments\n"); } else { if ( HandleInputLine(argc, myargv, stdout) == 0 ){ #if HAVE_GETRUSAGE getrusage(RUSAGE_SELF, &myusage); gettimeofday(¤ttime, NULL); printf("OK u:%1.2f s:%1.2f r:%1.2f\n", (double) myusage.ru_utime.tv_sec + (double) myusage.ru_utime.tv_usec / 1000000.0, (double) myusage.ru_stime.tv_sec + (double) myusage.ru_stime.tv_usec / 1000000.0, (double) (currenttime.tv_sec - starttime.tv_sec) + (double) (currenttime.tv_usec - starttime.tv_usec) / 1000000.0); #else printf("OK\n"); #endif } } fflush(stdout); /* this is important for pipes to work */ free(myargv); free(aLineOrig); } } else if (argc == 2) { PrintUsage(argv[1]); exit(0); } else if (argc == 3 && !strcmp(argv[1], "help")) { PrintUsage(argv[2]); exit(0); } else { exit(HandleInputLine(argc, argv, stderr)); } return 0; }
int gsl_ieee_set_mode (int precision, int rounding, int exception_mask) { fp_prec_t prec = 0 ; fp_except_t mode = 0 ; fp_rnd_t rnd = 0 ; switch (precision) { case GSL_IEEE_SINGLE_PRECISION: prec = FP_PS; fpsetprec(prec); break ; case GSL_IEEE_DOUBLE_PRECISION: prec = FP_PD; fpsetprec(prec); break ; case GSL_IEEE_EXTENDED_PRECISION: prec = FP_PE; fpsetprec(prec); break ; } switch (rounding) { case GSL_IEEE_ROUND_TO_NEAREST: rnd = FP_RN ; fpsetround (rnd) ; break ; case GSL_IEEE_ROUND_DOWN: rnd = FP_RM ; fpsetround (rnd) ; break ; case GSL_IEEE_ROUND_UP: rnd = FP_RP ; fpsetround (rnd) ; break ; case GSL_IEEE_ROUND_TO_ZERO: rnd = FP_RZ ; fpsetround (rnd) ; break ; default: rnd = FP_RN ; fpsetround (rnd) ; } /* Turn on all the exceptions apart from 'inexact' */ mode = FP_X_INV | FP_X_DNML | FP_X_DZ | FP_X_OFL | FP_X_UFL ; if (exception_mask & GSL_IEEE_MASK_INVALID) mode &= ~ FP_X_INV ; if (exception_mask & GSL_IEEE_MASK_DENORMALIZED) mode &= ~ FP_X_DNML ; if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO) mode &= ~ FP_X_DZ ; if (exception_mask & GSL_IEEE_MASK_OVERFLOW) mode &= ~ FP_X_OFL ; if (exception_mask & GSL_IEEE_MASK_UNDERFLOW) mode &= ~ FP_X_UFL ; if (exception_mask & GSL_IEEE_TRAP_INEXACT) { mode |= FP_X_IMP ; } else { mode &= ~ FP_X_IMP ; } fpsetmask (mode) ; return GSL_SUCCESS ; }
static int setup_fpu(int doINV, int doOFL) { #if defined(WIN32) /* Win32 uses _controlfp() */ unsigned int mask = _controlfp(0,0); fpe_inv = doINV; fpe_ofl = doOFL; if (doINV) mask&=(~_EM_INVALID); else mask|=(_EM_INVALID); if (doOFL) mask&=(~_EM_OVERFLOW); else mask|=(_EM_OVERFLOW); if (doOFL) mask&=(~_EM_ZERODIVIDE); else mask|=(_EM_ZERODIVIDE); _controlfp(mask, _MCW_EM); return 1; #elif defined(HAVE_FPSETMASK) /* SysVr4 defines fpsetmask() */ int mask = 0; fpe_inv = doINV; fpe_ofl = doOFL; #ifdef FP_X_INV if (doINV) mask |= FP_X_INV; #endif #ifdef FP_X_OFL if (doOFL) mask |= FP_X_OFL; #endif #ifdef FP_X_DZ if (doOFL) mask |= FP_X_DZ; #endif fpsetmask( mask ); return 1; #elif defined(HAVE_FENV_H) && defined(HAVE_FEENABLEEXCEPT) /* GLIBC-2.2 model */ int mask1 = 0; int mask2 = 0; fpe_inv = doINV; fpe_ofl = doOFL; #ifdef FE_INVALID if (doINV) mask1 |= FE_INVALID; else mask2 |= FE_INVALID; #endif #ifdef FE_DIVBYZERO if (doOFL) mask1 |= FE_DIVBYZERO; else mask2 |= FE_DIVBYZERO; #endif #ifdef FE_OVERFLOW if (doOFL) mask1 |= FE_OVERFLOW; else mask2 |= FE_OVERFLOW; #endif feenableexcept(mask1); fedisableexcept(mask2); return 1; #elif defined(HAVE_FPU_CONTROL_H) /* Older GLIBC */ int mask = 0; fpe_inv = doINV; fpe_ofl = doOFL; #ifdef _FPU_DEFAULT mask = _FPU_DEFAULT; #endif #define DO(c,f) mask=((c)?(mask|(f)):(mask&~(f))); #if defined(__i386__) || defined(__alpha__) #ifdef _FPU_MASK_IM DO(!doINV, _FPU_MASK_IM); #endif #ifdef _FPU_MASK_OM DO(!doOFL, _FPU_MASK_OM); #endif #ifdef _FPU_MASK_ZM DO(!doOFL, _FPU_MASK_ZM); #endif #else #ifdef _FPU_MASK_IM DO(doINV, _FPU_MASK_IM); #endif #ifdef _FPU_MASK_OM DO(doOFL, _FPU_MASK_OM); #endif #ifdef _FPU_MASK_ZM DO(doOFL, _FPU_MASK_ZM); #endif #ifdef _FPU_MASK_V DO(doINV, _FPU_MASK_V); #endif #ifdef _FPU_MASK_O DO(doOFL, _FPU_MASK_O); #endif #ifdef _FPU_MASK_Z DO(doOFL, _FPU_MASK_Z); #endif #ifdef _FPU_MASK_OPERR DO(doINV, _FPU_MASK_OPERR); #endif #ifdef _FPU_MASK_OVFL DO(doOFL, _FPU_MASK_OPERR); #endif #ifdef _FPU_MASK_DZ DO(doOFL, _FPU_MASK_DZ); #endif #endif /* continue */ #if defined(HAVE___SETFPUCW) __setfpucw( mask ); return 1; #elif defined(_FPU_SETCW) _FPU_SETCW( mask ); return 1; #undef DO #endif #endif /* Default */ return 0; }
int zend_startup(zend_utility_functions *utility_functions, char **extensions) /* {{{ */ { #ifdef ZTS zend_compiler_globals *compiler_globals; zend_executor_globals *executor_globals; extern ZEND_API ts_rsrc_id ini_scanner_globals_id; extern ZEND_API ts_rsrc_id language_scanner_globals_id; ZEND_TSRMLS_CACHE_UPDATE(); #else extern zend_ini_scanner_globals ini_scanner_globals; extern zend_php_scanner_globals language_scanner_globals; #endif start_memory_manager(); virtual_cwd_startup(); /* Could use shutdown to free the main cwd but it would just slow it down for CGI */ #if defined(__FreeBSD__) || defined(__DragonFly__) /* FreeBSD and DragonFly floating point precision fix */ fpsetmask(0); #endif zend_startup_strtod(); zend_startup_extensions_mechanism(); /* Set up utility functions and values */ zend_error_cb = utility_functions->error_function; zend_printf = utility_functions->printf_function; zend_write = (zend_write_func_t) utility_functions->write_function; zend_fopen = utility_functions->fopen_function; if (!zend_fopen) { zend_fopen = zend_fopen_wrapper; } zend_stream_open_function = utility_functions->stream_open_function; zend_message_dispatcher_p = utility_functions->message_handler; #ifndef ZEND_SIGNALS zend_block_interruptions = utility_functions->block_interruptions; zend_unblock_interruptions = utility_functions->unblock_interruptions; #endif zend_get_configuration_directive_p = utility_functions->get_configuration_directive; zend_ticks_function = utility_functions->ticks_function; zend_on_timeout = utility_functions->on_timeout; zend_vspprintf = utility_functions->vspprintf_function; zend_vstrpprintf = utility_functions->vstrpprintf_function; zend_getenv = utility_functions->getenv_function; zend_resolve_path = utility_functions->resolve_path_function; #if HAVE_DTRACE /* build with dtrace support */ zend_compile_file = dtrace_compile_file; zend_execute_ex = dtrace_execute_ex; zend_execute_internal = dtrace_execute_internal; #else zend_compile_file = compile_file; zend_execute_ex = execute_ex; zend_execute_internal = NULL; #endif /* HAVE_SYS_SDT_H */ zend_compile_string = compile_string; zend_throw_exception_hook = NULL; /* Set up the default garbage collection implementation. */ gc_collect_cycles = zend_gc_collect_cycles; zend_init_opcodes_handlers(); /* set up version */ zend_version_info = strdup(ZEND_CORE_VERSION_INFO); zend_version_info_length = sizeof(ZEND_CORE_VERSION_INFO) - 1; GLOBAL_FUNCTION_TABLE = (HashTable *) malloc(sizeof(HashTable)); GLOBAL_CLASS_TABLE = (HashTable *) malloc(sizeof(HashTable)); GLOBAL_AUTO_GLOBALS_TABLE = (HashTable *) malloc(sizeof(HashTable)); GLOBAL_CONSTANTS_TABLE = (HashTable *) malloc(sizeof(HashTable)); zend_hash_init_ex(GLOBAL_FUNCTION_TABLE, 1024, NULL, ZEND_FUNCTION_DTOR, 1, 0); zend_hash_init_ex(GLOBAL_CLASS_TABLE, 64, NULL, ZEND_CLASS_DTOR, 1, 0); zend_hash_init_ex(GLOBAL_AUTO_GLOBALS_TABLE, 8, NULL, auto_global_dtor, 1, 0); zend_hash_init_ex(GLOBAL_CONSTANTS_TABLE, 128, NULL, ZEND_CONSTANT_DTOR, 1, 0); zend_hash_init_ex(&module_registry, 32, NULL, module_destructor_zval, 1, 0); zend_init_rsrc_list_dtors(); #ifdef ZTS ts_allocate_id(&compiler_globals_id, sizeof(zend_compiler_globals), (ts_allocate_ctor) compiler_globals_ctor, (ts_allocate_dtor) compiler_globals_dtor); ts_allocate_id(&executor_globals_id, sizeof(zend_executor_globals), (ts_allocate_ctor) executor_globals_ctor, (ts_allocate_dtor) executor_globals_dtor); ts_allocate_id(&language_scanner_globals_id, sizeof(zend_php_scanner_globals), (ts_allocate_ctor) php_scanner_globals_ctor, NULL); ts_allocate_id(&ini_scanner_globals_id, sizeof(zend_ini_scanner_globals), (ts_allocate_ctor) ini_scanner_globals_ctor, NULL); compiler_globals = ts_resource(compiler_globals_id); executor_globals = ts_resource(executor_globals_id); compiler_globals_dtor(compiler_globals); compiler_globals->in_compilation = 0; compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable)); compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable)); *compiler_globals->function_table = *GLOBAL_FUNCTION_TABLE; *compiler_globals->class_table = *GLOBAL_CLASS_TABLE; compiler_globals->auto_globals = GLOBAL_AUTO_GLOBALS_TABLE; zend_hash_destroy(executor_globals->zend_constants); *executor_globals->zend_constants = *GLOBAL_CONSTANTS_TABLE; #else ini_scanner_globals_ctor(&ini_scanner_globals); php_scanner_globals_ctor(&language_scanner_globals); zend_set_default_compile_time_values(); #ifdef ZEND_WIN32 zend_get_windows_version_info(&EG(windows_version_info)); #endif #endif EG(error_reporting) = E_ALL & ~E_NOTICE; zend_interned_strings_init(); zend_startup_builtin_functions(); zend_register_standard_constants(); zend_register_auto_global(zend_string_init("GLOBALS", sizeof("GLOBALS") - 1, 1), 1, php_auto_globals_create_globals); #ifndef ZTS zend_init_rsrc_plist(); zend_init_exception_op(); zend_init_call_trampoline_op(); #endif zend_ini_startup(); #ifdef ZTS tsrm_set_new_thread_end_handler(zend_new_thread_end_handler); #endif return SUCCESS; }
FPEnvironmentImpl::~FPEnvironmentImpl() { fpsetround(_rnd); fpsetmask(_exc); }
void FPEnvironmentImpl::keepCurrentImpl() { fpsetround(_rnd); fpsetmask(_exc); }
void TclpInitPlatform(void) { #ifdef DJGPP tclPlatform = TCL_PLATFORM_WINDOWS; #else tclPlatform = TCL_PLATFORM_UNIX; #endif /* * Make sure, that the standard FDs exist. [Bug 772288] */ if (TclOSseek(0, (Tcl_SeekOffset) 0, SEEK_CUR) == -1 && errno == EBADF) { open("/dev/null", O_RDONLY); } if (TclOSseek(1, (Tcl_SeekOffset) 0, SEEK_CUR) == -1 && errno == EBADF) { open("/dev/null", O_WRONLY); } if (TclOSseek(2, (Tcl_SeekOffset) 0, SEEK_CUR) == -1 && errno == EBADF) { open("/dev/null", O_WRONLY); } /* * The code below causes SIGPIPE (broken pipe) errors to be ignored. This * is needed so that Tcl processes don't die if they create child * processes (e.g. using "exec" or "open") that terminate prematurely. * The signal handler is only set up when the first interpreter is * created; after this the application can override the handler with a * different one of its own, if it wants. */ #ifdef SIGPIPE (void) signal(SIGPIPE, SIG_IGN); #endif /* SIGPIPE */ #if defined(__FreeBSD__) && defined(__GNUC__) /* * Adjust the rounding mode to be more conventional. Note that FreeBSD * only provides the __fpsetreg() used by the following two for the GNU * Compiler. When using, say, Intel's icc they break. (Partially based on * patch in BSD ports system from [email protected]) */ fpsetround(FP_RN); (void) fpsetmask(0L); #endif #if defined(__bsdi__) && (_BSDI_VERSION > 199501) /* * Find local symbols. Don't report an error if we fail. */ (void) dlopen(NULL, RTLD_NOW); /* INTL: Native. */ #endif /* * Initialize the C library's locale subsystem. This is required for input * methods to work properly on X11. We only do this for LC_CTYPE because * that's the necessary one, and we don't want to affect LC_TIME here. * The side effect of setting the default locale should be to load any * locale specific modules that are needed by X. [BUG: 5422 3345 4236 2522 * 2521]. */ setlocale(LC_CTYPE, ""); /* * In case the initial locale is not "C", ensure that the numeric * processing is done in "C" locale regardless. This is needed because Tcl * relies on routines like strtod, but should not have locale dependent * behavior. */ setlocale(LC_NUMERIC, "C"); #ifdef GET_DARWIN_RELEASE { struct utsname name; if (!uname(&name)) { tclMacOSXDarwinRelease = strtol(name.release, NULL, 10); } } #endif }
int gsl_ieee_set_mode (int precision, int rounding, int exception_mask) { fp_except mode = 0; fp_rnd rnd = 0; switch (precision) { case GSL_IEEE_SINGLE_PRECISION: GSL_ERROR ("OpenBSD only supports default precision rounding", GSL_EUNSUP); break; case GSL_IEEE_DOUBLE_PRECISION: GSL_ERROR ("OpenBSD only supports default precision rounding", GSL_EUNSUP); break; case GSL_IEEE_EXTENDED_PRECISION: GSL_ERROR ("OpenBSD only supports default precision rounding", GSL_EUNSUP); break; } switch (rounding) { case GSL_IEEE_ROUND_TO_NEAREST: rnd = FP_RN; fpsetround (rnd); break; case GSL_IEEE_ROUND_DOWN: rnd = FP_RM; fpsetround (rnd); break; case GSL_IEEE_ROUND_UP: rnd = FP_RP; fpsetround (rnd); break; case GSL_IEEE_ROUND_TO_ZERO: rnd = FP_RZ; fpsetround (rnd); break; default: rnd = FP_RN; fpsetround (rnd); } /* Turn on all available exceptions apart from 'inexact'. Denormalized operand exception not available on all platforms. */ mode = FP_X_INV | FP_X_DZ | FP_X_OFL | FP_X_UFL; #ifdef FP_X_DNML mode = mode | FP_X_DNML; #endif if (exception_mask & GSL_IEEE_MASK_INVALID) mode &= ~ FP_X_INV; if (exception_mask & GSL_IEEE_MASK_DENORMALIZED) { #ifdef FP_X_DNML mode &= ~ FP_X_DNML; #endif } else { #ifndef FP_X_DNML GSL_ERROR ("OpenBSD does not support the denormalized operand exception on this platform. " "Use 'mask-denormalized' to work around this.", GSL_EUNSUP); #endif } if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO) mode &= ~ FP_X_DZ; if (exception_mask & GSL_IEEE_MASK_OVERFLOW) mode &= ~ FP_X_OFL; if (exception_mask & GSL_IEEE_MASK_UNDERFLOW) mode &= ~ FP_X_UFL; if (exception_mask & GSL_IEEE_TRAP_INEXACT) { mode |= FP_X_IMP; } else { mode &= ~ FP_X_IMP; } fpsetmask (mode); return GSL_SUCCESS; }