Skip to content
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
2 changes: 1 addition & 1 deletion src/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ cdf = CDFDataset("data.cdf")
```
"""
function CDFDataset(filename)
fname = String(filename)
fname = String(filename)::String
# `open(f, name, mode) do` form: routes through varargs splatting (`_apply_iterate`) which `juliac --trim` can't resolve.
io = open(fname, "r")
try
Expand Down
6 changes: 3 additions & 3 deletions src/loading/variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function _majority_swap!(data::Ptr{UInt8}, esz::Int, rdims::Vector{Int}, nrec::I
end
sstrides[k+1] = record_bytes
chunk = clamp((1 << 20) ÷ record_bytes, 1, nrec)
dims = [rdims; chunk]
dims = push!(copy(rdims), chunk)
temp = Vector{UInt8}(undef, chunk * record_bytes)
GC.@preserve temp for r0 in 0:chunk:(nrec-1)
n = min(chunk, nrec - r0)
Expand All @@ -89,7 +89,7 @@ function _copy_subblock!(dst::Ptr{UInt8}, src::Ptr{UInt8}, esz::Int, rdims::Vect
s *= rdims[i]
end
sstrides[k+1] = s
dims = [length.(ranges); nrec]
dims = push!(length.(ranges), nrec)
_copy_block!(dst, src + off, esz, dims, sstrides)
return
end
Expand All @@ -104,7 +104,7 @@ function DiskArrays.readblock!(var::CDFVariable{T,N}, dest::AbstractArray{T}, ra
rdims = Int[Base.front(var.dims)...]
other_ranges = UnitRange{Int}[Int(first(r)):Int(last(r)) for r in Base.front(ranges)]
rec_range = Int(first(ranges[end])):Int(last(ranges[end]))
GC.@preserve dest _readblock!(Ptr{UInt8}(pointer(dest)), sizeof(T), rdims, other_ranges, rec_range, var.vdr, var.parentdataset)
GC.@preserve dest _readblock!(Ptr{UInt8}(_ptr(dest)), sizeof(T), rdims, other_ranges, rec_range, var.vdr, var.parentdataset)
is_big_endian_encoding(var) && _byte_swap!(dest)
return dest
end
Expand Down
6 changes: 5 additions & 1 deletion src/parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,9 @@ function _swap_words!(p::Ptr{U}, n::Int) where {U}
end
return
end
# `pointer` goes through `cconvert`, so when `T` is not inferred any new
# `cconvert(::Type{Ptr{X}}, ::Vector)` method (e.g. LibGit2's) invalidates the caller.
_ptr(a::Array{T}) where {T} = Base.unsafe_convert(Ptr{T}, a)

_byte_swap!(data::Array{T}) where {T} =
GC.@preserve data _byte_swap!(Ptr{UInt8}(pointer(data)), sizeof(data), _swap_unit(T))
GC.@preserve data _byte_swap!(Ptr{UInt8}(_ptr(data)), sizeof(data), _swap_unit(T))
2 changes: 1 addition & 1 deletion src/records/aedr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ end

function load_attribute_data(::Type{T}, buffer::Vector{UInt8}, pos, NumElems, needs_byte_swap) where {T}
data = Vector{T}(undef, NumElems)
dst_ptr = pointer(data)
dst_ptr = _ptr(data)
src_ptr = convert(Ptr{T}, pointer(buffer, pos))
unsafe_copyto!(dst_ptr, src_ptr, NumElems)
needs_byte_swap && _byte_swap!(data)
Expand Down
Loading