aboutsummaryrefslogtreecommitdiff
path: root/unix/os/zzepro.c
blob: 9f0467165628dcf4b368183b99fe95892ae67d43 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdio.h>
#include <signal.h>
#ifdef MACOSX
#include <math.h>
#include <fenv.h>
#endif
#ifdef CYGWIN
#include <math.h>
#include <mingw/fenv.h>
#endif

#define import_spp
#define import_knames
#include <iraf.h>



#if (defined(MACOSX) && defined(OLD_MACOSX))
void ex_handler ( int, int, struct sigcontext * );
#else
void ex_handler ( int, siginfo_t *, void * );
#endif


/*
 * ZZEPRO.C -- Code which is executed at the end of every procedure.
 */

/* NOTE: Following is also picked up by Mac/Intel. */
#if ( (defined(MACOSX) || defined(CYGWIN)) && !defined(IPAD))

int macosx_sigmask = (FE_DIVBYZERO|FE_OVERFLOW|FE_INVALID);

void mxmask_ (void);
void mxumsk_ (void);


/* ZZEPRO.C -- On MacOSX (which under 10.1.x can't raise a hardware
 * exception) we check at the end of every procedure to see if a floating
 * exception occurred.
 */
int
ZZEPRO (void)
{
	fexcept_t  flagp;

	fegetexceptflag (&flagp, macosx_sigmask);
	if (flagp & macosx_sigmask) {
	    siginfo_t info;
	    info.si_code = (flagp & macosx_sigmask);
	    ex_handler (SIGFPE, &info, NULL);
	}

	/* Clear the exception. */
    	flagp = (fexcept_t) 0;
    	feclearexcept (FE_ALL_EXCEPT);

	return (XOK);
}

/* Mask or unmask the invalid operand exception.  Invalid must be
 * masked to be able to operate upon invalid operands, e.g., to filter
 * out NaN/Inf in IEEE i/o code (see as$ieee.gx).
 */
void mxmask_ (void)
{
	macosx_sigmask &= ~FE_INVALID;
}

void mxumsk_ (void)
{	
	fexcept_t  flagp;

	fegetexceptflag (&flagp, macosx_sigmask);
	macosx_sigmask |=  FE_INVALID;
	flagp &= ~FE_INVALID;
	
	fesetexceptflag (&flagp, macosx_sigmask);
}


#else
int ZZEPRO ( void) { return (XOK); }
#endif