From 3ffa26543ff4c31aa7884be1ba0b4816082766e9 Mon Sep 17 00:00:00 2001 From: Justin Willmert Date: Sun, 1 Nov 2020 12:31:01 -0600 Subject: [PATCH] Skip over function handles in v7.3 format This is similar to #129 which returns `missing` for unhandled data types in HDF5 Datasets; function handles are stored as HDF5 groups, so a different explicit check is required to skip over them. --- src/MAT_HDF5.jl | 3 +++ test/read.jl | 9 ++++++++- test/v7.3/function_handles.mat | Bin 0 -> 21808 bytes 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 test/v7.3/function_handles.mat diff --git a/src/MAT_HDF5.jl b/src/MAT_HDF5.jl index 2ecd258..63cbf5c 100644 --- a/src/MAT_HDF5.jl +++ b/src/MAT_HDF5.jl @@ -229,6 +229,9 @@ function m_read(g::HDF5Group) data = str2eltype_matlab[mattype][] end return SparseMatrixCSC(convert(Int, HDF5.a_read(g, sparse_attr_matlab)), length(jc)-1, jc, ir, data) + elseif mattype == "function_handle" + @warn "MATLAB $mattype values are currently not supported" + return missing else error("Cannot read from a non-struct group, type was $mattype") end diff --git a/test/read.jl b/test/read.jl index e1f388b..866e631 100644 --- a/test/read.jl +++ b/test/read.jl @@ -213,9 +213,16 @@ let objtestfile = "figure.fig" @test vars["hgS_070000"]["type"] == "figure" end -# test reading file containing Matlab table and datetime objects +# test reading file containing Matlab function handle, table, and datetime objects # since we don't support these objects, just make sure that there are no errors # reading the file and that the variables are there and replaced with `missing` +let objtestfile = "function_handles.mat" + vars = matread(joinpath(dirname(@__FILE__), "v7.3", objtestfile)) + @test "sin" in keys(vars) + @test ismissing(vars["sin"]) + @test "anonymous" in keys(vars) + @test ismissing(vars["anonymous"]) +end let objtestfile = "struct_table_datetime.mat" vars = matread(joinpath(dirname(@__FILE__), "v7.3", objtestfile))["s"] @test "testTable" in keys(vars) diff --git a/test/v7.3/function_handles.mat b/test/v7.3/function_handles.mat new file mode 100644 index 0000000000000000000000000000000000000000..39e2b598c5d09db00f4ab65ab75628877873f7b1 GIT binary patch literal 21808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