Skip to content

Commit

Permalink
restrict to known non-offset-indexed inds
Browse files Browse the repository at this point in the history
  • Loading branch information
LilithHafner committed Mar 30, 2024
1 parent bc6f772 commit 91542bc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/genericmemory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ end
$(Expr(:new, :(Array{T, N}), :ref, :dims))
end

@eval function view(m::GenericMemory{M, T}, inds::AbstractUnitRange) where {M, T}
isempty(inds) && return T[] # needed to allow view(Memory{T}(undef, 0), 2:1)
@eval function view(m::GenericMemory{M, T}, inds::Union{UnitRange, OneTo}) where {M, T}
!(inds isa OneTo) && isempty(inds) && return T[] # needed to allow view(Memory{T}(undef, 0), 2:1)
@boundscheck checkbounds(m, inds)
ref = MemoryRef(m, first(inds)) # @inbounds here is not safe on view(Memory{T}(undef, 0), 2:1)
dims = (length(inds),)
Expand Down
3 changes: 3 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3215,6 +3215,9 @@ end
@test view(empty_mem, 1:0)::Vector{Module} == []
@test view(empty_mem, 10:3)::Vector{Module} == []
@test isempty(reshape(empty_mem, 0, 7, 1)::Array{Module, 3})

offset_inds = OffsetArrays.IdOffsetRange(values=3:6, indices=53:56)
@test view(collect(mem), offset_inds) == view(mem, offset_inds)
end

@testset "Memory size" begin
Expand Down

0 comments on commit 91542bc

Please sign in to comment.