Mercurial > octave
annotate liboctave/cruft/misc/f77-fcn.h @ 22134:a51d5c5c71e6
handle gfortran and f2c calling conventions separately
* configure.ac: New option --enable-fortran-calling-convention.
Explicitly define config.h macros for gfortran, f2c, Cray, and Visual
Fortran options.
* f77-fcn.h: Handle gfortran separately from f2c.
(F77_CHAR_ARG_LEN_TYPE, F77_DBLE, F77_REAL, F77_DBLE_CMPLX, F77_CMPLX,
F77_INT, F77_INT4, F77_LOGICAL, F77_CMPLX_ARG, F77_CONST_CMPLX_ARG,
F77_DBLE_CMPLX_ARG, F77_CONST_DBLE_CMPLX_ARG): New macros.
* f77-fcn.c (xstopx): Use F77_CHAR_ARG_LEN_TYPE.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 18 Jul 2016 09:56:41 -0400 |
parents | 59cadee1c74b |
children | 407c66ae1e20 |
rev | line source |
---|---|
2544 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
3 Copyright (C) 1996-2015 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2544 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2544 | 20 |
21 */ | |
22 | |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
20545
diff
changeset
|
23 #if ! defined (octave_f77_fcn_h) |
2544 | 24 #define octave_f77_fcn_h 1 |
25 | |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21229
diff
changeset
|
26 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21229
diff
changeset
|
27 |
4268 | 28 #include "quit.h" |
29 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21662
diff
changeset
|
30 #if defined (__cplusplus) |
2544 | 31 extern "C" { |
32 #endif | |
33 | |
4153 | 34 /* Hack to stringize macro results. */ |
3887 | 35 #define xSTRINGIZE(x) #x |
36 #define STRINGIZE(x) xSTRINGIZE(x) | |
2544 | 37 |
38 /* How to print an error for the F77_XFCN macro. */ | |
39 | |
40 #define F77_XFCN_ERROR(f, F) \ | |
41 (*current_liboctave_error_handler) \ | |
3887 | 42 ("exception encountered in Fortran subroutine %s", \ |
43 STRINGIZE (F77_FUNC (f, F))) | |
2544 | 44 |
45 /* This can be used to call a Fortran subroutine that might call | |
4153 | 46 XSTOPX. XSTOPX will call lonjmp with current_context. Once back |
47 here, we'll restore the previous context and return. We may also | |
48 end up here if an interrupt is processed when the Fortran | |
49 subroutine is called. In that case, we resotre the context and go | |
20545
c547458dc10e
eliminate error_state from most header files
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
50 to the top level. */ |
2544 | 51 |
52 #define F77_XFCN(f, F, args) \ | |
53 do \ | |
54 { \ | |
4182 | 55 octave_jmp_buf saved_context; \ |
5767 | 56 sig_atomic_t saved_octave_interrupt_immediately = octave_interrupt_immediately; \ |
2544 | 57 f77_exception_encountered = 0; \ |
5760 | 58 octave_save_current_context (saved_context); \ |
4153 | 59 if (octave_set_current_context) \ |
9930
1ddc25c3623a
libcruft/misc: untabify sources
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
60 { \ |
1ddc25c3623a
libcruft/misc: untabify sources
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
61 octave_interrupt_immediately = saved_octave_interrupt_immediately; \ |
5760 | 62 octave_restore_current_context (saved_context); \ |
9930
1ddc25c3623a
libcruft/misc: untabify sources
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
63 if (f77_exception_encountered) \ |
1ddc25c3623a
libcruft/misc: untabify sources
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
64 F77_XFCN_ERROR (f, F); \ |
4153 | 65 else \ |
9930
1ddc25c3623a
libcruft/misc: untabify sources
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
66 octave_rethrow_exception (); \ |
1ddc25c3623a
libcruft/misc: untabify sources
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
67 } \ |
2544 | 68 else \ |
4153 | 69 { \ |
9930
1ddc25c3623a
libcruft/misc: untabify sources
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
70 octave_interrupt_immediately++; \ |
1ddc25c3623a
libcruft/misc: untabify sources
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
71 F77_FUNC (f, F) args; \ |
1ddc25c3623a
libcruft/misc: untabify sources
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
72 octave_interrupt_immediately--; \ |
5760 | 73 octave_restore_current_context (saved_context); \ |
4153 | 74 } \ |
2544 | 75 } \ |
76 while (0) | |
77 | |
78 /* So we can check to see if an exception has occurred. */ | |
21227 | 79 OCTAVE_API extern int f77_exception_encountered; |
2544 | 80 |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
20545
diff
changeset
|
81 #if ! defined (F77_FCN) |
3938 | 82 #define F77_FCN(f, F) F77_FUNC (f, F) |
83 #endif | |
84 | |
15128
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
85 /* |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
86 |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
87 The following macros are used for handling Fortran <-> C calling |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
88 conventions. They are defined below for three different types of |
22134
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
89 systems, Cray (possibly now obsolete), Visual Fortran, and gfortran. |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
90 Note that we don't attempt to handle Fortran functions, we always use |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
91 subroutine wrappers for them and pass the return value as an extra |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
92 argument. |
15128
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
93 |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
94 Use these macros to pass character strings from C to Fortran: |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
95 |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
96 F77_CHAR_ARG(x) |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
97 F77_CONST_CHAR_ARG(x) |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
98 F77_CXX_STRING_ARG(x) |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
99 F77_CHAR_ARG_LEN(l) |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
100 F77_CHAR_ARG_DECL |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
101 F77_CONST_CHAR_ARG_DECL |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
102 F77_CHAR_ARG_LEN_DECL |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
103 |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
104 Use these macros to write C-language functions that accept |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
105 Fortran-style character strings: |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
106 |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
107 F77_CHAR_ARG_DEF(s, len) |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
108 F77_CONST_CHAR_ARG_DEF(s, len) |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
109 F77_CHAR_ARG_LEN_DEF(len) |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
110 F77_CHAR_ARG_USE(s) |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
111 F77_CHAR_ARG_LEN_USE(s, len) |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
112 |
22133
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
113 Use these macros for C++ code |
15128
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
114 |
22133
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
115 F77_INT Equivalent to Fortran INTEGER type |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
116 F77_INT4 Equivalent to Fortran INTEGER*4 type |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
117 F77_DBLE Equivalent to Fortran DOUBLE PRECISION type |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
118 F77_REAL Equivalent to Fortran REAL type |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
119 F77_CMPLX Equivalent to Fortran COMPLEX type |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
120 F77_DBLE_CMPLX Equivalent to Fortran DOUBLE COMPLEX type |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
121 F77_LOGICAL Equivalent to Fortran LOGICAL type |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
122 F77_RET_T Return type of a C++ function that acts like a |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
123 Fortran subroutine. |
15128
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
124 |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
125 Use these macros to return from C-language functions that are supposed |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
126 to act like Fortran subroutines. F77_NORETURN is intended to be used |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
127 as the last statement of such a function that has been tagged with a |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
128 "noreturn" attribute. If the compiler supports the "noreturn" |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
129 attribute or if F77_RET_T is void, then it should expand to nothing so |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
130 that we avoid warnings about functions tagged as "noreturn" |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
131 containing a return statement. Otherwise, it should expand to a |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
132 statement that returns the given value so that we avoid warnings about |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
133 not returning a value from a function declared to return something. |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
134 |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
135 F77_RETURN(retval) |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
136 F77_NORETURN(retval) |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
137 |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
138 */ |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
139 |
4552 | 140 #if defined (F77_USES_CRAY_CALLING_CONVENTION) |
141 | |
142 #include <fortran.h> | |
6072 | 143 |
22134
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
144 /* Use these macros to pass character strings from C to Fortran. Cray |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
145 Fortran uses a descriptor structure to pass a pointer to the string |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
146 and the length in a single argument. */ |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
147 |
4552 | 148 #define F77_CHAR_ARG(x) octave_make_cray_ftn_ch_dsc (x, strlen (x)) |
149 #define F77_CONST_CHAR_ARG(x) \ | |
150 octave_make_cray_const_ftn_ch_dsc (x, strlen (x)) | |
4577 | 151 #define F77_CHAR_ARG2(x, l) octave_make_cray_ftn_ch_dsc (x, l) |
152 #define F77_CONST_CHAR_ARG2(x, l) octave_make_cray_const_ftn_ch_dsc (x, l) | |
4552 | 153 #define F77_CXX_STRING_ARG(x) \ |
154 octave_make_cray_const_ftn_ch_dsc (x.c_str (), x.length ()) | |
155 #define F77_CHAR_ARG_LEN(l) | |
22134
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
156 #define F77_CHAR_ARG_LEN_TYPE |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
157 #define F77_CHAR_ARG_LEN_DECL |
4577 | 158 #define F77_CHAR_ARG_DECL octave_cray_ftn_ch_dsc |
159 #define F77_CONST_CHAR_ARG_DECL octave_cray_ftn_ch_dsc | |
6072 | 160 |
161 /* Use these macros to write C-language functions that accept | |
162 Fortran-style character strings. */ | |
163 #define F77_CHAR_ARG_DEF(s, len) octave_cray_ftn_ch_dsc s | |
164 #define F77_CONST_CHAR_ARG_DEF(s, len) octave_cray_ftn_ch_dsc s | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
165 #define F77_CHAR_ARG_LEN_DEF(len) |
6072 | 166 #define F77_CHAR_ARG_USE(s) s.ptr |
21662
5b9868c2e212
maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents:
21244
diff
changeset
|
167 #define F77_CHAR_ARG_LEN_USE(s, len) (s.mask.len >> 3) |
6072 | 168 |
4552 | 169 #define F77_RET_T int |
15128
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
170 |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
171 /* Use these macros to return from C-language functions that are |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
172 supposed to act like Fortran subroutines. F77_NORETURN is intended |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
173 to be used as the last statement of such a function that has been |
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
174 tagged with a "noreturn" attribute. */ |
22134
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
175 |
4552 | 176 #define F77_RETURN(retval) return retval; |
21229
a83e7a384ee0
create and install a subset of config.h in octave-config.h
John W. Eaton <jwe@octave.org>
parents:
21227
diff
changeset
|
177 #if defined (HAVE_OCTAVE_NORETURN_ATTR) |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21076
diff
changeset
|
178 # define F77_NORETURN(retval) |
15127
87411930d6c4
avoid "function declared 'noreturn' has a return statement" warning.
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
179 #else |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21076
diff
changeset
|
180 # define F77_NORETURN(retval) return retval; |
15127
87411930d6c4
avoid "function declared 'noreturn' has a return statement" warning.
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
181 #endif |
4552 | 182 |
21066
258c787cd9ce
maint: Use "FIXME:" consistently in code base.
Rik <rik@octave.org>
parents:
21040
diff
changeset
|
183 /* FIXME: These should work for SV1 or Y-MP systems but will |
258c787cd9ce
maint: Use "FIXME:" consistently in code base.
Rik <rik@octave.org>
parents:
21040
diff
changeset
|
184 need to be changed for others. */ |
4552 | 185 |
4558 | 186 typedef union |
4552 | 187 { |
4558 | 188 const char *const_ptr; |
189 char *ptr; | |
4552 | 190 struct |
191 { | |
192 unsigned off : 6; | |
193 unsigned len : 26; | |
194 unsigned add : 32; | |
195 } mask; | |
4558 | 196 } octave_cray_descriptor; |
4552 | 197 |
198 typedef void *octave_cray_ftn_ch_dsc; | |
199 | |
22133
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
200 #if defined (__cplusplus) |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21076
diff
changeset
|
201 # define OCTAVE_F77_FCN_INLINE inline |
4558 | 202 #else |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21076
diff
changeset
|
203 # define OCTAVE_F77_FCN_INLINE |
4555 | 204 #endif |
205 | |
206 static OCTAVE_F77_FCN_INLINE octave_cray_ftn_ch_dsc | |
4552 | 207 octave_make_cray_ftn_ch_dsc (char *ptr_arg, unsigned long len_arg) |
208 { | |
209 octave_cray_descriptor desc; | |
210 desc.ptr = ptr_arg; | |
211 desc.mask.len = len_arg << 3; | |
4558 | 212 return *((octave_cray_ftn_ch_dsc *) &desc); |
4552 | 213 } |
214 | |
4555 | 215 static OCTAVE_F77_FCN_INLINE octave_cray_ftn_ch_dsc |
4552 | 216 octave_make_cray_const_ftn_ch_dsc (const char *ptr_arg, unsigned long len_arg) |
217 { | |
218 octave_cray_descriptor desc; | |
219 desc.const_ptr = ptr_arg; | |
220 desc.mask.len = len_arg << 3; | |
4558 | 221 return *((octave_cray_ftn_ch_dsc *) &desc); |
4552 | 222 } |
223 | |
22133
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
224 #undef OCTAVE_F77_FCN_INLINE |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
225 |
4552 | 226 #elif defined (F77_USES_VISUAL_FORTRAN_CALLING_CONVENTION) |
227 | |
22134
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
228 /* Use these macros to pass character strings from C to Fortran. |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
229 Visual Fortran inserts the length after each character string |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
230 argument. */ |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
231 |
4552 | 232 #define F77_CHAR_ARG(x) x, strlen (x) |
233 #define F77_CONST_CHAR_ARG(x) F77_CHAR_ARG (x) | |
234 #define F77_CHAR_ARG2(x, l) x, l | |
235 #define F77_CONST_CHAR_ARG2(x, l) F77_CHAR_ARG2 (x, l) | |
236 #define F77_CXX_STRING_ARG(x) F77_CONST_CHAR_ARG2 (x.c_str (), x.length ()) | |
237 #define F77_CHAR_ARG_LEN(l) | |
22134
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
238 #define F77_CHAR_ARG_LEN_TYPE int |
4552 | 239 #define F77_CHAR_ARG_LEN_DECL |
22134
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
240 #define F77_CHAR_ARG_DECL char *, F77_CHAR_ARG_LEN_TYPE |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
241 #define F77_CONST_CHAR_ARG_DECL const char *, F77_CHAR_ARG_LEN_TYPE |
6072 | 242 |
22134
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
243 #define F77_CHAR_ARG_DEF(s, len) char *s, F77_CHAR_ARG_LEN_TYPE len |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
244 #define F77_CONST_CHAR_ARG_DEF(s, len) const char *s, F77_CHAR_ARG_LEN_TYPE len |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
245 #define F77_CHAR_ARG_LEN_DEF(len) |
6072 | 246 #define F77_CHAR_ARG_USE(s) s |
247 #define F77_CHAR_ARG_LEN_USE(s, len) len | |
248 | |
4552 | 249 #define F77_RET_T void |
15128
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
250 |
15127
87411930d6c4
avoid "function declared 'noreturn' has a return statement" warning.
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
251 #define F77_RETURN(retval) return; |
87411930d6c4
avoid "function declared 'noreturn' has a return statement" warning.
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
252 #define F77_NORETURN(retval) |
4552 | 253 |
22134
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
254 #elif defined (F77_USES_GFORTRAN_CALLING_CONVENTION) |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
255 |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
256 /* Use these macros to pass character strings from C to Fortran. |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
257 gfortran appends length arguments for assumed size character |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
258 strings to the and ignores others. |
4552 | 259 |
22134
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
260 FIXME: I don't think we correctly handle the case of mixing some |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
261 fixed-length and some assumed-length character string arguments as |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
262 we don't handle each case separately, so it seems there could be |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
263 mismatch? However, I don't think we currently have to handle this |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
264 case in Octave. */ |
4552 | 265 |
266 #define F77_CHAR_ARG(x) x | |
267 #define F77_CONST_CHAR_ARG(x) F77_CHAR_ARG (x) | |
268 #define F77_CHAR_ARG2(x, l) x | |
269 #define F77_CONST_CHAR_ARG2(x, l) F77_CHAR_ARG2 (x, l) | |
270 #define F77_CXX_STRING_ARG(x) F77_CONST_CHAR_ARG2 (x.c_str (), x.length ()) | |
5760 | 271 #define F77_CHAR_ARG_LEN(l) , l |
22134
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
272 #define F77_CHAR_ARG_LEN_TYPE int |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
273 #define F77_CHAR_ARG_LEN_DECL , F77_CHAR_ARG_LEN_TYPE |
4552 | 274 #define F77_CHAR_ARG_DECL char * |
275 #define F77_CONST_CHAR_ARG_DECL const char * | |
6072 | 276 |
277 #define F77_CHAR_ARG_DEF(s, len) char *s | |
278 #define F77_CONST_CHAR_ARG_DEF(s, len) const char *s | |
22134
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
279 #define F77_CHAR_ARG_LEN_DEF(len) , F77_CHAR_ARG_LEN_TYPE len |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
280 #define F77_CHAR_ARG_USE(s) s |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
281 #define F77_CHAR_ARG_LEN_USE(s, len) len |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
282 |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
283 #define F77_RET_T void |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
284 |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
285 #define F77_RETURN(retval) return retval; |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
286 #if defined (HAVE_OCTAVE_NORETURN_ATTR) |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
287 # define F77_NORETURN(retval) |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
288 #else |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
289 # define F77_NORETURN(retval) return retval; |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
290 #endif |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
291 |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
292 #elif defined (F77_USES_F2C_CALLING_CONVENTION) |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
293 |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
294 /* Assume f2c-compatible calling convention. */ |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
295 |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
296 /* Use these macros to pass character strings from C to Fortran. f2c |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
297 appends all length arguments at the end of the parameter list. */ |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
298 |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
299 #define F77_CHAR_ARG(x) x |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
300 #define F77_CONST_CHAR_ARG(x) F77_CHAR_ARG (x) |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
301 #define F77_CHAR_ARG2(x, l) x |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
302 #define F77_CONST_CHAR_ARG2(x, l) F77_CHAR_ARG2 (x, l) |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
303 #define F77_CXX_STRING_ARG(x) F77_CONST_CHAR_ARG2 (x.c_str (), x.length ()) |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
304 #define F77_CHAR_ARG_LEN(l) , l |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
305 #define F77_CHAR_ARG_LEN_TYPE long |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
306 #define F77_CHAR_ARG_LEN_DECL , F77_CHAR_ARG_LEN_TYPE |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
307 #define F77_CHAR_ARG_DECL char * |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
308 #define F77_CONST_CHAR_ARG_DECL const char * |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
309 |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
310 #define F77_CHAR_ARG_DEF(s, len) char *s |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
311 #define F77_CONST_CHAR_ARG_DEF(s, len) const char *s |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
312 #define F77_CHAR_ARG_LEN_DEF(len) , F77_CHAR_ARG_LEN_TYPE len |
6072 | 313 #define F77_CHAR_ARG_USE(s) s |
314 #define F77_CHAR_ARG_LEN_USE(s, len) len | |
315 | |
4552 | 316 #define F77_RET_T int |
15128
4d52239daef5
improve internal documentation of F77_ macros.
John W. Eaton <jwe@octave.org>
parents:
15127
diff
changeset
|
317 |
4552 | 318 #define F77_RETURN(retval) return retval; |
21229
a83e7a384ee0
create and install a subset of config.h in octave-config.h
John W. Eaton <jwe@octave.org>
parents:
21227
diff
changeset
|
319 #if defined (HAVE_OCTAVE_NORETURN_ATTR) |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21076
diff
changeset
|
320 # define F77_NORETURN(retval) |
15127
87411930d6c4
avoid "function declared 'noreturn' has a return statement" warning.
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
321 #else |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21076
diff
changeset
|
322 # define F77_NORETURN(retval) return retval; |
15127
87411930d6c4
avoid "function declared 'noreturn' has a return statement" warning.
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
323 #endif |
4552 | 324 |
22134
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
325 #else |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
326 |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
327 #error "unknown C++ to Fortran calling convention" |
a51d5c5c71e6
handle gfortran and f2c calling conventions separately
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
328 |
4552 | 329 #endif |
330 | |
22133
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
331 #define F77_DBLE double |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
332 #define F77_REAL float |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
333 #define F77_DBLE_CMPLX Complex |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
334 #define F77_CMPLX FloatComplex |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
335 #define F77_INT octave_idx_type |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
336 #define F77_INT4 int32_t |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
337 #define F77_LOGICAL octave_idx_type |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
338 |
6072 | 339 /* Build a C string local variable CS from the Fortran string parameter S |
340 declared as F77_CHAR_ARG_DEF(s, len) or F77_CONST_CHAR_ARG_DEF(s, len). | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
341 The string will be cleaned up at the end of the current block. |
6072 | 342 Needs to include <cstring> and <vector>. */ |
343 | |
344 #define F77_CSTRING(s, len, cs) \ | |
6253 | 345 OCTAVE_LOCAL_BUFFER (char, cs, F77_CHAR_ARG_LEN_USE (s, len) + 1); \ |
6072 | 346 memcpy (cs, F77_CHAR_ARG_USE (s), F77_CHAR_ARG_LEN_USE (s, len)); \ |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
347 cs[F77_CHAR_ARG_LEN_USE(s, len)] = '\0' |
6072 | 348 |
21227 | 349 OCTAVE_NORETURN OCTAVE_API extern |
21076
b433f9990452
strip trailing whitespace from files
John W. Eaton <jwe@octave.org>
parents:
21066
diff
changeset
|
350 F77_RET_T |
4801 | 351 F77_FUNC (xstopx, XSTOPX) (F77_CONST_CHAR_ARG_DECL |
21029
e3b3bb522d62
maint: Move GCC_ attributes to start of declaration for future compatibility.
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
352 F77_CHAR_ARG_LEN_DECL); |
4552 | 353 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21662
diff
changeset
|
354 #if defined (__cplusplus) |
2544 | 355 } |
356 #endif | |
357 | |
358 #endif |