From 575fa7d4ac0eedb7ff63520a18753a1f1f7b7997 Mon Sep 17 00:00:00 2001 From: Stephan Hageboeck Date: Fri, 27 Feb 2026 10:37:42 +0100 Subject: [PATCH 1/2] 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. When using gcc <= 7 or clang (where the __GNUC__ macro might return unpredictable values), we were putting int on the C side, which got interpreted as size_t on the fortran side. (cherry picked from commit 3a9316ed1ddb4f0655d8d979181819e94c877048) --- main/src/h2root.cxx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/main/src/h2root.cxx b/main/src/h2root.cxx index 57d77a3c74a86..c0ca8d5f0db44 100644 --- a/main/src/h2root.cxx +++ b/main/src/h2root.cxx @@ -134,11 +134,7 @@ void MAIN__() {} // As recommended in // https://gcc.gnu.org/onlinedocs/gfortran/Argument-passing-conventions.html -#if __GNUC__ > 7 -typedef size_t fortran_charlen_t; -#else -typedef int fortran_charlen_t; -#endif +using fortran_charlen_t = size_t; #else # define hlimit HLIMIT @@ -329,7 +325,11 @@ int main(int argc, char **argv) int lun = 10; #ifndef WIN32 - hropen(lun,PASSCHAR("example"),PASSCHAR(file_in),PASSCHAR("px"),record_size,ier,7,strlen(file_in),2); + // Reminder: Argument passing convention is that string lengths go as hidden arguments + // at the end of the argument list. + constexpr auto chdir = "example"; + constexpr auto opt = "px"; + hropen(lun, chdir, file_in, opt, record_size, ier, strlen(chdir), strlen(file_in), strlen(opt)); #else hropen(lun,PASSCHAR("example"),PASSCHAR(file_in),PASSCHAR("px"),record_size,ier); #endif From ed8a5dd650830decc15f59c843b3b4e3ff32e7c2 Mon Sep 17 00:00:00 2001 From: Stephan Hageboeck Date: Fri, 27 Feb 2026 10:37:42 +0100 Subject: [PATCH 2/2] Fix argument passing conventions in THbookFile. 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. When using gcc <= 7 or clang (where the __GNUC__ macro might return unpredictable values), we were putting int on the C side, which got interpreted as size_t on the fortran side. (cherry picked from commit 19fdba0a951f6a0dd2126b4a701a1e3964c9c812) --- hist/hbook/src/THbookFile.cxx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/hist/hbook/src/THbookFile.cxx b/hist/hbook/src/THbookFile.cxx index c4b1896c48a9d..efcf625f88076 100644 --- a/hist/hbook/src/THbookFile.cxx +++ b/hist/hbook/src/THbookFile.cxx @@ -140,11 +140,7 @@ static Int_t gLastEntry = -1; // As recommended in // https://gcc.gnu.org/onlinedocs/gfortran/Argument-passing-conventions.html -#if __GNUC__ > 7 -typedef size_t fortran_charlen_t; -#else -typedef int fortran_charlen_t; -#endif +using fortran_charlen_t = size_t; #else # define hlimit HLIMIT