Skip to content

Commit 12aa087

Browse files
committed
Fix argument passing conventions in h2root.
When variable-length strings are passed into functions compiled by gfortran, the lengths of the strings have to be passed at the end of the argument list as size_t. We were still using int, making fortran interpret the string lengths wrongly.
1 parent 3b5d581 commit 12aa087

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

main/src/h2root.cxx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,7 @@ void MAIN__() {}
134134

135135
// As recommended in
136136
// 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
137+
using fortran_charlen_t = size_t;
142138

143139
#else
144140
# define hlimit HLIMIT
@@ -329,11 +325,11 @@ int main(int argc, char **argv)
329325

330326
int lun = 10;
331327
#ifndef WIN32
332-
// "px" is a string being changed to "pxc" in the fortran side; since it's a temporary on C's side,
333-
// we need a buffer of at least 3 chars on Cs side, too. Predefine it as a extra variable "px " since that way
334-
// the space will be replaced by 'c' on the preallocated memory, instead of appending a new char (new memory) to "px".
335-
auto opt = PASSCHAR("px ");
336-
hropen(lun,PASSCHAR("example"),PASSCHAR(file_in),opt,record_size,ier,7,strlen(file_in),2);
328+
// Reminder: Argument passing convention is that string lengths go as hidden arguments
329+
// at the end of the argument list.
330+
constexpr auto chdir = "example";
331+
constexpr auto opt = "px";
332+
hropen(lun, chdir, file_in, opt, record_size, ier, strlen(chdir), strlen(file_in), strlen(opt));
337333
#else
338334
hropen(lun,PASSCHAR("example"),PASSCHAR(file_in),PASSCHAR("px"),record_size,ier);
339335
#endif

0 commit comments

Comments
 (0)