Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions builtins/cernlib/src/hbook.f
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,11 @@ SUBROUTINE HBNAM(IDD, BLKNA1, ADDRES, FORM1, ISCHAR)
INCLUDE 'hcform.inc'
INCLUDE 'zbits.inc'
INCLUDE 'hcflag.inc'
INTEGER IDD, ADDRES, HNBPTR
INTEGER IDD, HNBPTR
* The address is passed in as the full 64 bit value. It must not be
* truncated to 32 bits, since LOCF (used to compute the offset
* relative to the PAWC store) returns the full address too.
INTEGER*8 ADDRES, IADD
CHARACTER*(*) BLKNA1, FORM1
PARAMETER (MAXTOK = 50)
CHARACTER*8 BLKNAM
Expand Down Expand Up @@ -1713,7 +1717,7 @@ SUBROUTINE HNMADR(VAR1, IADD, ISCHAR)
INCLUDE 'zbits.inc'
CHARACTER*(*) VAR1
CHARACTER*32 NAME, VAR
INTEGER IADD
INTEGER*8 IADD, IADDW, LOCF
LOGICAL ISCHAR, ALL, LDUM
VAR = VAR1
CALL CLTOU(VAR)
Expand Down Expand Up @@ -1744,9 +1748,12 @@ SUBROUTINE HNMADR(VAR1, IADD, ISCHAR)
IELEM = IELEM*IE
10 CONTINUE
IADDW = ISHFT(IADD, -2)
IBYOF = IAND(IADD, IBYPW-1)
IBYOF = IAND(INT(IADD,4), IBYPW-1)
IF (IBYOF .NE. 0) GOTO 40
IQ(LNAME+IOFF+ZNADDR) = IADDW - LOCF(IQ(1))
* Word offset of the user variable relative to IQ(1), computed
* from the full 64 bit addresses so that it does not depend on
* where the buffer and the PAWC common happen to be mapped.
IQ(LNAME+IOFF+ZNADDR) = INT(IADDW - LOCF(IQ(1)), 4)
IADD = IADD + IELEM*ISIZE
20 IOFF = IOFF + ZNADDR
30 CONTINUE
Expand Down
15 changes: 8 additions & 7 deletions hist/hbook/src/THbookFile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "TMath.h"
#include "strlcpy.h"

#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
Expand Down Expand Up @@ -220,9 +221,9 @@ extern "C" void type_of_call hntvar3(const int&,const int&,DEFCHAR);
#endif

#ifndef WIN32
extern "C" void type_of_call hbnam(const int&,DEFCHAR,const int&,DEFCHAR,const int&,fortran_charlen_t, fortran_charlen_t);
extern "C" void type_of_call hbnam(const int&,DEFCHAR,const std::int64_t&,DEFCHAR,const int&,fortran_charlen_t, fortran_charlen_t);
#else
extern "C" void type_of_call hbnam(const int&,DEFCHAR,const int&,DEFCHAR,const int&);
extern "C" void type_of_call hbnam(const int&,DEFCHAR,const std::int64_t&,DEFCHAR,const int&);
#endif

extern "C" void type_of_call hgnpar(const int&,const char *,const int);
Expand Down Expand Up @@ -590,8 +591,7 @@ Bool_t THbookFile::IsOpen() const

