From a6a88c7a2bdaea1545727b02e1d2c19f8b38d7e2 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 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. --- 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 5ea121775313d..91212285f389b 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 From 09ad756935f17b3a0e7dc29e9174bdaa106f66fc Mon Sep 17 00:00:00 2001 From: Stephan Hageboeck Date: Fri, 27 Feb 2026 15:34:44 +0100 Subject: [PATCH 2/2] [roottest] Add a test to read an hbook file. --- roottest/root/hist/CMakeLists.txt | 3 +++ roottest/root/hist/THbookFile.cxx | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 roottest/root/hist/THbookFile.cxx diff --git a/roottest/root/hist/CMakeLists.txt b/roottest/root/hist/CMakeLists.txt index f4c216918ba78..adcf2726d598b 100644 --- a/roottest/root/hist/CMakeLists.txt +++ b/roottest/root/hist/CMakeLists.txt @@ -11,6 +11,9 @@ if(fortran AND CMAKE_Fortran_COMPILER AND NOT CMAKE_Fortran_COMPILER_ID STREQUAL COMMAND h2root mb4i1.hbook COPY_TO_BUILDDIR mb4i1.hbook OUTREF h2root.ref) + ROOT_ADD_GTEST(THbookFile THbookFile.cxx LIBRARIES Hbook) + set_tests_properties(roottest-root-hist-h2root PROPERTIES FIXTURES_SETUP hbookFile) + set_tests_properties(gtest-roottest-root-hist-THbookFile PROPERTIES FIXTURES_REQUIRED hbookFile) endif() ROOTTEST_ADD_TESTDIRS() diff --git a/roottest/root/hist/THbookFile.cxx b/roottest/root/hist/THbookFile.cxx new file mode 100644 index 0000000000000..64f2ad38c9df0 --- /dev/null +++ b/roottest/root/hist/THbookFile.cxx @@ -0,0 +1,16 @@ +#include +#include + +#include "gtest/gtest.h" + +TEST(THbookFile, ReadTH1) +{ + THbookFile file("mb4i1.hbook"); + EXPECT_STREQ(file.GetCurDir(), "//lun10"); + EXPECT_EQ(file.GetListOfKeys()->size(), 9); + + TObject *histo = file.Get(1); + auto th1 = dynamic_cast(histo); + ASSERT_NE(th1, nullptr); + EXPECT_EQ(th1->GetEntries(), 500); +}