From c34d8ff2d1a9be8745a60eddf404b5709dc05d20 Mon Sep 17 00:00:00 2001 From: "femtocleaner[bot]" Date: Tue, 8 Aug 2017 22:46:52 +0000 Subject: [PATCH] Fix deprecations --- benchmark/benchmark.jl | 4 +-- src/JLD2.jl | 4 +-- src/attributes.jl | 2 +- src/bufferedio.jl | 4 +-- src/data.jl | 56 +++++++++++++++--------------- src/dataio.jl | 68 ++++++++++++++++++------------------- src/datasets.jl | 20 +++++------ src/dataspaces.jl | 18 +++++----- src/global_heaps.jl | 2 +- src/groups.jl | 2 +- src/mmapio.jl | 4 +-- test/customserialization.jl | 32 ++++++++--------- test/rw.jl | 2 +- 13 files changed, 109 insertions(+), 109 deletions(-) diff --git a/benchmark/benchmark.jl b/benchmark/benchmark.jl index 295d668c..813fab1f 100644 --- a/benchmark/benchmark.jl +++ b/benchmark/benchmark.jl @@ -65,7 +65,7 @@ bench("integer_int_vector", convert(Vector{Integer}, rand(typemin(Int):typemax(I bench("complex128_vector", [complex(rand(), rand()) for i = 1:10000000]) # Vector{Any} of non-builtin immutable -immutable IntWrapper +struct IntWrapper x::Int end bench("any_complex128_vector", Any[complex(rand(), rand()) for i = 1:1000000]) @@ -79,7 +79,7 @@ bench("one_element_arrays", [[rand(typemin(Int):typemax(Int))] for i = 1:1000000 # Equivalent benchmark from https://github.com/timholy/HDF5.jl/issues/170 # This is 1/10 of the amount of data, but we don't have a problem with # scaling, so this should be fine -type Cell +mutable struct Cell a::Array{Float64,1} b::Array{Float64,1} c::Array{Float64,2} diff --git a/src/JLD2.jl b/src/JLD2.jl index a8ef86f2..ab352fc0 100644 --- a/src/JLD2.jl +++ b/src/JLD2.jl @@ -195,9 +195,9 @@ openfile(::Type{MmapIO}, fname, wr, create, truncate) = read_bytestring(io::IOStream) = chop(String(readuntil(io, 0x00))) const OPEN_FILES = Dict{String,WeakRef}() -function jldopen{T<:Union{Type{IOStream},Type{MmapIO}}}( +function jldopen( fname::AbstractString, wr::Bool, create::Bool, truncate::Bool, - iotype::T=MmapIO; compress::Bool=false, mmaparrays::Bool=false) +iotype::T=MmapIO; compress::Bool=false, mmaparrays::Bool=false) where T<:Union{Type{IOStream},Type{MmapIO}} exists = isfile(fname) if exists rname = realpath(fname) diff --git a/src/attributes.jl b/src/attributes.jl index 5d8db9ff..c7dd8b6a 100644 --- a/src/attributes.jl +++ b/src/attributes.jl @@ -10,7 +10,7 @@ struct WrittenAttribute{DS<:WriteDataspace,H5T<:H5Datatype,T} data::T end -function WrittenAttribute{T}(f::JLDFile, name::Symbol, data::T) +function WrittenAttribute(f::JLDFile, name::Symbol, data::T) where T WrittenAttribute(name, WriteDataspace(f, data, objodr(data)), h5type(f, data), data) end diff --git a/src/bufferedio.jl b/src/bufferedio.jl index c9d43ad6..4313a2a4 100644 --- a/src/bufferedio.jl +++ b/src/bufferedio.jl @@ -95,7 +95,7 @@ end @inline Base.read(io::BufferedReader, T::Type{Int8}) = _read(io, T) @inline Base.read(io::BufferedReader, T::PlainType) = _read(io, T) -function Base.read{T}(io::BufferedReader, ::Type{T}, n::Int) +function Base.read(io::BufferedReader, ::Type{T}, n::Int) where T position = io.position[] buffer = io.buffer n = sizeof(T) * n @@ -107,7 +107,7 @@ function Base.read{T}(io::BufferedReader, ::Type{T}, n::Int) unsafe_copy!(pointer(arr), Ptr{T}(pointer(buffer, position+1)), n) arr end -Base.read{T}(io::BufferedReader, ::Type{T}, n::Integer) = +Base.read(io::BufferedReader, ::Type{T}, n::Integer) where {T} = read(io, T, Int(n)) Base.position(io::BufferedReader) = io.file_position + io.position[] diff --git a/src/data.jl b/src/data.jl index a0553d98..6d8bc62a 100644 --- a/src/data.jl +++ b/src/data.jl @@ -84,7 +84,7 @@ function samelayout(T::DataType) return offset == T.size end -fieldnames{T<:Tuple}(x::Type{T}) = [Symbol(x) for x = 1:length(x.types)] +fieldnames(x::Type{T}) where {T<:Tuple} = [Symbol(x) for x = 1:length(x.types)] fieldnames(x::ANY) = Base.fieldnames(x) # fieldodr gives the on-disk representation of a field of a given type, @@ -108,8 +108,8 @@ end # h5fieldtype is fieldodr's HDF5 companion. It should give the HDF5 # datatype reflecting the on-disk representation. -@generated function h5fieldtype{T}(f::JLDFile, writeas::Type{T}, readas::Type, - initialized::Initialized) +@generated function h5fieldtype(f::JLDFile, writeas::Type{T}, readas::Type, + initialized::Initialized) where T if isleaftype(T) if !hasfielddata(T) return nothing @@ -480,13 +480,13 @@ end # h5convert! stores the HDF5 representation of Julia data to a pointer. This # method handles types with no padding or references where this is just a simple # store -h5convert!{T}(out::Pointers, ::Type{T}, ::JLDFile, x, ::JLDWriteSession) = +h5convert!(out::Pointers, ::Type{T}, ::JLDFile, x, ::JLDWriteSession) where {T} = (unsafe_store!(convert(Ptr{T}, out), x); nothing) # We pack types that have padding using a staged h5convert! method -@generated function h5convert!{Offsets,Types,H5Types}(out::Pointers, - ::OnDiskRepresentation{Offsets,Types,H5Types}, - file::JLDFile, x, wsession::JLDWriteSession) +@generated function h5convert!(out::Pointers, + ::OnDiskRepresentation{Offsets,Types,H5Types}, + file::JLDFile, x, wsession::JLDWriteSession) where {Offsets,Types,H5Types} T = x types = Types.parameters members = H5Types.parameters @@ -547,24 +547,24 @@ rconvert(T, x) = convert(T, x) odr_sizeof{T,ODR}(::Type{CustomSerialization{T,ODR}}) = odr_sizeof(ODR) # Usually we want to convert the object and then write it. -@inline h5convert!{T,ODR}(out::Pointers, ::Type{CustomSerialization{T,ODR}}, f::JLDFile, - x, wsession::JLDWriteSession) = +@inline h5convert!(out::Pointers, ::Type{CustomSerialization{T,ODR}}, f::JLDFile, + x, wsession::JLDWriteSession) where {T,ODR} = h5convert!(out, ODR, f, wconvert(T, x)::T, wsession) # When writing as a reference, we don't want to convert the object first. That # should happen automatically after write_dataset is called so that the written # object gets the right written_type attribute. -@inline h5convert!{T}(out::Pointers, odr::Type{CustomSerialization{T,RelOffset}}, - f::JLDFile, x, wsession::JLDWriteSession) = +@inline h5convert!(out::Pointers, odr::Type{CustomSerialization{T,RelOffset}}, + f::JLDFile, x, wsession::JLDWriteSession) where {T} = h5convert!(out, RelOffset, f, x, wsession) # When writing as a reference to something that's being custom-serialized as an # array, we have to convert the object first. -@inline h5convert!{T<:Array}(out::Pointers, odr::Type{CustomSerialization{T,RelOffset}}, - f::JLDFile, x, wsession::JLDWriteSession) = +@inline h5convert!(out::Pointers, odr::Type{CustomSerialization{T,RelOffset}}, + f::JLDFile, x, wsession::JLDWriteSession) where {T<:Array} = h5convert!(out, RelOffset, f, wconvert(T, x)::T, wsession) -h5convert_uninitialized!{T,ODR}(out::Pointers, odr::Type{CustomSerialization{T,ODR}}) = +h5convert_uninitialized!(out::Pointers, odr::Type{CustomSerialization{T,ODR}}) where {T,ODR} = h5convert_uninitialized!(out, ODR) jlconvert_canbeuninitialized{T,S,ODR}(::ReadRepresentation{T,CustomSerialization{S,ODR}}) = @@ -688,11 +688,11 @@ jlconvert_isinitialized{T}(::ReadRepresentation{T,RelOffset}, ptr::Ptr) = nothing end -h5convert!{T}(out::Pointers, ::Type{Vlen{T}}, f::JLDFile, x, wsession::JLDWriteSession) = +h5convert!(out::Pointers, ::Type{Vlen{T}}, f::JLDFile, x, wsession::JLDWriteSession) where {T} = store_vlen!(out, T, f, x, wsession) @assert odr_sizeof(Vlen) == sizeof(UInt128) -h5convert_uninitialized!{T<:Vlen}(out::Pointers, odr::Type{T}) = +h5convert_uninitialized!(out::Pointers, odr::Type{T}) where {T<:Vlen} = (unsafe_store!(convert(Ptr{Int128}, out), 0); nothing) # Read variable-length data given offset and length in ptr @@ -814,7 +814,7 @@ const H5TYPE_DATATYPE = CompoundDatatype( [H5TYPE_VLEN_UTF8, VariableLengthDatatype(ReferenceDatatype())] ) -function h5fieldtype{T<:DataType}(f::JLDFile, ::Type{T}, readas::Type, ::Initialized) +function h5fieldtype(f::JLDFile, ::Type{T}, readas::Type, ::Initialized) where T<:DataType if !(readas <: DataType) @lookup_committed f readas return commit(f, H5TYPE_DATATYPE, DataType, readas) @@ -840,7 +840,7 @@ function h5fieldtype{T<:DataType}(f::JLDFile, ::Type{T}, readas::Type, ::Initial end fieldodr{T<:DataType}(::Type{T}, ::Bool) = DataTypeODR() -h5type{T<:DataType}(f::JLDFile, ::Type{T}, x) = +h5type(f::JLDFile, ::Type{T}, x) where {T<:DataType} = h5fieldtype(f, DataType, typeof(x), Val{true}) odr{T<:DataType}(::Type{T}) = DataTypeODR() @@ -941,11 +941,11 @@ constructrr{T<:DataType}(::JLDFile, ::Type{T}, dt::CompoundDatatype, ::Vector{Re const H5TYPE_UNION = VariableLengthDatatype(H5TYPE_DATATYPE) -function h5fieldtype{T<:Union,S<:Union}(f::JLDFile, ::Type{T}, readas::Type{S}, ::Initialized) +function h5fieldtype(f::JLDFile, ::Type{T}, readas::Type{S}, ::Initialized) where {T<:Union,S<:Union} @lookup_committed f Union commit(f, H5TYPE_UNION, Union, Union) end -function h5fieldtype{T<:Union}(f::JLDFile, ::Type{T}, readas::Type, ::Initialized) +function h5fieldtype(f::JLDFile, ::Type{T}, readas::Type, ::Initialized) where T<:Union @lookup_committed f readas commit(f, H5TYPE_UNION, Union, readas) end @@ -953,7 +953,7 @@ fieldodr{T<:Union}(::Type{T}, ::Bool) = Vlen{DataTypeODR()} h5fieldtype(f::JLDFile, ::Type{Union{}}, ::Initialized) = nothing fieldodr(::Type{Union{}}, initialized::Bool) = nothing -h5type{T<:Union}(f::JLDFile, ::Type{T}, x::Any) = +h5type(f::JLDFile, ::Type{T}, x::Any) where {T<:Union} = h5fieldtype(f, Union, typeof(x), Val{true}) odr(::Type{Union}) = fieldodr(Union, true) @@ -1004,15 +1004,15 @@ end # This is all so that when you define a writeas method to write something as an # array, it writes a reference to the actual array where the datatype is # committed and has a written_type attribute. -function h5fieldtype{T<:Array}(f::JLDFile, ::Type{T}, readas::DataType, - ::Initialized) +function h5fieldtype(f::JLDFile, ::Type{T}, readas::DataType, + ::Initialized) where T<:Array @lookup_committed f readas commit(f, ReferenceDatatype(), T, readas) end -h5type{T<:Array}(f::JLDFile, ::Type{T}, x) = +h5type(f::JLDFile, ::Type{T}, x) where {T<:Array} = h5fieldtype(f, T, typeof(x), Val{true}) -_odr{T<:Array}(writtenas::Type{T}, readas::Type{T}, odr) = odr -_odr{T<:Array}(writtenas::Type{T}, readas::DataType, odr) = +_odr(writtenas::Type{T}, readas::Type{T}, odr) where {T<:Array} = odr +_odr(writtenas::Type{T}, readas::DataType, odr) where {T<:Array} = CustomSerialization{writtenas,RelOffset} function constructrr{T<:Array}(::JLDFile, ::Type{T}, dt::BasicDatatype, @@ -1189,7 +1189,7 @@ end # These need to go at the bottom. Also, JLD2 doesn't support custom serialization because # these methods are not guaranteed to work if you add methods to `writeas`. -@generated function h5type{T<:Array}(f::JLDFile, ::Type{T}, ::T) +@generated function h5type(f::JLDFile, ::Type{T}, ::T) where T<:Array if T <: Array{Union{}} return :(ReferenceDatatype()) end @@ -1340,7 +1340,7 @@ struct HasReferences <: DataMode end @Base.pure datamode(::DataType) = ReferenceFree() @Base.pure datamode(::FixedLengthString) = ReferenceFree() @Base.pure datamode(::Void) = ReferenceFree() -@generated function datamode{H5Types}(odr::OnDiskRepresentation{Offsets,JLTypes,H5Types} where {Offsets,JLTypes}) +@generated function datamode(odr::OnDiskRepresentation{Offsets,JLTypes,H5Types} where {Offsets,JLTypes}) where H5Types for ty in H5Types.parameters datamode(ty) == HasReferences() && return HasReferences() end diff --git a/src/dataio.jl b/src/dataio.jl index 0631e97e..10d5a75e 100644 --- a/src/dataio.jl +++ b/src/dataio.jl @@ -39,8 +39,8 @@ const MMAP_CUTOFF = 1048576 obj end -@inline function read_array!{T}(v::Array{T}, f::JLDFile{MmapIO}, - rr::ReadRepresentation{T,T}) +@inline function read_array!(v::Array{T}, f::JLDFile{MmapIO}, + rr::ReadRepresentation{T,T}) where T io = f.io inptr = io.curptr n = length(v) @@ -60,8 +60,8 @@ end v end -@inline function read_array!{T,RR}(v::Array{T}, f::JLDFile{MmapIO}, - rr::ReadRepresentation{T,RR}) +@inline function read_array!(v::Array{T}, f::JLDFile{MmapIO}, + rr::ReadRepresentation{T,RR}) where {T,RR} io = f.io inptr = io.curptr n = length(v) @@ -75,9 +75,9 @@ end v end -@inline function read_compressed_array!{T,RR}(v::Array{T}, f::JLDFile{MmapIO}, - rr::ReadRepresentation{T,RR}, - data_length::Int) +@inline function read_compressed_array!(v::Array{T}, f::JLDFile{MmapIO}, + rr::ReadRepresentation{T,RR}, + data_length::Int) where {T,RR} io = f.io inptr = io.curptr data = read(ZlibInflateInputStream(unsafe_wrap(Array, Ptr{UInt8}(inptr), data_length); gzip=false)) @@ -91,8 +91,8 @@ end v end -function write_data{S}(io::MmapIO, f::JLDFile, data, odr::S, ::ReferenceFree, - wsession::JLDWriteSession) +function write_data(io::MmapIO, f::JLDFile, data, odr::S, ::ReferenceFree, + wsession::JLDWriteSession) where S io = f.io ensureroom(io, odr_sizeof(odr)) cp = io.curptr @@ -102,8 +102,8 @@ function write_data{S}(io::MmapIO, f::JLDFile, data, odr::S, ::ReferenceFree, nothing end -function write_data{S}(io::MmapIO, f::JLDFile, data, odr::S, ::HasReferences, - wsession::JLDWriteSession) +function write_data(io::MmapIO, f::JLDFile, data, odr::S, ::HasReferences, + wsession::JLDWriteSession) where S io = f.io ensureroom(io, odr_sizeof(odr)) p = position(io) @@ -148,12 +148,12 @@ else end end -write_data{T}(io::MmapIO, f::JLDFile, data::Array{T}, odr::Type{T}, ::ReferenceFree, - wsession::JLDWriteSession) = +write_data(io::MmapIO, f::JLDFile, data::Array{T}, odr::Type{T}, ::ReferenceFree, + wsession::JLDWriteSession) where {T} = raw_write(io, Ptr{UInt8}(pointer(data)), odr_sizeof(odr) * length(data)) -function write_data{T,S}(io::MmapIO, f::JLDFile, data::Array{T}, odr::S, ::ReferenceFree, - wsession::JLDWriteSession) +function write_data(io::MmapIO, f::JLDFile, data::Array{T}, odr::S, ::ReferenceFree, + wsession::JLDWriteSession) where {T,S} io = f.io ensureroom(io, odr_sizeof(odr) * length(data)) cp = cporig = io.curptr @@ -166,8 +166,8 @@ function write_data{T,S}(io::MmapIO, f::JLDFile, data::Array{T}, odr::S, ::Refer nothing end -function write_data{T,S}(io::MmapIO, f::JLDFile, data::Array{T}, odr::S, ::HasReferences, - wsession::JLDWriteSession) +function write_data(io::MmapIO, f::JLDFile, data::Array{T}, odr::S, ::HasReferences, + wsession::JLDWriteSession) where {T,S} io = f.io ensureroom(io, odr_sizeof(odr) * length(data)) p = position(io) @@ -196,9 +196,9 @@ end jlconvert(rr, f, pointer(r), header_offset) end -@inline function read_compressed_array!{T,RR}(v::Array{T}, f::JLDFile{IOStream}, - rr::ReadRepresentation{T,RR}, - data_length::Int) +@inline function read_compressed_array!(v::Array{T}, f::JLDFile{IOStream}, + rr::ReadRepresentation{T,RR}, + data_length::Int) where {T,RR} io = f.io data_offset = position(io) n = length(v) @@ -213,14 +213,14 @@ end v end -@inline function read_array!{T}(v::Array{T}, f::JLDFile{IOStream}, - rr::ReadRepresentation{T,T}) +@inline function read_array!(v::Array{T}, f::JLDFile{IOStream}, + rr::ReadRepresentation{T,T}) where T unsafe_read(f.io, pointer(v), odr_sizeof(T)*length(v)) v end -@inline function read_array!{T,RR}(v::Array{T}, f::JLDFile{IOStream}, - rr::ReadRepresentation{T,RR}) +@inline function read_array!(v::Array{T}, f::JLDFile{IOStream}, + rr::ReadRepresentation{T,RR}) where {T,RR} n = length(v) nb = odr_sizeof(RR)*n io = f.io @@ -234,28 +234,28 @@ end v end -function write_data{S}(io::BufferedWriter, f::JLDFile, data, odr::S, ::DataMode, - wsession::JLDWriteSession) +function write_data(io::BufferedWriter, f::JLDFile, data, odr::S, ::DataMode, + wsession::JLDWriteSession) where S position = io.position[] h5convert!(Ptr{Void}(pointer(io.buffer, position+1)), odr, f, data, wsession) io.position[] = position + odr_sizeof(odr) nothing end -function write_data{T}(io::BufferedWriter, f::JLDFile, data::Array{T}, odr::Type{T}, ::ReferenceFree, - wsession::JLDWriteSession) +function write_data(io::BufferedWriter, f::JLDFile, data::Array{T}, odr::Type{T}, ::ReferenceFree, + wsession::JLDWriteSession) where T unsafe_write(io, Ptr{UInt8}(pointer(data)), odr_sizeof(odr) * length(data)) nothing end -function write_data{T}(io::IOStream, f::JLDFile, data::Array{T}, odr::Type{T}, ::ReferenceFree, - wsession::JLDWriteSession) +function write_data(io::IOStream, f::JLDFile, data::Array{T}, odr::Type{T}, ::ReferenceFree, + wsession::JLDWriteSession) where T unsafe_write(io, Ptr{UInt8}(pointer(data)), odr_sizeof(odr) * length(data)) nothing end -function write_data{T,S}(io::BufferedWriter, f::JLDFile, data::Array{T}, odr::S, - ::DataMode, wsession::JLDWriteSession) +function write_data(io::BufferedWriter, f::JLDFile, data::Array{T}, odr::S, + ::DataMode, wsession::JLDWriteSession) where {T,S} position = io.position[] cp = Ptr{Void}(pointer(io.buffer, position+1)) @simd for i = 1:length(data) @@ -270,8 +270,8 @@ function write_data{T,S}(io::BufferedWriter, f::JLDFile, data::Array{T}, odr::S, nothing end -function write_data{T,S}(io::IOStream, f::JLDFile, data::Array{T}, odr::S, wm::DataMode, - wsession::JLDWriteSession) +function write_data(io::IOStream, f::JLDFile, data::Array{T}, odr::S, wm::DataMode, + wsession::JLDWriteSession) where {T,S} nb = odr_sizeof(odr) * length(data) buf = Vector{UInt8}(nb) pos = position(io) diff --git a/src/datasets.jl b/src/datasets.jl index 1cea55ef..258c3658 100644 --- a/src/datasets.jl +++ b/src/datasets.jl @@ -237,8 +237,8 @@ function find_dimensions_attr(attributes::Vector{ReadAttribute}) dimensions_attr_index end -function read_empty{T}(rr::ReadRepresentation{T}, f::JLDFile, - dimensions_attr::ReadAttribute, header_offset::RelOffset) +function read_empty(rr::ReadRepresentation{T}, f::JLDFile, + dimensions_attr::ReadAttribute, header_offset::RelOffset) where T dimensions_attr.datatype_class == DT_FIXED_POINT || throw(UnsupportedFeatureException()) io = f.io @@ -305,10 +305,10 @@ function construct_array{T}(io::IO, ::Type{T}, ndims::Int)::Array{T} end -function read_array{T,RR}(f::JLDFile, dataspace::ReadDataspace, - rr::ReadRepresentation{T,RR}, data_length::Int, - filter_id::UInt16, header_offset::RelOffset, - attributes::Union{Vector{ReadAttribute},Void}) +function read_array(f::JLDFile, dataspace::ReadDataspace, + rr::ReadRepresentation{T,RR}, data_length::Int, + filter_id::UInt16, header_offset::RelOffset, + attributes::Union{Vector{ReadAttribute},Void}) where {T,RR} io = f.io data_offset = position(io) ndims, offset = get_ndims_offset(f, dataspace, attributes) @@ -337,7 +337,7 @@ end unsafe_isdefined(arr::Array, i::Int) = unsafe_load(Ptr{Ptr{Void}}(pointer(arr)+(i-1)*sizeof(Ptr{Void}))) != Ptr{Void}(0) -function deflate_data{T,S}(f::JLDFile, data::Array{T}, odr::S, wsession::JLDWriteSession) +function deflate_data(f::JLDFile, data::Array{T}, odr::S, wsession::JLDWriteSession) where {T,S} buf = Vector{UInt8}(odr_sizeof(odr) * length(data)) cp = Ptr{Void}(pointer(buf)) @simd for i = 1:length(data) @@ -347,7 +347,7 @@ function deflate_data{T,S}(f::JLDFile, data::Array{T}, odr::S, wsession::JLDWrit read(ZlibDeflateInputStream(buf; gzip=false)) end -function write_dataset{T,S}(f::JLDFile, dataspace::WriteDataspace, datatype::H5Datatype, odr::S, data::Array{T}, wsession::JLDWriteSession) +function write_dataset(f::JLDFile, dataspace::WriteDataspace, datatype::H5Datatype, odr::S, data::Array{T}, wsession::JLDWriteSession) where {T,S} io = f.io datasz = odr_sizeof(odr) * numel(dataspace) layout_class = datasz < 8192 ? LC_COMPACT_STORAGE : @@ -404,7 +404,7 @@ function write_dataset{T,S}(f::JLDFile, dataspace::WriteDataspace, datatype::H5D h5offset(f, header_offset) end -function write_dataset{S}(f::JLDFile, dataspace::WriteDataspace, datatype::H5Datatype, odr::S, data, wsession::JLDWriteSession) +function write_dataset(f::JLDFile, dataspace::WriteDataspace, datatype::H5Datatype, odr::S, data, wsession::JLDWriteSession) where S io = f.io datasz = odr_sizeof(odr) * numel(dataspace) psz = payload_size_without_storage_message(dataspace, datatype) + sizeof(CompactStorageMessage) + datasz @@ -485,7 +485,7 @@ define_packed(ContiguousStorageMessage) @inline chunked_storage_message_size(ndims::Int) = sizeof(HeaderMessage) + 5 + (ndims+1)*sizeof(Length) + 1 + sizeof(Length) + 4 + sizeof(RelOffset) -function write_chunked_storage_message{N}(io::IO, elsize::Int, dims::NTuple{N,Int}, filtered_size::Int, offset::RelOffset) +function write_chunked_storage_message(io::IO, elsize::Int, dims::NTuple{N,Int}, filtered_size::Int, offset::RelOffset) where N write(io, HeaderMessage(HM_DATA_LAYOUT, chunked_storage_message_size(N) - sizeof(HeaderMessage), 0)) write(io, UInt8(4)) # Version write(io, UInt8(LC_CHUNKED_STORAGE)) # Layout Class diff --git a/src/dataspaces.jl b/src/dataspaces.jl index ceb912cb..f38022b9 100644 --- a/src/dataspaces.jl +++ b/src/dataspaces.jl @@ -32,11 +32,11 @@ const EMPTY_DIMENSIONS = Int[] # Pass-through for custom serializations # Need a bunch of methods to avoid ambiguity -WriteDataspace{S,ODR}(f::JLDFile, x, ::Type{CustomSerialization{S,ODR}}) = +WriteDataspace(f::JLDFile, x, ::Type{CustomSerialization{S,ODR}}) where {S,ODR} = WriteDataspace(f, x, ODR) -WriteDataspace{S,ODR}(f::JLDFile, x::Array, ::Type{CustomSerialization{S,ODR}}) = +WriteDataspace(f::JLDFile, x::Array, ::Type{CustomSerialization{S,ODR}}) where {S,ODR} = WriteDataspace(f, x, ODR) -WriteDataspace{T,S,ODR}(f::JLDFile, x::Array{T,0}, ::Type{CustomSerialization{S,ODR}}) = +WriteDataspace(f::JLDFile, x::Array{T,0}, ::Type{CustomSerialization{S,ODR}}) where {T,S,ODR} = WriteDataspace(f, x, ODR) WriteDataspace() = WriteDataspace(DS_NULL, (), ()) @@ -44,12 +44,12 @@ WriteDataspace(::JLDFile, ::Any, odr::Void) = WriteDataspace() WriteDataspace(::JLDFile, ::Any, ::Any) = WriteDataspace(DS_SCALAR, (), ()) # Ghost type array -WriteDataspace{T}(f::JLDFile, x::Array{T}, ::Void) = +WriteDataspace(f::JLDFile, x::Array{T}, ::Void) where {T} = WriteDataspace(DS_NULL, (), (WrittenAttribute(f, :dimensions, Int64[x for x in reverse(size(x))]),)) # Reference array -WriteDataspace{T,N}(f::JLDFile, x::Array{T,N}, ::Type{RelOffset}) = +WriteDataspace(f::JLDFile, x::Array{T,N}, ::Type{RelOffset}) where {T,N} = WriteDataspace(DS_SIMPLE, convert(Tuple{Vararg{Length}}, reverse(size(x))), (WrittenAttribute(f, :julia_type, write_ref(f, T, f.datatype_wsession)),)) @@ -58,14 +58,14 @@ WriteDataspace(f::JLDFile, x::Array, ::Any) = WriteDataspace(DS_SIMPLE, convert(Tuple{Vararg{Length}}, reverse(size(x))), ()) # Zero-dimensional arrays need an empty dimensions attribute -WriteDataspace{T}(f::JLDFile, x::Array{T,0}, ::Void) = +WriteDataspace(f::JLDFile, x::Array{T,0}, ::Void) where {T} = WriteDataspace(DS_NULL, (Length(1),), (WrittenAttribute(f, :dimensions, EMPTY_DIMENSIONS))) -WriteDataspace{T}(f::JLDFile, x::Array{T,0}, ::Type{RelOffset}) = +WriteDataspace(f::JLDFile, x::Array{T,0}, ::Type{RelOffset}) where {T} = WriteDataspace(DS_SIMPLE, (Length(1),), (WrittenAttribute(f, :julia_type, write_ref(f, T, f.datatype_wsession)), WrittenAttribute(f, :dimensions, EMPTY_DIMENSIONS))) -WriteDataspace{T}(f::JLDFile, x::Array{T,0}, ::Any) = +WriteDataspace(f::JLDFile, x::Array{T,0}, ::Any) where {T} = WriteDataspace(DS_SIMPLE, (Length(1),), (WrittenAttribute(f, :dimensions, EMPTY_DIMENSIONS),)) @@ -73,7 +73,7 @@ sizeof{N}(::Union{WriteDataspace{N},Type{WriteDataspace{N}}}) = 4 + sizeof(Lengt numel(x::WriteDataspace{0}) = x.dataspace_type == DS_SCALAR ? 1 : 0 numel(x::WriteDataspace) = Int(prod(x.size)) -function Base.write{N}(io::IO, dspace::WriteDataspace{N}) +function Base.write(io::IO, dspace::WriteDataspace{N}) where N write(io, DataspaceStart(2, N, 0, dspace.dataspace_type)) for x in dspace.size write(io, x::Length) diff --git a/src/global_heaps.jl b/src/global_heaps.jl index 83b18be4..3da14107 100644 --- a/src/global_heaps.jl +++ b/src/global_heaps.jl @@ -117,7 +117,7 @@ function Base.read(io::IO, ::Type{GlobalHeap}) GlobalHeap(offset, heapsz, free, objects) end -function read_heap_object{T,RR}(f::JLDFile, hid::GlobalHeapID, rr::ReadRepresentation{T,RR}) +function read_heap_object(f::JLDFile, hid::GlobalHeapID, rr::ReadRepresentation{T,RR}) where {T,RR} io = f.io if haskey(f.global_heaps, hid.heap_offset) gh = f.global_heaps[hid.heap_offset] diff --git a/src/groups.jl b/src/groups.jl index 666dbea8..a3cea5c9 100644 --- a/src/groups.jl +++ b/src/groups.jl @@ -14,7 +14,7 @@ Group(f::JLDFile, name::AbstractString) = Group(f.root_group, name) Construct a group named `name` as a child of group `g`. """ -Group{T}(g::Group{T}, name::AbstractString) = (g[name] = Group{T}(g.f)) +Group(g::Group{T}, name::AbstractString) where {T} = (g[name] = Group{T}(g.f)) """ lookup_offset(g::Group, name::AbstractString) -> RelOffset diff --git a/src/mmapio.jl b/src/mmapio.jl index 8fb5d643..56937826 100644 --- a/src/mmapio.jl +++ b/src/mmapio.jl @@ -212,7 +212,7 @@ end @inline Base.read(io::MmapIO, T::Type{Int8}) = _read(io, T) @inline Base.read(io::MmapIO, T::PlainType) = _read(io, T) -function Base.read{T}(io::MmapIO, ::Type{T}, n::Int) +function Base.read(io::MmapIO, ::Type{T}, n::Int) where T cp = io.curptr ep = cp + sizeof(T)*n ep > io.endptr && throw(EOFError()) @@ -221,7 +221,7 @@ function Base.read{T}(io::MmapIO, ::Type{T}, n::Int) io.curptr = ep arr end -Base.read{T}(io::MmapIO, ::Type{T}, n::Integer) = +Base.read(io::MmapIO, ::Type{T}, n::Integer) where {T} = read(io, T, Int(n)) # Read a null-terminated string diff --git a/test/customserialization.jl b/test/customserialization.jl index 19d966bc..7d53c02f 100644 --- a/test/customserialization.jl +++ b/test/customserialization.jl @@ -1,29 +1,29 @@ using JLD2, Base.Test -immutable SingleFieldWrapper{T} +struct SingleFieldWrapper{T} x::T end Base.:(==)(a::SingleFieldWrapper, b::SingleFieldWrapper) = a.x == b.x -immutable MultiFieldWrapper{T} +struct MultiFieldWrapper{T} x::T y::Int end Base.:(==)(a::MultiFieldWrapper, b::MultiFieldWrapper) = (a.x == b.x && a.y == b.y) -immutable UntypedWrapper +struct UntypedWrapper x end Base.:(==)(a::UntypedWrapper, b::UntypedWrapper) = a.x == b.x # This is a type with a custom serialization, where the original type has data # but the custom serialization is empty -immutable CSA +struct CSA x::Ptr{Void} end a = CSA(Ptr{Void}(0)) -immutable CSASerialization end +struct CSASerialization end JLD2.writeas(::Type{CSA}) = CSASerialization function JLD2.wconvert(::Type{CSASerialization}, x::CSA) global converted = true @@ -36,10 +36,10 @@ end # This is a type with a custom serialization, where the original type has no # data but the custom serialization does -immutable CSB end +struct CSB end b = CSB() -immutable CSBSerialization +struct CSBSerialization x::Int end JLD2.writeas(::Type{CSB}) = CSBSerialization @@ -54,13 +54,13 @@ end # This is a type where the custom serialized data can be stored inline when it # is a field of another type, but the original data could not -type CSC +mutable struct CSC x::Vector{Int} end Base.:(==)(a::CSC, b::CSC) = a.x == b.x c = CSC(rand(Int, 2)) -immutable CSCSerialization +struct CSCSerialization a::Int b::Int end @@ -76,13 +76,13 @@ end # This is a type where the original data could be stored inline when it is a # field of another type, but the custom serialized data cannot -immutable CSD +struct CSD a::Int b::Int end d = CSD(rand(Int), rand(Int)) -immutable CSDSerialization +struct CSDSerialization x::Vector{Int} end JLD2.writeas(::Type{CSD}) = CSDSerialization @@ -96,7 +96,7 @@ function JLD2.rconvert(::Type{CSD}, x::CSDSerialization) end # This is a type that gets written as an array -immutable CSE +struct CSE a::Int b::Int c::Int @@ -114,7 +114,7 @@ function JLD2.rconvert(::Type{CSE}, x::Vector{Int}) end # This is a type that is custom-serialized as an Int -immutable CSF +struct CSF x::Int end f = CSF(rand(Int)) @@ -130,7 +130,7 @@ function Base.convert(::Type{CSF}, x::Int) end # This is a type that is custom-serialized as a String -immutable CSG +struct CSG x::Int end g = CSG(rand(Int)) @@ -146,7 +146,7 @@ function Base.convert(::Type{CSG}, x::String) end # This is a type that is custom-serialized as a DataType -immutable CSH +struct CSH T::DataType N::Int end @@ -163,7 +163,7 @@ function Base.convert{T,N}(::Type{CSH}, x::Type{Array{T,N}}) end # This is a type that is custom-serialized as a Union -immutable CSK +struct CSK T::DataType S::DataType end diff --git a/test/rw.jl b/test/rw.jl index c9636a0e..6781bdb7 100644 --- a/test/rw.jl +++ b/test/rw.jl @@ -351,7 +351,7 @@ fn = joinpath(tempdir(),"test.jld") # Issue #106 module Mod106 primitive type Typ{T} 64 end -typ{T}(x::Int64, ::Type{T}) = Base.box(Typ{T}, Base.unbox(Int64,x)) +typ(x::Int64, ::Type{T}) where {T} = Base.box(Typ{T}, Base.unbox(Int64,x)) abstract type UnexportedT end end