From fa735fd1d125648b22a2d77fb5359dcea77fac54 Mon Sep 17 00:00:00 2001 From: foreverallama Date: Fri, 5 Jun 2026 15:53:55 +0530 Subject: [PATCH 1/4] Fix: Return varname with opaque class object --- src/MAT_v5.jl | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/MAT_v5.jl b/src/MAT_v5.jl index b25237e..084c8c4 100644 --- a/src/MAT_v5.jl +++ b/src/MAT_v5.jl @@ -441,10 +441,20 @@ function getvarnames(matfile::Matlabv5File) error("Unexpected data type") end - read_element(f, matfile.swap_bytes, UInt32) - read_element(f, matfile.swap_bytes, Int32) - varnames[String(read_element(f, matfile.swap_bytes, UInt8))] = offset + flags = read_element(f, matfile.swap_bytes, UInt32) + class = flags[1] & 0xFF + if class != mxOPAQUE_CLASS + read_element(f, matfile.swap_bytes, Int32) + end + + varname = String(read_element(f, matfile.swap_bytes, UInt8)) + if varname == "" + # Skip unnamed variable (subsystem) + seek(matfile.ios, offset+nbytes+hbytes) + continue + end + varnames[varname] = offset seek(matfile.ios, offset+nbytes+hbytes) end end From cf2f2f561574f8cf1f9abbadee120227907f1be6 Mon Sep 17 00:00:00 2001 From: foreverallama Date: Fri, 5 Jun 2026 16:07:20 +0530 Subject: [PATCH 2/4] Add test --- test/read.jl | 8 ++++++++ test/v7/varnames.mat | Bin 0 -> 634 bytes 2 files changed, 8 insertions(+) create mode 100644 test/v7/varnames.mat diff --git a/test/read.jl b/test/read.jl index 0b2ab64..2967c12 100644 --- a/test/read.jl +++ b/test/read.jl @@ -418,3 +418,11 @@ let objtestfile = "char_array_old_null.mat" @test haskey(vars, "simple_string") @test vars["simple_string"] == "t\0e\0q\0i\0k\0b\0o\0n\0f\0x" end + +@testset "read variable names" begin + let objtestfile = "varnames.mat" + file = matopen(joinpath(dirname(@__FILE__), "v7", objtestfile)) + var_name_dict = keys(file) + @test Set(var_name_dict) == Set(["a", "b", "c", "d"]) + end +end diff --git a/test/v7/varnames.mat b/test/v7/varnames.mat new file mode 100644 index 0000000000000000000000000000000000000000..7f5e7655586d4db3ed0ac739f66a41be5a71a520 GIT binary patch literal 634 zcmeZu4DoSvQZUssQ1EpO(M`+DN!3vZ$Vn_o%P-2c0*X01nwjV*I2WZRmZYXAi85tme(bJb7$kG7fiaC#y6A}ye1cA1!T@qIx3)CU$@vWTKvufu4ZBBePo&JIwCpY3%}|AGJ^;D{7Mo5mmOJd WIJi_ka6C|#bedU!fq}C`buj=$+}L~o literal 0 HcmV?d00001 From a70712021609905fcb4a12c592b0b9f3ddea9c57 Mon Sep 17 00:00:00 2001 From: foreverallama Date: Fri, 5 Jun 2026 16:20:46 +0530 Subject: [PATCH 3/4] Tests for haskey and read --- test/read.jl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/read.jl b/test/read.jl index 2967c12..5f7b8ba 100644 --- a/test/read.jl +++ b/test/read.jl @@ -424,5 +424,23 @@ end file = matopen(joinpath(dirname(@__FILE__), "v7", objtestfile)) var_name_dict = keys(file) @test Set(var_name_dict) == Set(["a", "b", "c", "d"]) + + @test haskey(file, "a") + @test haskey(file, "b") + @test haskey(file, "c") + @test haskey(file, "d") + @test !haskey(file, "e") + + data = read(file, "a") + @test data == reshape([1.0; 2.0; 3.0], 3, 1) + + data = read(file, "b") + @test data == "hello" + + data = read(file, "c") + @test data == "stringstring" + + data = read(file, "d") + @test data == reshape([4.0, 5.0, 6.0], 3, 1) end end From e69ba3ffac63e7b007157fd002ebb05c4dff407c Mon Sep 17 00:00:00 2001 From: foreverallama Date: Sat, 6 Jun 2026 20:31:37 +0530 Subject: [PATCH 4/4] Version bump --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 23c392f..3e1f641 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "MAT" uuid = "23992714-dd62-5051-b70f-ba57cb901cac" -version = "0.12.0" +version = "0.12.1" [deps] CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"