summaryrefslogtreecommitdiffstats
path: root/c++/src/H5IdComponent.cpp
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2015-10-04 05:05:51 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2015-10-04 05:05:51 (GMT)
commit888a002cddaa4e1d9a165ea01dfe62f399df9eb9 (patch)
tree986735636f94271dff411304d420f95eb92752ed /c++/src/H5IdComponent.cpp
parent0ef29b550bc30d5798001ac144d1b1228d663919 (diff)
downloadhdf5-888a002cddaa4e1d9a165ea01dfe62f399df9eb9.zip
hdf5-888a002cddaa4e1d9a165ea01dfe62f399df9eb9.tar.gz
hdf5-888a002cddaa4e1d9a165ea01dfe62f399df9eb9.tar.bz2
[svn-r27945] Purpose: Fix HDFFV-9529
Description: Merged from hdf5_CppAPI_Constants r27942: ------ Description: - Added H5dont_atexit() to getPredType and all the getConstant's to prevent the C library from terminating before the C++ library cleanup. - More cleanup and added more comments r27923: ------ - Updated more comments and moved some things around for consistency - Removed check for "new" failure, exceptions would be thrown r27922: ------ Description: Added function headers and more comments for clarity. r27917: ------ Description: The C++ library has several types of global constants from different classes, such as PropList, PredType, DataSpace, etc... Previously, these global constants were declared statically and the C++ library used a constant, called PredType::AtExit, to detect when all the global contants are destroyed then close the C library (H5close). This method relied on the order of the constants being created and destroyed and that PredType constants be the last to be destroyed. In September 2015, it was recognized that the order in which the global constants were created and destroyed was actually undefined, thus can be different between different compilers. This resulted in failure when compilers destroy PredType constants before others because when PredType::AtExit was destroyed, the C library was closed, so when the constants of other classes such as PropList or DataSpace were being deleted, the C library would not be available. Solution: The static approach is changed to dynamic. In order to avoid an impact on existing applications, the static global constants are changed to constant references to the dynamically allocated objects. A detailed explanation of the new method and a description of the changes are in a Design Notes at the end of the file H5PredType.cpp. New functions added to support the new methods are listed below. class H5Library: // Returns a singleton H5Library to initialize the global // constants, invoked in IdComponent default constructor static H5Library* getInstance(); // public // Registers cleanup and terminating functions with atexit(), // called in IdComponent default constructor static void initH5cpp(void); // public // Calls H5close to terminate the library, registered with // atexit(), as the last thing to be done. static void termH5cpp(void); // public class PredType: // Creates the constants static void makePredTypes(); // private // Calls makePredTypes to create the constants and returns // the dummy constant PREDTYPE_CONST; static PredType* getPredTypes(); // private class DataSpace: // Creates the constant static DataSpace* getConstant(); // private class PropList: // Creates the constant static PropList* getConstant(); // private class DSetCreatPropList: // Creates the constant static DSetCreatPropList* getConstant(); // private class DSetMemXferPropList: // Creates the constant static DSetMemXferPropList* getConstant(); // private class FileCreatPropList: // Creates the constant static FileCreatPropList* getConstant(); // private class FileAccPropList: // Creates the constant static FileAccPropList* getConstant(); // private This function is added to PredType, DataSpace, PropList, and the four subclasses of PropList: // Deletes the constant static void deleteConstants(); // public Platforms tested: Linux/32 2.6 (jam) Linux/64 (platypus) Darwin (osx1010test)
Diffstat (limited to 'c++/src/H5IdComponent.cpp')
-rw-r--r--c++/src/H5IdComponent.cpp33
1 files changed, 19 insertions, 14 deletions
diff --git a/c++/src/H5IdComponent.cpp b/c++/src/H5IdComponent.cpp
index bcd69c4..93ee4fd 100644
--- a/c++/src/H5IdComponent.cpp
+++ b/c++/src/H5IdComponent.cpp
@@ -13,11 +13,6 @@
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-#ifdef OLD_HEADER_FILENAME
-#include <iostream.h>
-#else
-#include <iostream>
-#endif
#include <string>
#include "H5Include.h"
@@ -31,11 +26,16 @@
namespace H5 {
#endif
+// This flag controls whether H5Library::initH5cpp has been called to register
+// terminating functions with atexit()
+bool IdComponent::H5cppinit = false;
+bool IdComponent::H5dontAtexit_called = false;
+
//--------------------------------------------------------------------------
// Function: IdComponent overloaded constructor
-///\brief Creates an IdComponent object using the id of an existing object.
-///\param h5_id - IN: Id of an existing object
-///\exception H5::DataTypeIException
+// Purpose Creates an IdComponent object using the id of an existing object.
+// Param h5_id - IN: Id of an existing object
+// Exception H5::DataTypeIException
// Programmer Binh-Minh Ribler - 2000
//
// *** Deprecation warning ***
@@ -43,14 +43,10 @@ namespace H5 {
// been moved to the sub-classes. It will be removed in 1.10 release. If its
// removal does not raise any problems in 1.10, it will be removed from 1.8 in
// subsequent releases.
+// - Removed from documentation in 1.8.16 -BMR (October 2015)
//--------------------------------------------------------------------------
IdComponent::IdComponent(const hid_t h5_id) {}
-//void IdComponent::p_setId(const hid_t new_id)
-//{
- //p_setId(new_id);
-//}
-
//--------------------------------------------------------------------------
// Function: IdComponent copy constructor
// Purpose: This noop copy constructor is removed as a result of the data
@@ -296,7 +292,16 @@ H5std_string IdComponent::inMemFunc(const char* func_name) const
///\brief Default constructor.
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-IdComponent::IdComponent() {}
+IdComponent::IdComponent()
+{
+ // initH5cpp will register the terminating functions with atexit().
+ // We only do this once.
+ if (!H5cppinit)
+ {
+ H5Library::getInstance()->initH5cpp();
+ H5cppinit = true;
+ }
+}
//--------------------------------------------------------------------------
// Function: IdComponent::p_get_file_name (protected)