Skip to content

Commit

Permalink
returntype of unsafe_write
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasIsensee committed Sep 19, 2024
1 parent 05023d4 commit ec87ed5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
13 changes: 0 additions & 13 deletions src/bufferedio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,8 @@ function finish!(io::BufferedWriter)
nothing
end

function _write(io::BufferedWriter, x)
n = jlsizeof(x)
ensureroom(io, n)
jlunsafe_store!(Ptr{typeof(x)}(io.curptr), x)
io.curptr += n
end

jlwrite(io::BufferedWriter, x::Union{UInt8,Int8}) = _write(io, x)

function Base.unsafe_write(io::BufferedWriter, x::Ptr{UInt8}, n::UInt64)
ensureroom(io, n)
unsafe_copyto!(Ptr{UInt8}(io.curptr), x, n)
io.curptr += n
end

mutable struct BufferedReader{io} <: MemoryBackedIO
f::io
buffer::Vector{UInt8}
Expand Down
7 changes: 4 additions & 3 deletions src/mmapio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function Base.close(io::MmapIO)
close(io.f)
end

function _write(io::MmapIO, x)
function _write(io::MemoryBackedIO, x)
n = jlsizeof(x)
ensureroom(io, n)
jlunsafe_store!(Ptr{typeof(x)}(io.curptr), x)
Expand All @@ -189,10 +189,11 @@ end
jlwrite(io::MmapIO, x::Union{UInt8, Int8}) = _write(io, x)
jlwrite(io::MmapIO, x::Plain) = _write(io, x)

function Base.unsafe_write(io::MmapIO, x::Ptr{UInt8}, n::UInt)
function Base.unsafe_write(io::MemoryBackedIO, x::Ptr{UInt8}, n::UInt)
ensureroom(io, n)
unsafe_copyto!(Ptr{UInt8}(io.curptr), x, n)
io.curptr += n
n
end

@inline function _read(io::MmapIO, T::DataType)
Expand Down Expand Up @@ -256,7 +257,7 @@ struct IndirectPointer{P<:MemoryBackedIO}
offset::Int
end

IndirectPointer(io::MemoryBackedIO) = IndirectPointer(io, bufferpos(io))
IndirectPointer(io::MemoryBackedIO) = IndirectPointer(io, Int(bufferpos(io)))

Base.:+(x::IndirectPointer, y::Integer) = IndirectPointer(x.io, x.offset+y)
pconvert(::Type{Ptr{T}}, x::IndirectPointer) where {T} = Ptr{T}(x.io.curptr - bufferpos(x.io) + x.offset)
Expand Down

0 comments on commit ec87ed5

Please sign in to comment.