00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if !defined (octave_f77_fcn_h)
00025 #define octave_f77_fcn_h 1
00026
00027 #include "quit.h"
00028
00029 #ifdef __cplusplus
00030 extern "C" {
00031 #endif
00032
00033
00034 #define xSTRINGIZE(x) #x
00035 #define STRINGIZE(x) xSTRINGIZE(x)
00036
00037
00038
00039 #define F77_XFCN_ERROR(f, F) \
00040 (*current_liboctave_error_handler) \
00041 ("exception encountered in Fortran subroutine %s", \
00042 STRINGIZE (F77_FUNC (f, F)))
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 #define F77_XFCN(f, F, args) \
00053 do \
00054 { \
00055 octave_jmp_buf saved_context; \
00056 sig_atomic_t saved_octave_interrupt_immediately = octave_interrupt_immediately; \
00057 f77_exception_encountered = 0; \
00058 octave_save_current_context (saved_context); \
00059 if (octave_set_current_context) \
00060 { \
00061 octave_interrupt_immediately = saved_octave_interrupt_immediately; \
00062 octave_restore_current_context (saved_context); \
00063 if (f77_exception_encountered) \
00064 F77_XFCN_ERROR (f, F); \
00065 else \
00066 octave_rethrow_exception (); \
00067 } \
00068 else \
00069 { \
00070 octave_interrupt_immediately++; \
00071 F77_FUNC (f, F) args; \
00072 octave_interrupt_immediately--; \
00073 octave_restore_current_context (saved_context); \
00074 } \
00075 } \
00076 while (0)
00077
00078
00079 CRUFT_API extern int f77_exception_encountered;
00080
00081 #if !defined (F77_FCN)
00082 #define F77_FCN(f, F) F77_FUNC (f, F)
00083 #endif
00084
00085 #if defined (F77_USES_CRAY_CALLING_CONVENTION)
00086
00087 #include <fortran.h>
00088
00089
00090 #define F77_CHAR_ARG(x) octave_make_cray_ftn_ch_dsc (x, strlen (x))
00091 #define F77_CONST_CHAR_ARG(x) \
00092 octave_make_cray_const_ftn_ch_dsc (x, strlen (x))
00093 #define F77_CHAR_ARG2(x, l) octave_make_cray_ftn_ch_dsc (x, l)
00094 #define F77_CONST_CHAR_ARG2(x, l) octave_make_cray_const_ftn_ch_dsc (x, l)
00095 #define F77_CXX_STRING_ARG(x) \
00096 octave_make_cray_const_ftn_ch_dsc (x.c_str (), x.length ())
00097 #define F77_CHAR_ARG_LEN(l)
00098 #define F77_CHAR_ARG_DECL octave_cray_ftn_ch_dsc
00099 #define F77_CONST_CHAR_ARG_DECL octave_cray_ftn_ch_dsc
00100 #define F77_CHAR_ARG_LEN_DECL
00101
00102
00103
00104 #define F77_CHAR_ARG_DEF(s, len) octave_cray_ftn_ch_dsc s
00105 #define F77_CONST_CHAR_ARG_DEF(s, len) octave_cray_ftn_ch_dsc s
00106 #define F77_CHAR_ARG_LEN_DEF(len)
00107 #define F77_CHAR_ARG_USE(s) s.ptr
00108 #define F77_CHAR_ARG_LEN_USE(s, len) (s.mask.len>>3)
00109
00110 #define F77_RET_T int
00111 #define F77_RETURN(retval) return retval;
00112
00113
00114
00115
00116 typedef union
00117 {
00118 const char *const_ptr;
00119 char *ptr;
00120 struct
00121 {
00122 unsigned off : 6;
00123 unsigned len : 26;
00124 unsigned add : 32;
00125 } mask;
00126 } octave_cray_descriptor;
00127
00128 typedef void *octave_cray_ftn_ch_dsc;
00129
00130 #ifdef __cplusplus
00131 #define OCTAVE_F77_FCN_INLINE inline
00132 #else
00133 #define OCTAVE_F77_FCN_INLINE
00134 #endif
00135
00136 static OCTAVE_F77_FCN_INLINE octave_cray_ftn_ch_dsc
00137 octave_make_cray_ftn_ch_dsc (char *ptr_arg, unsigned long len_arg)
00138 {
00139 octave_cray_descriptor desc;
00140 desc.ptr = ptr_arg;
00141 desc.mask.len = len_arg << 3;
00142 return *((octave_cray_ftn_ch_dsc *) &desc);
00143 }
00144
00145 static OCTAVE_F77_FCN_INLINE octave_cray_ftn_ch_dsc
00146 octave_make_cray_const_ftn_ch_dsc (const char *ptr_arg, unsigned long len_arg)
00147 {
00148 octave_cray_descriptor desc;
00149 desc.const_ptr = ptr_arg;
00150 desc.mask.len = len_arg << 3;
00151 return *((octave_cray_ftn_ch_dsc *) &desc);
00152 }
00153
00154 #ifdef __cplusplus
00155 #undef OCTAVE_F77_FCN_INLINE
00156 #endif
00157
00158 #elif defined (F77_USES_VISUAL_FORTRAN_CALLING_CONVENTION)
00159
00160
00161 #define F77_CHAR_ARG(x) x, strlen (x)
00162 #define F77_CONST_CHAR_ARG(x) F77_CHAR_ARG (x)
00163 #define F77_CHAR_ARG2(x, l) x, l
00164 #define F77_CONST_CHAR_ARG2(x, l) F77_CHAR_ARG2 (x, l)
00165 #define F77_CXX_STRING_ARG(x) F77_CONST_CHAR_ARG2 (x.c_str (), x.length ())
00166 #define F77_CHAR_ARG_LEN(l)
00167 #define F77_CHAR_ARG_DECL char *, int
00168 #define F77_CONST_CHAR_ARG_DECL const char *, int
00169 #define F77_CHAR_ARG_LEN_DECL
00170
00171
00172
00173 #define F77_CHAR_ARG_DEF(s, len) char *s, int len
00174 #define F77_CONST_CHAR_ARG_DEF(s, len) const char *s, int len
00175 #define F77_CHAR_ARG_LEN_DEF(len)
00176 #define F77_CHAR_ARG_USE(s) s
00177 #define F77_CHAR_ARG_LEN_USE(s, len) len
00178
00179 #define F77_RET_T void
00180 #define F77_RETURN(retval)
00181
00182 #else
00183
00184
00185
00186
00187 #define F77_CHAR_ARG(x) x
00188 #define F77_CONST_CHAR_ARG(x) F77_CHAR_ARG (x)
00189 #define F77_CHAR_ARG2(x, l) x
00190 #define F77_CONST_CHAR_ARG2(x, l) F77_CHAR_ARG2 (x, l)
00191 #define F77_CXX_STRING_ARG(x) F77_CONST_CHAR_ARG2 (x.c_str (), x.length ())
00192 #define F77_CHAR_ARG_LEN(l) , l
00193 #define F77_CHAR_ARG_DECL char *
00194 #define F77_CONST_CHAR_ARG_DECL const char *
00195 #define F77_CHAR_ARG_LEN_DECL , long
00196
00197
00198
00199 #define F77_CHAR_ARG_DEF(s, len) char *s
00200 #define F77_CONST_CHAR_ARG_DEF(s, len) const char *s
00201 #define F77_CHAR_ARG_LEN_DEF(len) , long len
00202 #define F77_CHAR_ARG_USE(s) s
00203 #define F77_CHAR_ARG_LEN_USE(s, len) len
00204
00205 #define F77_RET_T int
00206 #define F77_RETURN(retval) return retval;
00207
00208 #endif
00209
00210
00211
00212
00213
00214
00215
00216 #define F77_CSTRING(s, len, cs) \
00217 OCTAVE_LOCAL_BUFFER (char, cs, F77_CHAR_ARG_LEN_USE (s, len) + 1); \
00218 memcpy (cs, F77_CHAR_ARG_USE (s), F77_CHAR_ARG_LEN_USE (s, len)); \
00219 cs[F77_CHAR_ARG_LEN_USE(s, len)] = '\0'
00220
00221
00222 extern CRUFT_API F77_RET_T
00223 F77_FUNC (xstopx, XSTOPX) (F77_CONST_CHAR_ARG_DECL
00224 F77_CHAR_ARG_LEN_DECL) GCC_ATTR_NORETURN;
00225
00226 #ifdef __cplusplus
00227 }
00228 #endif
00229
00230 #endif
00231
00232
00233
00234
00235
00236