Skip to content
Open
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
3 changes: 3 additions & 0 deletions plugins/decl_hdf5/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Julien Bigot - CEA ([email protected])
* Run tests that depend on the filesystem in their own temporary directory
* Buildsystem

Anida Khizar - CEA ([email protected])
* fix HDF5 API version compatibility issue [#567](https://github.com/pdidev/pdi/issues/567)

Jacques Morice - CEA ([email protected])
* contribution to feature improvement, validation
* fix issue [#55](https://github.com/pdidev/pkgs/issues/55)
Expand Down
2 changes: 2 additions & 0 deletions plugins/decl_hdf5/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Removed

### Fixed
* fix HDF5 API version compatibility issue during error handling
[#567](https://github.com/pdidev/pdi/issues/567)

### Security

Expand Down
86 changes: 55 additions & 31 deletions plugins/decl_hdf5/hdf5_wrapper.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (C) 2015-2021 Commissariat a l'energie atomique et aux energies alternatives (CEA)
* Copyright (C) 2015-2025 Commissariat a l'energie atomique et aux energies alternatives (CEA)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -48,36 +48,6 @@ namespace decl_hdf5 {
*/
[[noreturn]] void handle_hdf5_err(const char* message = NULL);

/** A RAII-style HDF5 error handler.
*
* Creating an instance of this class removes any HDF5 error handler.
* The original handler is reinstalled when the instance is destroyed.
*/
class Hdf5_error_handler
{
/// The original handler
H5E_auto2_t m_old_func;

/// The original handler data
void* m_old_data;

public:
/** The default (and only) constructor, installs the handler
*/
Hdf5_error_handler()
{
if (0 > H5Eget_auto2(H5E_DEFAULT, &m_old_func, &m_old_data)) handle_hdf5_err();
if (0 > H5Eset_auto2(H5E_DEFAULT, NULL, NULL)) handle_hdf5_err();
}

/** The destructor
*/
~Hdf5_error_handler()
{
if (0 > H5Eset_auto2(H5E_DEFAULT, m_old_func, m_old_data)) handle_hdf5_err();
}
};

/** A RAII-style wrapper for HDF5 hid_t.
*
* This calls the provided destroyer function when the hid_t goes out of scope.
Expand Down Expand Up @@ -183,6 +153,60 @@ Raii_hid make_raii_hid(hid_t value, Destroyer&& dst, const char* message = NULL)
*/
std::tuple<Raii_hid, Raii_hid> space(PDI::Datatype_sptr type, bool dense = false);

/** A RAII-style HDF5 error handler.
*
* Creating an instance of this class removes any HDF5 error handler.
* The original handler is reinstalled when the instance is destroyed.
*/
class Hdf5_error_handler
{
/// The original handler
union {
// handler to use with the HDF5 API version 2
H5E_auto2_t m_old_func;
///handler to use with old HDF5 API
H5E_auto1_t m_old_func_V16;
};

/// The original handler data
void* m_old_data;

static unsigned get_api_version()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you just add a comment to document the purpose of the function please?

{
Raii_hid stack = make_raii_hid(H5Eget_current_stack(), H5Eclose_stack, "unable to retrieve HDF5 stack to check API version");
unsigned result;
if (0 > H5Eauto_is_v2(stack, &result)) handle_hdf5_err("unable to retrieve HDF5 stack to check API version");
return result;
}

public:
/** The default (and only) constructor, installs the handler
*/
Hdf5_error_handler()
{
static unsigned is_v2 = get_api_version();
if (is_v2) {
if (0 > H5Eget_auto2(H5E_DEFAULT, &m_old_func, &m_old_data)) handle_hdf5_err();
if (0 > H5Eset_auto2(H5E_DEFAULT, NULL, NULL)) handle_hdf5_err();
} else {
if (0 > H5Eget_auto1(&m_old_func_V16, &m_old_data)) handle_hdf5_err();
if (0 > H5Eset_auto1(NULL, NULL)) handle_hdf5_err();
}
}

/** The destructor
*/
~Hdf5_error_handler()
{
static unsigned is_v2 = get_api_version();
if (is_v2) {
if (0 > H5Eset_auto2(H5E_DEFAULT, m_old_func, m_old_data)) handle_hdf5_err();
} else {
if (0 > H5Eset_auto1(m_old_func_V16, m_old_data)) handle_hdf5_err();
}
}
};

} // namespace decl_hdf5

#endif // DECL_HDF5_HDF5_WRAPPER_H_
Loading