Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow literal bitstype and symbol type parameters #203

Merged
merged 2 commits into from
Jan 7, 2015
Merged
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: 2 additions & 1 deletion src/JLD.jl
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ length(x::Union(JldFile, JldGroup)) = length(names(x))

is_valid_type_ex(s::Symbol) = true
is_valid_type_ex(s::QuoteNode) = true
is_valid_type_ex(x::Int) = true
is_valid_type_ex{T}(::T) = isbits(T)
is_valid_type_ex(e::Expr) = ((e.head == :curly || e.head == :tuple || e.head == :.) && all(map(is_valid_type_ex, e.args))) ||
(e.head == :call && (e.args[1] == :Union || e.args[1] == :TypeVar))

Expand Down Expand Up @@ -816,6 +816,7 @@ function full_typename(io::IO, file::JldFile, jltype::(Type...))
print(io, ')')
end
full_typename(io::IO, ::JldFile, x) = print(io, x)
full_typename(io::IO, ::JldFile, x::Symbol) = print(io, ":", x) # print(io, ::Symbol) doesn't show the leading colon
function full_typename(io::IO, file::JldFile, jltype::DataType)
mod = jltype.name.module
if mod != Main
Expand Down
13 changes: 13 additions & 0 deletions test/jld.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ Abig = kron(eye(10), rand(20,20))
Bbig = Any[i for i=1:3000]
Sbig = "A test string "^1000

# Bitstype type parameters
type BitsParams{x}; end
bitsparamfloat = BitsParams{1.0}()
bitsparambool = BitsParams{true}()
bitsparamsymbol = BitsParams{:x}()

iseq(x,y) = isequal(x,y)
iseq(x::MyStruct, y::MyStruct) = (x.len == y.len && x.data == y.data)
iseq(x::MyImmutable, y::MyImmutable) = (isequal(x.x, y.x) && isequal(x.y, y.y) && isequal(x.z, y.z))
Expand Down Expand Up @@ -361,6 +367,10 @@ for compress in (true,false)
@write fid Abig
@write fid Bbig
@write fid Sbig
@write fid bitsparamfloat
@write fid bitsparambool
@write fid bitsparamsymbol

# Make sure we can create groups (i.e., use HDF5 features)
g = g_create(fid, "mygroup")
i = 7
Expand Down Expand Up @@ -474,6 +484,9 @@ for compress in (true,false)
@check fidr Abig
@check fidr Bbig
@check fidr Sbig
@check fidr bitsparamfloat
@check fidr bitsparambool
@check fidr bitsparamsymbol

x1 = read(fidr, "group1/x")
@assert x1 == Any[1]
Expand Down