2544
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2544
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_f77_fcn_h) |
|
24 #define octave_f77_fcn_h 1 |
|
25 |
4268
|
26 #include "quit.h" |
|
27 |
2544
|
28 #ifdef __cplusplus |
|
29 extern "C" { |
|
30 #endif |
|
31 |
4153
|
32 /* Hack to stringize macro results. */ |
3887
|
33 #define xSTRINGIZE(x) #x |
|
34 #define STRINGIZE(x) xSTRINGIZE(x) |
2544
|
35 |
|
36 /* How to print an error for the F77_XFCN macro. */ |
|
37 |
|
38 #define F77_XFCN_ERROR(f, F) \ |
|
39 (*current_liboctave_error_handler) \ |
3887
|
40 ("exception encountered in Fortran subroutine %s", \ |
|
41 STRINGIZE (F77_FUNC (f, F))) |
2544
|
42 |
|
43 /* This can be used to call a Fortran subroutine that might call |
4153
|
44 XSTOPX. XSTOPX will call lonjmp with current_context. Once back |
|
45 here, we'll restore the previous context and return. We may also |
|
46 end up here if an interrupt is processed when the Fortran |
|
47 subroutine is called. In that case, we resotre the context and go |
|
48 to the top level. The error_state should be checked immediately |
|
49 after this macro is used. */ |
2544
|
50 |
|
51 #define F77_XFCN(f, F, args) \ |
|
52 do \ |
|
53 { \ |
4182
|
54 octave_jmp_buf saved_context; \ |
2544
|
55 f77_exception_encountered = 0; \ |
4153
|
56 octave_save_current_context ((char *) saved_context); \ |
|
57 if (octave_set_current_context) \ |
2544
|
58 { \ |
4153
|
59 octave_restore_current_context ((char *) saved_context); \ |
|
60 if (f77_exception_encountered) \ |
|
61 F77_XFCN_ERROR (f, F); \ |
4180
|
62 else if (octave_allocation_error) \ |
4182
|
63 octave_throw_bad_alloc (); \ |
4153
|
64 else \ |
4182
|
65 octave_throw_interrupt_exception (); \ |
2544
|
66 } \ |
|
67 else \ |
4153
|
68 { \ |
4182
|
69 octave_interrupt_immediately++; \ |
4153
|
70 F77_FUNC (f, F) args; \ |
4182
|
71 octave_interrupt_immediately--; \ |
4153
|
72 octave_restore_current_context ((char *) saved_context); \ |
|
73 } \ |
2544
|
74 } \ |
|
75 while (0) |
|
76 |
|
77 /* So we can check to see if an exception has occurred. */ |
|
78 extern int f77_exception_encountered; |
|
79 |
3938
|
80 #if !defined (F77_FCN) |
|
81 #define F77_FCN(f, F) F77_FUNC (f, F) |
|
82 #endif |
|
83 |
4552
|
84 #if defined (F77_USES_CRAY_CALLING_CONVENTION) |
|
85 |
|
86 #include <fortran.h> |
|
87 #define F77_CHAR_ARG(x) octave_make_cray_ftn_ch_dsc (x, strlen (x)) |
|
88 #define F77_CONST_CHAR_ARG(x) \ |
|
89 octave_make_cray_const_ftn_ch_dsc (x, strlen (x)) |
|
90 #define F77_CHAR_ARG2(x, l) octave_make_cray_fcd (x, l) |
|
91 #define F77_CONST_CHAR_ARG2(x, l) octave_make_cray_const_fcd (x, l) |
|
92 #define F77_CXX_STRING_ARG(x) \ |
|
93 octave_make_cray_const_ftn_ch_dsc (x.c_str (), x.length ()) |
|
94 #define F77_CHAR_ARG_LEN(l) |
|
95 #define F77_CHAR_ARG_DECL octave_cray_fcd |
|
96 #define F77_CONST_CHAR_ARG_DECL octave_cray_fcd |
|
97 #define F77_CHAR_ARG_LEN_DECL |
|
98 #define F77_RET_T int |
|
99 #define F77_RETURN(retval) return retval; |
|
100 |
4572
|
101 /* XXX FIXME XXX -- these should work for SV1 or Y-MP systems but will |
|
102 need to be changed for others. */ |
4552
|
103 |
4558
|
104 typedef union |
4552
|
105 { |
4558
|
106 const char *const_ptr; |
|
107 char *ptr; |
4552
|
108 struct |
|
109 { |
|
110 unsigned off : 6; |
|
111 unsigned len : 26; |
|
112 unsigned add : 32; |
|
113 } mask; |
4558
|
114 } octave_cray_descriptor; |
4552
|
115 |
|
116 typedef void *octave_cray_ftn_ch_dsc; |
|
117 |
4555
|
118 #ifdef __cplusplus |
|
119 #define OCTAVE_F77_FCN_INLINE inline |
4558
|
120 #else |
|
121 #define OCTAVE_F77_FCN_INLINE |
4555
|
122 #endif |
|
123 |
|
124 static OCTAVE_F77_FCN_INLINE octave_cray_ftn_ch_dsc |
4552
|
125 octave_make_cray_ftn_ch_dsc (char *ptr_arg, unsigned long len_arg) |
|
126 { |
|
127 octave_cray_descriptor desc; |
|
128 desc.ptr = ptr_arg; |
|
129 desc.mask.len = len_arg << 3; |
4558
|
130 return *((octave_cray_ftn_ch_dsc *) &desc); |
4552
|
131 } |
|
132 |
4555
|
133 static OCTAVE_F77_FCN_INLINE octave_cray_ftn_ch_dsc |
4552
|
134 octave_make_cray_const_ftn_ch_dsc (const char *ptr_arg, unsigned long len_arg) |
|
135 { |
|
136 octave_cray_descriptor desc; |
|
137 desc.const_ptr = ptr_arg; |
|
138 desc.mask.len = len_arg << 3; |
4558
|
139 return *((octave_cray_ftn_ch_dsc *) &desc); |
4552
|
140 } |
|
141 |
4555
|
142 #ifdef __cplusplus |
|
143 #undef OCTAVE_F77_FCN_INLINE |
|
144 #endif |
|
145 |
4552
|
146 #elif defined (F77_USES_VISUAL_FORTRAN_CALLING_CONVENTION) |
|
147 |
|
148 #define F77_CHAR_ARG(x) x, strlen (x) |
|
149 #define F77_CONST_CHAR_ARG(x) F77_CHAR_ARG (x) |
|
150 #define F77_CHAR_ARG2(x, l) x, l |
|
151 #define F77_CONST_CHAR_ARG2(x, l) F77_CHAR_ARG2 (x, l) |
|
152 #define F77_CXX_STRING_ARG(x) F77_CONST_CHAR_ARG2 (x.c_str (), x.length ()) |
|
153 #define F77_CHAR_ARG_LEN(l) |
|
154 #define F77_CHAR_ARG_DECL char *, int |
|
155 #define F77_CONST_CHAR_ARG_DECL const char *, int |
|
156 #define F77_CHAR_ARG_LEN_DECL |
|
157 #define F77_RET_T void |
|
158 #define F77_RETURN(retval) |
|
159 |
|
160 #else |
|
161 |
4572
|
162 /* Assume f2c-compatible calling convention. */ |
4552
|
163 |
|
164 #define F77_CHAR_ARG(x) x |
|
165 #define F77_CONST_CHAR_ARG(x) F77_CHAR_ARG (x) |
|
166 #define F77_CHAR_ARG2(x, l) x |
|
167 #define F77_CONST_CHAR_ARG2(x, l) F77_CHAR_ARG2 (x, l) |
|
168 #define F77_CXX_STRING_ARG(x) F77_CONST_CHAR_ARG2 (x.c_str (), x.length ()) |
|
169 #define F77_CHAR_ARG_LEN(l) , (long) l |
|
170 #define F77_CHAR_ARG_DECL char * |
|
171 #define F77_CONST_CHAR_ARG_DECL const char * |
|
172 #define F77_CHAR_ARG_LEN_DECL , long |
|
173 #define F77_RET_T int |
|
174 #define F77_RETURN(retval) return retval; |
|
175 |
|
176 #endif |
|
177 |
|
178 extern F77_RET_T |
|
179 F77_FUNC (xstopx, XSTOPX) (const char *s, long int slen) GCC_ATTR_NORETURN; |
|
180 |
2544
|
181 #ifdef __cplusplus |
|
182 } |
|
183 #endif |
|
184 |
|
185 #endif |
|
186 |
|
187 /* |
|
188 ;;; Local Variables: *** |
|
189 ;;; mode: C++ *** |
|
190 ;;; End: *** |
|
191 */ |