Skip to content

Commit

Permalink
Merge pull request #29 from simonster/fbot/deps
Browse files Browse the repository at this point in the history
Fix deprecations
  • Loading branch information
simonster authored Aug 9, 2017
2 parents fd5eabd + c34d8ff commit 190da18
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 109 deletions.
4 changes: 2 additions & 2 deletions benchmark/benchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions src/JLD2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/bufferedio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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[]
Expand Down
56 changes: 28 additions & 28 deletions src/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}}) =
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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()

Expand Down Expand Up @@ -941,19 +941,19 @@ 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
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)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
68 changes: 34 additions & 34 deletions src/dataio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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))
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Loading

0 comments on commit 190da18

Please sign in to comment.