Skip to content

Commit

Permalink
fixup! Revert "Test and fix non-int-length bug in `view(::Memory, ::U…
Browse files Browse the repository at this point in the history
…nion{UnitRange, Base.OneTo})` (#53991)"
  • Loading branch information
KristofferC committed Jun 25, 2024
1 parent f42db3a commit 26f0068
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3081,7 +3081,7 @@ function _wrap(ref::MemoryRef{T}, dims::NTuple{N, Int}) where {T, N}
@boundscheck mem_len >= len || invalid_wrap_err(mem_len, dims, len)
if N != 1 && !(ref === GenericMemoryRef(mem) && len === mem_len)
mem = ccall(:jl_genericmemory_slice, Memory{T}, (Any, Ptr{Cvoid}, Int), mem, ref.ptr_or_offset, len)
ref = MemoryRef(mem)
ref = memoryref(mem)
end
return ref
end
Expand All @@ -3097,7 +3097,7 @@ end

@eval @propagate_inbounds function wrap(::Type{Array}, m::Memory{T}, dims::NTuple{N, Integer}) where {T, N}
dims = convert(Dims, dims)
ref = _wrap(MemoryRef(m), dims)
ref = _wrap(memoryref(m), dims)
$(Expr(:new, :(Array{T, N}), :ref, :dims))
end
@eval @propagate_inbounds function wrap(::Type{Array}, m::MemoryRef{T}, l::Integer) where {T}
Expand All @@ -3107,11 +3107,11 @@ end
end
@eval @propagate_inbounds function wrap(::Type{Array}, m::Memory{T}, l::Integer) where {T}
dims = (Int(l),)
ref = _wrap(MemoryRef(m), (l,))
ref = _wrap(memoryref(m), (l,))
$(Expr(:new, :(Array{T, 1}), :ref, :dims))
end
@eval @propagate_inbounds function wrap(::Type{Array}, m::Memory{T}) where {T}
ref = MemoryRef(m)
ref = memoryref(m)
dims = (length(m),)
$(Expr(:new, :(Array{T, 1}), :ref, :dims))
end
8 changes: 4 additions & 4 deletions base/iobuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ function take!(io::IOBuffer)
if nbytes == 0 || io.reinit
data = StringVector(0)
elseif io.writable
data = wrap(Array, MemoryRef(io.data, io.offset + 1), nbytes)
data = wrap(Array, memoryref(io.data, io.offset + 1), nbytes)
else
data = copyto!(StringVector(nbytes), 1, io.data, io.offset + 1, nbytes)
end
Expand All @@ -475,7 +475,7 @@ function take!(io::IOBuffer)
if nbytes == 0
data = StringVector(0)
elseif io.writable
data = wrap(Array, MemoryRef(io.data, io.ptr), nbytes)
data = wrap(Array, memoryref(io.data, io.ptr), nbytes)
else
data = read!(io, data)
end
Expand Down Expand Up @@ -503,8 +503,8 @@ Array allocation), as well as omits some checks.
"""
_unsafe_take!(io::IOBuffer) =
wrap(Array, io.size == io.offset ?
MemoryRef(Memory{UInt8}()) :
MemoryRef(io.data, io.offset + 1),
memoryref(Memory{UInt8}()) :
memoryref(io.data, io.offset + 1),
io.size - io.offset)

function write(to::IO, from::GenericIOBuffer)
Expand Down

0 comments on commit 26f0068

Please sign in to comment.