void THbookFile::SetBranchAddress(Int_t id, const char *bname, void *add)
{
Int_t *iadd = (Int_t*)add;
Int_t &aadd = *iadd;
std::int64_t aadd = reinterpret_cast<std::int64_t>(add);
#ifndef WIN32
hbnam(id,PASSCHAR(bname),aadd,PASSCHAR("$SET"),0,strlen(bname),4);
#else
Expand Down Expand Up @@ -698,10 +698,11 @@ TObject *THbookFile::ConvertCWN(Int_t id)

char *bigbuf = tree->MakeX(500000);

std::int64_t add = reinterpret_cast<std::int64_t>(&bigbuf[0]);
#ifndef WIN32
hbnam(id,PASSCHAR(" "),bigbuf[0],PASSCHAR("$CLEAR"),0,1,6);
hbnam(id,PASSCHAR(" "),add,PASSCHAR("$CLEAR"),0,1,6);
#else
hbnam(id,PASSCHAR(" "),bigbuf[0],PASSCHAR("$CLEAR"),0);
hbnam(id,PASSCHAR(" "),add,PASSCHAR("$CLEAR"),0);
Comment thread
pcanal marked this conversation as resolved.
Resolved
#endif

UInt_t varNumber = 0;
Expand Down Expand Up @@ -755,7 +756,7 @@ TObject *THbookFile::ConvertCWN(Int_t id)
varNumber = 0;
strlcpy(oldblock,block,32);
oldischar = ischar;
Long_t add= (Long_t)&bigbuf[bufpos];
add = reinterpret_cast<std::int64_t>(&bigbuf[bufpos]);
Int_t lblock = strlen(block);
#ifndef WIN32
hbnam(id,PASSCHAR(block),add,PASSCHAR("$SET"),ischar,lblock,4);
Expand Down
9 changes: 5 additions & 4 deletions main/src/h2root.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "TMath.h"
#include "strlcpy.h"

#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <cctype>
Expand Down Expand Up @@ -205,9 +206,9 @@ extern "C" void type_of_call hntvar2(const int&,const int&,DEFCHAR,DEFCHAR,DEFC
#endif

#ifndef WIN32
extern "C" void type_of_call hbnam(const int&,DEFCHAR,const int&,DEFCHAR,const int&,fortran_charlen_t,fortran_charlen_t);
extern "C" void type_of_call hbnam(const int&,DEFCHAR,const std::int64_t&,DEFCHAR,const int&,fortran_charlen_t,fortran_charlen_t);
#else
extern "C" void type_of_call hbnam(const int&,DEFCHAR,const int&,DEFCHAR,const int&);
extern "C" void type_of_call hbnam(const int&,DEFCHAR,const std::int64_t&,DEFCHAR,const int&);
#endif

extern "C" void type_of_call hprntu(const int&);
Expand Down Expand Up @@ -715,7 +716,7 @@ void convert_cwn(Int_t id)
#else
hgiven(id,chtitl,80,nvar,chtag_out,kNchar,rmin[0],rmax[0]);
#endif
Long_t add= (Long_t)&bigbuf[0];
std::int64_t add = reinterpret_cast<std::int64_t>(&bigbuf[0]);
#ifndef WIN32
hbnam(id,PASSCHAR(" "),add,PASSCHAR("$CLEAR"),0,1,6);
#else
Expand Down Expand Up @@ -825,7 +826,7 @@ void convert_cwn(Int_t id)
strlcpy(oldblock,block,512);
oldischar = ischar;
Int_t lblock = strlen(block);
add= (Long_t)&bigbuf[bufpos];
add = reinterpret_cast<std::int64_t>(&bigbuf[bufpos]);
#ifndef WIN32
hbnam(id,PASSCHAR(block),add,PASSCHAR("$SET"),ischar,lblock,4);
#else
Expand Down
7 changes: 7 additions & 0 deletions roottest/root/hist/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ 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)
# Column-wise ntuples: the user buffer addresses are handed to HBOOK via
# HBNAM, which used to crash depending on where the executable was mapped.
# See https://github.com/root-project/root/issues/23628
ROOTTEST_ADD_TEST(h2root-cwn
COMMAND h2root cwn.hbook
COPY_TO_BUILDDIR cwn.hbook
OUTREF h2root_cwn.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)
Expand Down
Binary file added roottest/root/hist/cwn.hbook
Binary file not shown.
31 changes: 31 additions & 0 deletions roottest/root/hist/h2root_cwn.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Converting directory //example
Converting CWN with ID= 100, nentries = 7
Creating branch:Ivar, block:SCALARS, fullname:Ivar/I, nsub=0, itype=2, isize=4, ielem=1
Creating branch:Fvar, block:SCALARS, fullname:Fvar/F, nsub=0, itype=1, isize=4, ielem=1
Creating branch:Nel, block:ARRAYS, fullname:Nel/I, nsub=0, itype=2, isize=4, ielem=1
Creating branch:Arr, block:ARRAYS, fullname:Arr[Nel]/F, nsub=1, itype=1, isize=4, ielem=3
******************************************************************************
*Tree :h100 : cwn *
*Entries : 7 : Total = 3010 bytes File Size = 0 *
* : : Tree compression factor = 1.00 *
******************************************************************************
*Br 0 :Ivar : Ivar/I *
*Entries : 7 : Total Size= 667 bytes One basket in memory *
*Baskets : 0 : Basket Size= 64000 bytes Compression= 1.00 *
*............................................................................*
*Br 1 :Fvar : Fvar/F *
*Entries : 7 : Total Size= 667 bytes One basket in memory *
*Baskets : 0 : Basket Size= 64000 bytes Compression= 1.00 *
*............................................................................*
*Br 2 :Nel : Nel/I *
*Entries : 7 : Total Size= 661 bytes One basket in memory *
*Baskets : 0 : Basket Size= 64000 bytes Compression= 1.00 *
*............................................................................*
*Br 3 :Arr : Arr[Nel]/F *
*Entries : 7 : Total Size= 796 bytes One basket in memory *
*Baskets : 0 : Basket Size= 64000 bytes Compression= 1.00 *
*............................................................................*
TFile** cwn.root HBOOK file: cwn.hbook converted to ROOT
TFile* cwn.root HBOOK file: cwn.hbook converted to ROOT
KEY: TH1F h1;1 FVAR
KEY: TTree h100;1 cwn
34 changes: 34 additions & 0 deletions roottest/root/hist/mkcwn.f
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
* Generator for cwn.hbook, the input of the h2root-cwn test.
* Build against CERNLIB, which must be linked without PIE so that the
* commons live in the low 32 bit address space:
* gfortran -fno-pie -no-pie -fno-automatic -o mkcwn mkcwn.f \
* -lpacklib -lmathlib -lkernlib
PROGRAM MKCWN
INTEGER NWPAWC
PARAMETER (NWPAWC = 100000)
COMMON /PAWC/ H(NWPAWC)
INTEGER IVAR, NEL
REAL FVAR, ARR(3)
COMMON /CWNBLK/ IVAR, FVAR, NEL, ARR
INTEGER ISTAT, ICYCLE, I, J
CALL HLIMIT(NWPAWC)
CALL HROPEN(10, 'TEST', 'cwn.hbook', 'N', 1024, ISTAT)
IF (ISTAT .NE. 0) STOP 'HROPEN failed'
CALL HBOOK1(1, 'FVAR', 10, 0., 10., 0.)
CALL HBNT(100, 'cwn test', ' ')
CALL HBNAME(100, 'SCALARS', IVAR, 'IVAR:I*4,FVAR:R*4')
CALL HBNAME(100, 'ARRAYS', NEL, 'NEL[0,3]:I*4,ARR(NEL):R*4')
DO 20 I = 1, 7
IVAR = I
FVAR = 0.5*I
NEL = MOD(I, 4)
DO 10 J = 1, NEL
ARR(J) = I + 0.1*J
10 CONTINUE
CALL HFILL(1, FVAR, 0., 1.)
CALL HFNT(100)
20 CONTINUE
CALL HROUT(0, ICYCLE, ' ')
CALL HREND('TEST')
CLOSE(10)
END
Loading