Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RefArray issue on julia nightly #73

Merged
merged 8 commits into from
Nov 29, 2023
Merged

Conversation

IanButterworth
Copy link
Member

@IanButterworth IanButterworth commented Nov 28, 2023

Fixes #74

try fix

  TypeError: in RefArray, in A, expected A<:(AbstractArray{Ptr{UInt8}}), got Type{Vector{Ptr{RGBA{N0f16}}}}
  Stacktrace:
    [1] Ref{Ptr{UInt8}}(a::Vector{Ptr{RGBA{N0f16}}})
      @ Base ./refpointer.jl:158
    [2] cconvert(::Type{Ptr{Ptr{UInt8}}}, a::Vector{Ptr{RGBA{N0f16}}})
      @ Base ./refpointer.jl:176
    [3] png_read_image(png_ptr::Ptr{Nothing}, image::Vector{Ptr{RGBA{N0f16}}})
      @ PNGFiles ~/work/PNGFiles.jl/PNGFiles.jl/gen/libpng/libpng_api.jl:558
    [4] _load!(buffer::Matrix{RGBA{N0f16}}, png_ptr::Ptr{Nothing}, info_ptr::Ptr{Nothing})
      @ PNGFiles ~/work/PNGFiles.jl/PNGFiles.jl/src/io.jl:256
    [5] #invokelatest#2
      @ ./essentials.jl:950 [inlined]
    [6] invokelatest
      @ ./essentials.jl:947 [inlined]
    [7] _load(png_ptr::Ptr{Nothing}, info_ptr::Ptr{Nothing}; gamma::Nothing, expand_paletted::Bool, background::Bool)
      @ PNGFiles ~/work/PNGFiles.jl/PNGFiles.jl/src/io.jl:243
    [8] _load
      @ ~/work/PNGFiles.jl/PNGFiles.jl/src/io.jl:105 [inlined]
    [9] #4
      @ ~/work/PNGFiles.jl/PNGFiles.jl/src/io.jl:88 [inlined]
   [10] maybe_lock
      @ ~/work/PNGFiles.jl/PNGFiles.jl/src/io.jl:62 [inlined]
   [11] load(s::IOBuffer; gamma::Nothing, expand_paletted::Bool, background::Bool)
      @ PNGFiles ~/work/PNGFiles.jl/PNGFiles.jl/src/io.jl:80
   [12] load(s::IOBuffer)
      @ PNGFiles ~/work/PNGFiles.jl/PNGFiles.jl/src/io.jl:73
   [13] macro expansion
      @ ~/work/PNGFiles.jl/PNGFiles.jl/test/test_io.jl:16 [inlined]
   [14] macro expansion
      @ /opt/hostedtoolcache/julia/nightly/x64/share/julia/stdlib/v1.11/Test/src/Test.jl:676 [inlined]
   [15] macro expansion
      @ ~/work/PNGFiles.jl/PNGFiles.jl/test/test_io.jl:12 [inlined]
   [16] macro expansion
      @ /opt/hostedtoolcache/julia/nightly/x64/share/julia/stdlib/v1.11/Test/src/Test.jl:1598 [inlined]
   [17] top-level scope
      @ ~/work/PNGFiles.jl/PNGFiles.jl/test/test_io.jl:12

@IanButterworth
Copy link
Member Author

Using rawview(channelview(buf)) results in

