~ubuntu-branches/ubuntu/raring/babel/raring-proposed

« back to all changes in this revision

Viewing changes to runtime/m4/llnl_fortran_string_test.m4

  • Committer: Bazaar Package Importer
  • Author(s): Adam C. Powell, IV
  • Date: 2008-08-01 07:56:58 UTC
  • mfrom: (3.1.2 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080801075658-9ezcrbh8dcs8lg70
Tags: 1.2.0.dfsg-6
Added libparsifal-dev as dependency to libsidl-dev (closes: #483324).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# LLNL_FORTRAN_STRING_TEST
 
2
# ------------------------
 
3
# Test for the correct passing of string data
 
4
#
 
5
 
 
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_
 
10
#else
 
11
#define TESTFUNC str_tst_
 
12
#endif
 
13
#else
 
14
#ifdef SIDL_$1_TWO_UNDERSCORE
 
15
#ifdef SIDL_$1_UPPER_CASE
 
16
#define TESTFUNC STR_TST__
 
17
#else
 
18
#define TESTFUNC str_tst__
 
19
#endif
 
20
#else
 
21
#ifdef SIDL_$1_UPPER_CASE
 
22
#define TESTFUNC STR_TST
 
23
#else
 
24
#define TESTFUNC str_tst
 
25
#endif
 
26
#endif
 
27
#endif
 
28
#ifdef HAVE_INTTYPES_H
 
29
#include <inttypes.h>
 
30
#else
 
31
#include <sys/types.h>
 
32
#endif
 
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;
 
42
#else
 
43
typedef int SIDL_$1_Bool;
 
44
#endif
 
45
#else
 
46
typedef int SIDL_$1_Bool;
 
47
#endif
 
48
#ifdef __cplusplus
 
49
extern "C"
 
50
#else
 
51
extern
 
52
#endif
 
53
])
 
54
 
 
55
dnl LLNL_FORTRAN_STRING_TEST(longname,shortname)
 
56
AC_DEFUN([LLNL_FORTRAN_STRING_TEST],
 
57
[AC_REQUIRE([LLNL_$2_NAME_MANGLING])dnl
 
58
AC_CACHE_CHECK(dnl
 
59
[for $1 ($2) binary string passing convention],llnl_cv_$2_string_passing,
 
60
[llnl_cv_$2_string_passing="fail"
 
61
AC_LANG_PUSH($1)dnl
 
62
AC_COMPILE_IFELSE([
 
63
       subroutine str_tst(l,a,b,c)
 
64
       implicit none
 
65
       logical l
 
66
       character*(*) a, b, c
 
67
       l = .true.
 
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.
 
74
       end],[
 
75
  mv conftest.$ac_objext cfortran_test.$ac_objext
 
76
  AC_LANG_PUSH(C)dnl
 
77
  ac_save_LIBS=$LIBS
 
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
 
81
      AC_RUN_IFELSE(
 
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);
 
85
,[
 
86
  int l;
 
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;
 
92
])],[AC_RUN_IFELSE(
 
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);
 
96
,[
 
97
  int l;
 
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"])],
 
106
    [
 
107
        AC_RUN_IFELSE(
 
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, 
 
110
              $intsize l3);],[
 
111
    int l;
 
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;
 
117
])],[AC_RUN_IFELSE(
 
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);
 
121
,[
 
122
  int l;
 
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"])],
 
131
      [
 
132
          AC_RUN_IFELSE(
 
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; };
 
137
],[
 
138
    int l;
 
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;
 
145
])],[AC_RUN_IFELSE(
 
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; };
 
150
,[
 
151
  int l;
 
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"])],
 
161
        [
 
162
            AC_RUN_IFELSE(
 
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; };
 
167
],[
 
168
    int l;
 
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;
 
175
])],[AC_RUN_IFELSE(
 
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; };
 
180
,[
 
181
  int l;
 
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"])])
 
191
        ])
 
192
      ])
 
193
    ])
 
194
  fi
 
195
  done
 
196
  LIBS=$ac_save_LIBS
 
197
  AC_LANG_POP(C)dnl
 
198
  rm -f  conftest* cfortran_test*
 
199
  ],
 
200
  [AC_MSG_ERROR([unable to compile $2 subroutine])])
 
201
  dnl AC_COMPILE_IFELSE
 
202
  AC_LANG_POP($1)dnl
 
203
  ])
 
204
  case "$llnl_cv_$2_string_passing" in
 
205
  near*)
 
206
    AC_DEFINE(SIDL_$2_STR_LEN_NEAR,,[$2 string lengths immediately follow string])
 
207
    ;;
 
208
  far*)
 
209
    AC_DEFINE(SIDL_$2_STR_LEN_FAR,,[$2 string lengths at end of argument list])
 
210
    ;;
 
211
  struct_str_len*)
 
212
    AC_DEFINE(SIDL_$2_STR_STRUCT_STR_LEN,,[$2 strings as char*-length structs])
 
213
    ;;
 
214
  struct_len_str*)
 
215
    AC_DEFINE(SIDL_$2_STR_STRUCT_LEN_STR,,[$2 strings as length-char* structs])
 
216
    ;;
 
217
  *)
 
218
    AC_MSG_ERROR([unable to determine $2 binary string passing convention])
 
219
    ;;
 
220
  esac
 
221
  case "$llnl_cv_$2_string_passing" in
 
222
  *int32_t)
 
223
    AC_DEFINE(SIDL_$2_STR_INT_SIZE,int32_t,[$2 string length integer size])
 
224
    ;;
 
225
  *int64_t)
 
226
    AC_DEFINE(SIDL_$2_STR_INT_SIZE,int64_t,[$2 string length integer size])
 
227
    ;;
 
228
  *)
 
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])
 
231
    ;;
 
232
  esac
 
233
])
 
 
b'\\ No newline at end of file'