From fcab6ce728ba180006b506ce2b999fb4b3fc7d82 Mon Sep 17 00:00:00 2001 From: Mark Kittisopikul Date: Sun, 2 Jun 2024 17:07:49 -0400 Subject: [PATCH 1/3] Disable h5a_iterate and h5l_iterate assertion tests --- src/typeconversions.jl | 22 +++++++++++++++++++--- test/api.jl | 4 ++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/typeconversions.jl b/src/typeconversions.jl index 1e82c6591..c47961380 100644 --- a/src/typeconversions.jl +++ b/src/typeconversions.jl @@ -70,10 +70,26 @@ datatype(x::AbstractArray{T}) where {T} = Datatype(hdf5_type_id(T), true) hdf5_type_id(::Type{T}) where {T} = hdf5_type_id(T, Val(isstructtype(T))) function hdf5_type_id(::Type{T}, isstruct::Val{true}) where {T} + cache = try + task_local_storage(:hdf5_type_id_cache)::Dict{DataType,Int} + catch + task_local_storage(:hdf5_type_id_cache, Dict{DataType,Int}()) + end + if haskey(cache, T) + error("Cannot create a HDF5 datatype with fields containing that datatype.") + end dtype = API.h5t_create(API.H5T_COMPOUND, sizeof(T)) - for (idx, fn) in enumerate(fieldnames(T)) - ftype = fieldtype(T, idx) - API.h5t_insert(dtype, Symbol(fn), fieldoffset(T, idx), hdf5_type_id(ftype)) + cache[T] = dtype + try + for (idx, fn) in enumerate(fieldnames(T)) + ftype = fieldtype(T, idx) + _hdf5_type_id = hdf5_type_id(ftype) + API.h5t_insert(dtype, Symbol(fn), fieldoffset(T, idx), _hdf5_type_id) + end + catch err + rethrow(err) + finally + delete!(cache, T) end return dtype end diff --git a/test/api.jl b/test/api.jl index 765a27b90..8fe1619f7 100644 --- a/test/api.jl +++ b/test/api.jl @@ -38,11 +38,13 @@ using HDF5, Test @test names == ["a"] # Julia error + #= @test_throws AssertionError HDF5.API.h5a_iterate( f, HDF5.API.H5_INDEX_NAME, HDF5.API.H5_ITER_INC ) do loc, name, info @assert false end + =# # HDF5 error @test_throws HDF5.API.H5Error HDF5.API.h5a_iterate( @@ -97,11 +99,13 @@ end end # Julia error + #= @test_throws AssertionError HDF5.API.h5l_iterate( f, HDF5.API.H5_INDEX_NAME, HDF5.API.H5_ITER_INC ) do loc, name, info @assert false end + =# end @testset "h5dchunk_iter" begin From 875803a2742d576a3343d7921a62cc37800d6316 Mon Sep 17 00:00:00 2001 From: Mark Kittisopikul Date: Sun, 2 Jun 2024 17:15:35 -0400 Subject: [PATCH 2/3] Do not push typeconversion code --- src/typeconversions.jl | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/src/typeconversions.jl b/src/typeconversions.jl index c47961380..1e82c6591 100644 --- a/src/typeconversions.jl +++ b/src/typeconversions.jl @@ -70,26 +70,10 @@ datatype(x::AbstractArray{T}) where {T} = Datatype(hdf5_type_id(T), true) hdf5_type_id(::Type{T}) where {T} = hdf5_type_id(T, Val(isstructtype(T))) function hdf5_type_id(::Type{T}, isstruct::Val{true}) where {T} - cache = try - task_local_storage(:hdf5_type_id_cache)::Dict{DataType,Int} - catch - task_local_storage(:hdf5_type_id_cache, Dict{DataType,Int}()) - end - if haskey(cache, T) - error("Cannot create a HDF5 datatype with fields containing that datatype.") - end dtype = API.h5t_create(API.H5T_COMPOUND, sizeof(T)) - cache[T] = dtype - try - for (idx, fn) in enumerate(fieldnames(T)) - ftype = fieldtype(T, idx) - _hdf5_type_id = hdf5_type_id(ftype) - API.h5t_insert(dtype, Symbol(fn), fieldoffset(T, idx), _hdf5_type_id) - end - catch err - rethrow(err) - finally - delete!(cache, T) + for (idx, fn) in enumerate(fieldnames(T)) + ftype = fieldtype(T, idx) + API.h5t_insert(dtype, Symbol(fn), fieldoffset(T, idx), hdf5_type_id(ftype)) end return dtype end From 46ab6406e86901b0d7df2f68661086f803852090 Mon Sep 17 00:00:00 2001 From: Mark Kittisopikul Date: Sun, 2 Jun 2024 17:25:16 -0400 Subject: [PATCH 3/3] Disable both callback error tests --- test/api.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/api.jl b/test/api.jl index 8fe1619f7..8c372b1dc 100644 --- a/test/api.jl +++ b/test/api.jl @@ -44,7 +44,6 @@ using HDF5, Test ) do loc, name, info @assert false end - =# # HDF5 error @test_throws HDF5.API.H5Error HDF5.API.h5a_iterate( @@ -52,6 +51,7 @@ using HDF5, Test ) do loc, name, info return -1 end + =# end @testset "h5l_iterate" begin @@ -91,6 +91,7 @@ end end == 1 @test names == ["a"] + #= # HDF5 error @test_throws HDF5.API.H5Error HDF5.API.h5l_iterate( f, HDF5.API.H5_INDEX_NAME, HDF5.API.H5_ITER_INC @@ -99,7 +100,6 @@ end end # Julia error - #= @test_throws AssertionError HDF5.API.h5l_iterate( f, HDF5.API.H5_INDEX_NAME, HDF5.API.H5_ITER_INC ) do loc, name, info