AxisArrays: Error During Test at /home/runner/work/PNGFiles.jl/PNGFiles.jl/test/test_various_array_types.jl:27
  Got exception outside of a @test
  MethodError: no method matching strides(::MappedArrays.MappedArray{UInt8, 2, Base.ReinterpretArray{N0f8, 2, Gray{N0f8}, Matrix{Gray{N0f8}}, true}, typeof(reinterpret), ImageCore.var"#37#38"{N0f8}})
  
  Closest candidates are:
    strides(::LinearAlgebra.Transpose{<:Any, <:AbstractMatrix})
     @ LinearAlgebra /opt/hostedtoolcache/julia/nightly/x64/share/julia/stdlib/v1.11/LinearAlgebra/src/adjtrans.jl:350
    strides(::LinearAlgebra.Transpose{<:Any, <:AbstractVector})
     @ LinearAlgebra /opt/hostedtoolcache/julia/nightly/x64/share/julia/stdlib/v1.11/LinearAlgebra/src/adjtrans.jl:347
    strides(::Union{Base.ReinterpretArray{T, N, S, A, IsReshaped} where {T, N, A<:Union{SubArray{T, N, A, I, true} where {T, N, A<:DenseArray, I<:Union{Tuple{Vararg{Real}}, Tuple{AbstractUnitRange, Vararg{Any}}}}, DenseArray}, IsReshaped, S}, Base.ReshapedArray{T, N, A} where {T, N, A<:Union{Base.ReinterpretArray{T, N, S, A, IsReshaped} where {T, N, A<:Union{SubArray{T, N, A, I, true} where {T, N, A<:DenseArray, I<:Union{Tuple{Vararg{Real}}, Tuple{AbstractUnitRange, Vararg{Any}}}}, DenseArray}, IsReshaped, S}, SubArray{T, N, A, I, true} where {T, N, A<:DenseArray, I<:Union{Tuple{Vararg{Real}}, Tuple{AbstractUnitRange, Vararg{Any}}}}, DenseArray}}, DenseArray})
     @ Base reinterpretarray.jl:173
    ...
  
  Stacktrace:
    [1] _memory_offset(::MappedArrays.MappedArray{UInt8, 2, Base.ReinterpretArray{N0f8, 2, Gray{N0f8}, Matrix{Gray{N0f8}}, true}, typeof(reinterpret), ImageCore.var"#37#38"{N0f8}}, ::Int64, ::Int64)
      @ Base ./abstractarray.jl:1265
    [2] unsafe_convert(::Type{Ptr{UInt8}}, V::SubArray{UInt8, 1, MappedArrays.MappedArray{UInt8, 2, Base.ReinterpretArray{N0f8, 2, Gray{N0f8}, Matrix{Gray{N0f8}}, true}, typeof(reinterpret), ImageCore.var"#37#38"{N0f8}}, Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}, true})
      @ Base ./reshapedarray.jl:325
    [3] pointer(x::SubArray{UInt8, 1, MappedArrays.MappedArray{UInt8, 2, Base.ReinterpretArray{N0f8, 2, Gray{N0f8}, Matrix{Gray{N0f8}}, true}, typeof(reinterpret), ImageCore.var"#37#38"{N0f8}}, Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}, true})
      @ Base ./abstractarray.jl:1255
    [4] iterate
      @ ./generator.jl:48 [inlined]
    [5] _collect(c::ColumnSlices{Matrix{UInt8}, Tuple{Base.OneTo{Int64}}, SubArray{UInt8, 1, Matrix{UInt8}, Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}, true}}, itr::Base.Generator{ColumnSlices{Matrix{UInt8}, Tuple{Base.OneTo{Int64}}, SubArray{UInt8, 1, Matrix{UInt8}, Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}, true}}, typeof(pointer)}, ::Base.EltypeUnknown, isz::Base.HasShape{1})
      @ Base ./array.jl:793 [inlined]
    [6] collect_similar
      @ ./array.jl:702 [inlined]
    [7] map
      @ ./abstractarray.jl:3307 [inlined]
    [8] _write_image(buf::Matrix{Gray{N0f8}}, png_ptr::Ptr{Nothing}, info_ptr::Ptr{Nothing})
      @ PNGFiles ~/work/PNGFiles.jl/PNGFiles.jl/src/io.jl:520
    [9] _save(png_ptr::Ptr{Nothing}, info_ptr::Ptr{Nothing}, image::Matrix{Gray{N0f8}}; compression_level::Int64, compression_strategy::Int64, filters::Int64, file_gamma::Nothing, background::Nothing)
      @ PNGFiles ~/work/PNGFiles.jl/PNGFiles.jl/src/io.jl:507

src/io.jl Outdated
@@ -253,7 +253,7 @@ function _load(png_ptr, info_ptr; gamma::Union{Nothing,Float64}=nothing, expand_
end

function _load!(buffer::Matrix{T}, png_ptr, info_ptr) where T # separate to support precompilation of permutedims
png_read_image(png_ptr, map(pointer, eachcol(buffer)))
png_read_image(png_ptr, map(pointer, eachcol(reinterpret(UInt8, buffer))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
png_read_image(png_ptr, map(pointer, eachcol(reinterpret(UInt8, buffer))))
png_read_image(png_ptr, map(a -> Ptr(Ptr{UInt8}}(pointer(a)), eachcol(buffer)))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correcting what I assume is a { typo

Suggested change
png_read_image(png_ptr, map(pointer, eachcol(reinterpret(UInt8, buffer))))
png_read_image(png_ptr, map(a -> Ptr{Ptr{UInt8}}(pointer(a)), eachcol(buffer)))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hits

OffsetArrays: Error During Test at /home/runner/work/PNGFiles.jl/PNGFiles.jl/test/test_various_array_types.jl:12
  Got exception outside of a @test
  TypeError: in RefArray, in A, expected A<:(AbstractArray{Ptr{UInt8}}), got Type{Vector{Ptr{Ptr{UInt8}}}}
  Stacktrace:
    [1] Ref{Ptr{UInt8}}(a::Vector{Ptr{Ptr{UInt8}}})
      @ Base ./refpointer.jl:158
    [2] cconvert(::Type{Ptr{Ptr{UInt8}}}, a::Vector{Ptr{Ptr{UInt8}}})
      @ Base ./refpointer.jl:176
    [3] png_read_image(png_ptr::Ptr{Nothing}, image::Vector{Ptr{Ptr{UInt8}}})
      @ PNGFiles ~/work/PNGFiles.jl/PNGFiles.jl/gen/libpng/libpng_api.jl:558
    [4] _load!(buffer::Matrix{Gray{N0f8}}, png_ptr::Ptr{Nothing}, info_ptr::Ptr{Nothing})
      @ PNGFiles ~/work/PNGFiles.jl/PNGFiles.jl/src/io.jl:256

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to just be one too many Ptrs. Pushed a fix

@IanButterworth IanButterworth merged commit 1f5604b into master Nov 29, 2023
16 checks passed
@IanButterworth IanButterworth deleted the ib/nightly_fix branch November 29, 2023 15:44
@Drvi
Copy link
Collaborator

Drvi commented Nov 29, 2023

Thanks for looking into this, @IanButterworth!

@IanButterworth
Copy link
Member Author

No probs. There are ~200 public dependents of this package now, so it was taking down a large part of pkgeval

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants