Skip to content

Commit

Permalink
COMP: Improve HDF5 DataSpace::ALL initialization
Browse files Browse the repository at this point in the history
Per: https://www-igm.univ-mlv.fr/~dr/CPP/c++-faq/ctors.html#[10.12]
[10.12] How do I prevent the "static initialization order fiasco" for my static data members?
  • Loading branch information
thewtex committed Sep 17, 2023
1 parent ed2b1bc commit 30cb633
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Modules/ThirdParty/HDF5/src/itkhdf5/c++/src/H5DataSpace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace H5 {
// in "H5PredType.cpp" for information.

// Initialize a pointer for the constant
DataSpace *DataSpace::ALL_ = 0;
//DataSpace *DataSpace::ALL_ = 0;

//--------------------------------------------------------------------------
// Function: DataSpace::getConstant
Expand All @@ -49,6 +49,7 @@ DataSpace::getConstant()
IdComponent::H5dontAtexit_called = true;
}

/*
// If the constant pointer is not allocated, allocate it. Otherwise,
// throw because it shouldn't be.
if (ALL_ == 0)
Expand All @@ -64,6 +65,8 @@ DataSpace::getConstant()
throw DataSpaceIException("DataSpace::getConstant",
"DataSpace::getConstant is being invoked on an allocated ALL_");
#endif
*/
static DataSpace *ALL_ = new DataSpace(H5S_ALL);
return (ALL_);
}

Expand All @@ -75,6 +78,7 @@ DataSpace::getConstant()
void
DataSpace::deleteConstants()
{
DataSpace *ALL_ = getConstant();
if (ALL_ != 0)
delete ALL_;
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/ThirdParty/HDF5/src/itkhdf5/c++/src/H5DataSpace.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class H5_DLLCPP DataSpace : public IdComponent {

#ifndef DOXYGEN_SHOULD_SKIP_THIS

static DataSpace *ALL_;
//static DataSpace *ALL_;

// Creates the global constant
static DataSpace *getConstant();
Expand Down

0 comments on commit 30cb633

Please sign in to comment.