Skip to content

Commit aafddfb

Browse files
committed
[h2root] Adapt to GCC 8 passing convention for string length
According to the `gfortran` argument passing conventions, for any Fortran procedure, the compiler will automatically define a C prototype. This is what we use in `h2root`. Note that for procedures like `HROPEN` that takes string arguments, the signature of the C prototype will have extra arguments for the string lengths, which we also have to include in our forward declaration and usage. However, the type of these was changed with GCC 8 to size_t, so we have to also account for that as recommended in [1]. Otherwise, we get undefined behavor, which causes the `h2root` test to fail on ARM64 with GCC 14. [1] https://gcc.gnu.org/onlinedocs/gfortran/Argument-passing-conventions.html
1 parent b78500f commit aafddfb

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

main/src/h2root.cxx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ void MAIN__() {}
131131
# define type_of_call
132132
# define DEFCHAR const char*
133133
# define PASSCHAR(string) string
134+
135+
// As recommended in
136+
// https://gcc.gnu.org/onlinedocs/gfortran/Argument-passing-conventions.html
137+
#if __GNUC__ > 7
138+
typedef size_t fortran_charlen_t;
139+
#else
140+
typedef int fortran_charlen_t;
141+
#endif
142+
134143
#else
135144
# define hlimit HLIMIT
136145
# define hropen HROPEN
@@ -169,7 +178,7 @@ void MAIN__() {}
169178
extern "C" void type_of_call hlimit(const int&);
170179
#ifndef WIN32
171180
extern "C" void type_of_call hropen(const int&,DEFCHAR,DEFCHAR,DEFCHAR,
172-
const int&,const int&,const int,const int,const int);
181+
const int&,const int&,fortran_charlen_t,fortran_charlen_t,fortran_charlen_t);
173182
#else
174183
extern "C" void type_of_call hropen(const int&,DEFCHAR,DEFCHAR,DEFCHAR,
175184
const int&,const int&);
@@ -179,28 +188,28 @@ extern "C" void type_of_call hrin(const int&,const int&,const int&);
179188
extern "C" void type_of_call hnoent(const int&,const int&);
180189
#ifndef WIN32
181190
extern "C" void type_of_call hgive(const int&,DEFCHAR,const int&,const float&,const float&,
182-
const int&,const float&,const float&,const int&,const int&,const int);
191+
const int&,const float&,const float&,const int&,const int&,fortran_charlen_t);
183192
#else
184193
extern "C" void type_of_call hgive(const int&,DEFCHAR,const int&,const float&,const float&,
185194
const int&,const float&,const float&,const int&,const int&);
186195
#endif
187196

188197
#ifndef WIN32
189198
extern "C" void type_of_call hgiven(const int&,DEFCHAR,const int&,DEFCHAR,
190-
const float&,const float&,const int,const int);
199+
const float&,const float&,fortran_charlen_t,fortran_charlen_t);
191200
#else
192201
extern "C" void type_of_call hgiven(const int&,DEFCHAR,const int&,DEFCHAR,
193202
const float&,const float&);
194203
#endif
195204

196205
#ifndef WIN32
197-
extern "C" void type_of_call hntvar2(const int&,const int&,DEFCHAR,DEFCHAR,DEFCHAR,int&,int&,int&,int&,int&,const int,const int, const int);
206+
extern "C" void type_of_call hntvar2(const int&,const int&,DEFCHAR,DEFCHAR,DEFCHAR,int&,int&,int&,int&,int&,fortran_charlen_t,fortran_charlen_t,fortran_charlen_t);
198207
#else
199208
extern "C" void type_of_call hntvar2(const int&,const int&,DEFCHAR,DEFCHAR,DEFCHAR,int&,int&,int&,int&,int&);
200209
#endif
201210

202211
#ifndef WIN32
203-
extern "C" void type_of_call hbnam(const int&,DEFCHAR,const int&,DEFCHAR,const int&,const int, const int);
212+
extern "C" void type_of_call hbnam(const int&,DEFCHAR,const int&,DEFCHAR,const int&,fortran_charlen_t,fortran_charlen_t);
204213
#else
205214
extern "C" void type_of_call hbnam(const int&,DEFCHAR,const int&,DEFCHAR,const int&);
206215
#endif
@@ -232,14 +241,14 @@ extern "C" double type_of_call hije(const int&,const int&,const int&);
232241
#endif
233242

234243
#ifndef WIN32
235-
extern "C" void type_of_call hcdir(DEFCHAR,DEFCHAR ,const int,const int);
244+
extern "C" void type_of_call hcdir(DEFCHAR,DEFCHAR ,fortran_charlen_t,fortran_charlen_t);
236245
#else
237246
extern "C" void type_of_call hcdir(DEFCHAR,DEFCHAR);
238247
#endif
239248

240249
extern "C" void type_of_call zitoh(const int&,const int&,const int&);
241250
#ifndef WIN32
242-
extern "C" void type_of_call uhtoc(const int&,const int&,DEFCHAR,int&,const int);
251+
extern "C" void type_of_call uhtoc(const int&,const int&,DEFCHAR,int&,fortran_charlen_t);
243252
#else
244253
extern "C" void type_of_call uhtoc(const int&,const int&,DEFCHAR,int&);
245254
#endif

0 commit comments

Comments
 (0)