1
# LLNL_FORTRAN_STRING_TEST
2
# ------------------------
3
# Test for the correct passing of string data
6
AC_DEFUN([LLNL_FORTRAN_STRING_TEST_PROLOGUE],[
7
#ifdef SIDL_$1_ONE_UNDERSCORE
8
#ifdef SIDL_$1_UPPER_CASE
9
#define TESTFUNC STR_TST_
11
#define TESTFUNC str_tst_
14
#ifdef SIDL_$1_TWO_UNDERSCORE
15
#ifdef SIDL_$1_UPPER_CASE
16
#define TESTFUNC STR_TST__
18
#define TESTFUNC str_tst__
21
#ifdef SIDL_$1_UPPER_CASE
22
#define TESTFUNC STR_TST
24
#define TESTFUNC str_tst
28
#ifdef HAVE_INTTYPES_H
31
#include <sys/types.h>
33
#ifdef SIDL_$1_LOGICAL_SIZE
34
#if SIDL_$1_LOGICAL_SIZE == 1
35
typedef int8_t SIDL_$1_Bool;
36
#elif SIDL_$1_LOGICAL_SIZE == 2
37
typedef int16_t SIDL_$1_Bool;
38
#elif SIDL_$1_LOGICAL_SIZE == 4
39
typedef int32_t SIDL_$1_Bool;
40
#elif SIDL_$1_LOGICAL_SIZE == 8
41
typedef int64_t SIDL_$1_Bool;
43
typedef int SIDL_$1_Bool;
46
typedef int SIDL_$1_Bool;
55
dnl LLNL_FORTRAN_STRING_TEST(longname,shortname)
56
AC_DEFUN([LLNL_FORTRAN_STRING_TEST],
57
[AC_REQUIRE([LLNL_$2_NAME_MANGLING])dnl
59
[for $1 ($2) binary string passing convention],llnl_cv_$2_string_passing,
60
[llnl_cv_$2_string_passing="fail"
63
subroutine str_tst(l,a,b,c)
68
if (len ( a ) .ne. 3) l = .false.
69
if (len ( b ) .ne. 0) l = .false.
70
if (len ( c ) .ne. 7) l = .false.
71
if (a .ne. 'yes') l = .false.
72
if (b .ne. '') l = .false.
73
if (c .ne. 'confirm') l = .false.
75
mv conftest.$ac_objext cfortran_test.$ac_objext
78
LIBS="cfortran_test.$ac_objext $LIBS $3"
79
for intsize in int64_t int32_t; do
80
if test "$llnl_cv_$2_string_passing" = "fail" ; then
82
[AC_LANG_PROGRAM(LLNL_FORTRAN_STRING_TEST_PROLOGUE($2)
83
void TESTFUNC(SIDL_$2_Bool *l,char *s1, char *s2, char *s3,
84
$intsize l1, $intsize l2, $intsize l3);
87
char s1[[]] = "yes"; const $intsize l1 = ($intsize)(sizeof(s1)-1);
88
char s2[[]] = ""; const $intsize l2 = ($intsize)(sizeof(s2)-1);
89
char s3[[]] = "confirm"; const $intsize l3 = ($intsize)(sizeof(s3)-1);
90
TESTFUNC(&l,s1,s2,s3,l1,l2,l3);
91
return (l == SIDL_$2_TRUE) ? 0 : -1;
93
[AC_LANG_PROGRAM(LLNL_FORTRAN_STRING_TEST_PROLOGUE($2)
94
void TESTFUNC(SIDL_$2_Bool *l,char *s1, char *s2, char *s3,
95
$intsize l1, $intsize l2, $intsize l3);
98
const $intsize upper = ((($intsize)1) << (sizeof($intsize)*4));
99
char s1[[]] = "yes";const $intsize l1 = ($intsize)(sizeof(s1)-1) | upper;
100
char s2[[]] = "";const $intsize l2 = ($intsize)(sizeof(s2)-1) | upper;
101
char s3[[]] = "confirm"; const $intsize l3 = ($intsize)(sizeof(s3)-1) |upper;
102
TESTFUNC(&l,s1,s2,s3,l1,l2,l3);
103
return (l == SIDL_$2_TRUE) ? 0 : -1;
104
])],,[dnl Setting upper bits causes runtime failure; hence, $intsize is right.
105
llnl_cv_$2_string_passing="far $intsize"])],
108
[AC_LANG_PROGRAM([LLNL_FORTRAN_STRING_TEST_PROLOGUE($2)
109
void TESTFUNC(SIDL_$2_Bool *l, char *s1, $intsize l1, char *s2, $intsize l2, char *s3,
112
char s1[[]] = "yes"; const $intsize l1 = ($intsize)(sizeof(s1)-1);
113
char s2[[]] = ""; const $intsize l2 = ($intsize)(sizeof(s2)-1);
114
char s3[[]] = "confirm"; const $intsize l3 = ($intsize)(sizeof(s3)-1);
115
TESTFUNC(&l,s1,l1,s2,l2,s3,l3);
116
return (l == SIDL_$2_TRUE) ? 0 : -1;
118
[AC_LANG_PROGRAM(LLNL_FORTRAN_STRING_TEST_PROLOGUE($2)
119
void TESTFUNC(SIDL_$2_Bool *l,char *s1, $intsize l1, char *s2,
120
$intsize l2, char *s3, $intsize l3);
123
const $intsize upper = ((($intsize)1) << (sizeof($intsize)*4));
124
char s1[[]] = "yes";const $intsize l1 = ($intsize)(sizeof(s1)-1) | upper;
125
char s2[[]] = "";const $intsize l2 = ($intsize)(sizeof(s2)-1) | upper;
126
char s3[[]] = "confirm";const $intsize l3 = ($intsize)(sizeof(s3)-1) | upper;
127
TESTFUNC(&l,s1,l1,s2,l2,s3,l3);
128
return (l == SIDL_$2_TRUE) ? 0 : -1;
129
])],,[dnl Setting upper bits causes runtime failure; hence, $intsize is right.
130
llnl_cv_$2_string_passing="near $intsize"])],
133
[struct fortran_str_arg; /* forward declaration */
134
AC_LANG_PROGRAM([LLNL_FORTRAN_STRING_TEST_PROLOGUE($2)
135
void TESTFUNC(SIDL_$2_Bool *l,struct fortran_str_arg *s1, struct fortran_str_arg *s2, struct fortran_str_arg *s3);
136
struct fortran_str_arg { char *str; $intsize len; int dummy; };
139
char s1[[]] = "yes"; char s2[[]] = ""; char s3[[]] = "confirm";
140
struct fortran_str_arg a1 = { s1, ($intsize)(sizeof(s1) - 1), -1 },
141
a2 = { s2 , ($intsize)(sizeof(s2)-1), -1 },
142
a3 = { s3 , ($intsize)(sizeof(s3)-1), -1 };
143
TESTFUNC(&l, &a1, &a2, &a3);
144
return (l == SIDL_$2_TRUE) ? 0 : -1;
146
[AC_LANG_PROGRAM(struct fortran_str_arg; /* forward declaration */
147
LLNL_FORTRAN_STRING_TEST_PROLOGUE($2)
148
void TESTFUNC(SIDL_$2_Bool *l,struct fortran_str_arg *s1, struct fortran_str_arg *s2, struct fortran_str_arg *s3);
149
struct fortran_str_arg { char *str; $intsize len; int dummy; };
152
const $intsize upper = ((($intsize)1) << (sizeof($intsize)*4));
153
char s1[[]] = "yes"; char s2[[]] = ""; char s3[[]] = "confirm";
154
struct fortran_str_arg a1 = { s1, ($intsize)(sizeof(s1) - 1)|upper, -1 },
155
a2 = { s2 , ($intsize)(sizeof(s2)-1)|upper, -1 },
156
a3 = { s3 , ($intsize)(sizeof(s3)-1)|upper, -1 };
157
TESTFUNC(&l, &a1, &a2, &a3);
158
return (l == SIDL_$2_TRUE) ? 0 : -1;
159
])],,[dnl Setting upper bits causes runtime failure; hence, $intsize is right.
160
llnl_cv_$2_string_passing="struct_str_len $intsize"])],
163
[struct fortran_str_arg; /* forward declaration */
164
AC_LANG_PROGRAM([LLNL_FORTRAN_STRING_TEST_PROLOGUE($2)
165
void TESTFUNC(SIDL_$2_Bool *l,struct fortran_str_arg *s1, struct fortran_str_arg *s2, struct fortran_str_arg *s3);
166
struct fortran_str_arg { $intsize len; char *str; };
169
char s1[[]] = "yes"; char s2[[]] = ""; char s3[[]] = "confirm";
170
struct fortran_str_arg a1 = { ($intsize)(sizeof(s1) - 1), s1 },
171
a2 = { ($intsize)(sizeof(s2)-1), s2 },
172
a3 = { ($intsize)(sizeof(s3)-1), s3 };
173
TESTFUNC(&l,&a1, &a2, &a3);
174
return (l == SIDL_$2_TRUE) ? 0 : -1;
176
[AC_LANG_PROGRAM(struct fortran_str_arg; /* forward declaration */
177
LLNL_FORTRAN_STRING_TEST_PROLOGUE($2)
178
void TESTFUNC(SIDL_$2_Bool *l,struct fortran_str_arg *s1, struct fortran_str_arg *s2, struct fortran_str_arg *s3);
179
struct fortran_str_arg { $intsize len; char *str; };
182
const $intsize upper = ((($intsize)1) << (sizeof($intsize)*4));
183
char s1[[]] = "yes"; char s2[[]] = ""; char s3[[]] = "confirm";
184
struct fortran_str_arg a1 = { ($intsize)(sizeof(s1) - 1)|upper, s1 },
185
a2 = { ($intsize)(sizeof(s2)-1)|upper, s2 },
186
a3 = { ($intsize)(sizeof(s3)-1)|upper, s3 };
187
TESTFUNC(&l, &a1, &a2, &a3);
188
return (l == SIDL_$2_TRUE) ? 0 : -1;
189
])],,[dnl Setting upper bits causes runtime failure; hence, $intsize is right.
190
llnl_cv_$2_string_passing="struct_len_str $intsize"])])
198
rm -f conftest* cfortran_test*
200
[AC_MSG_ERROR([unable to compile $2 subroutine])])
201
dnl AC_COMPILE_IFELSE
204
case "$llnl_cv_$2_string_passing" in
206
AC_DEFINE(SIDL_$2_STR_LEN_NEAR,,[$2 string lengths immediately follow string])
209
AC_DEFINE(SIDL_$2_STR_LEN_FAR,,[$2 string lengths at end of argument list])
212
AC_DEFINE(SIDL_$2_STR_STRUCT_STR_LEN,,[$2 strings as char*-length structs])
215
AC_DEFINE(SIDL_$2_STR_STRUCT_LEN_STR,,[$2 strings as length-char* structs])
218
AC_MSG_ERROR([unable to determine $2 binary string passing convention])
221
case "$llnl_cv_$2_string_passing" in
223
AC_DEFINE(SIDL_$2_STR_INT_SIZE,int32_t,[$2 string length integer size])
226
AC_DEFINE(SIDL_$2_STR_INT_SIZE,int64_t,[$2 string length integer size])
229
AC_MSG_WARN([Guessing $2 string length integer size as int.])
230
AC_DEFINE(SIDL_$2_STR_INT_SIZE,int,[$2 string length integer size])
b'\\ No newline at end of file'