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

Conversion to pointer not defined for Base.ReinterpretArray on v1.11 and above #54725

Closed
jishnub opened this issue Jun 7, 2024 · 3 comments · Fixed by #55226
Closed

Conversion to pointer not defined for Base.ReinterpretArray on v1.11 and above #54725

jishnub opened this issue Jun 7, 2024 · 3 comments · Fixed by #55226
Assignees
Labels
arrays [a, r, r, a, y, s] regression 1.11 Regression in the 1.11 release
Milestone

Comments

@jishnub
Copy link
Contributor

jishnub commented Jun 7, 2024

I suspect this might have been discussed before, but I couldn't find it.

julia> VERSION
v"1.10.4"

julia> Base.unsafe_convert(Ptr{Float64}, reinterpret(Float64, ComplexF64[1.0]))
Ptr{Float64} @0x00007fc192837e20

but on v"1.11.0-beta2"

julia> Base.unsafe_convert(Ptr{Float64}, reinterpret(Float64, ComplexF64[1.0]))
ERROR: conversion to pointer not defined for Base.ReinterpretArray{Float64, 1, ComplexF64, Vector{ComplexF64}, false}
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] unsafe_convert(::Type{Ptr{Float64}}, a::Base.ReinterpretArray{Float64, 1, ComplexF64, Vector{ComplexF64}, false})
   @ Base ./pointer.jl:68
 [3] top-level scope
   @ REPL[1]:1

This occurs in ccall operations when trying to pass a ReinterpretArray to a C function (e.g. in https://github.com/JuliaAstro/FITSIO.jl/actions/runs/8897458859/job/24432396258?pr=196). The selevant snippet of the stacktrace is

     [1] error(s::String)
      @ Base ./error.jl:44
    [2] unsafe_convert(::Type{Ptr{Float64}}, a::Base.ReinterpretArray{Float64, 1, ComplexF64, Vector{ComplexF64}, false})
      @ Base ./pointer.jl:68
    [3] unsafe_convert(::Type{Ptr{Nothing}}, a::Base.ReinterpretArray{Float64, 1, ComplexF64, Vector{ComplexF64}, false})
      @ Base ./pointer.jl:66
    [4] fits_write_pix(f::FITSFile, fpixel::Tuple{Int64}, nelements::Int64, data::Base.ReinterpretArray{Float64, 1, ComplexF64, Vector{ComplexF64}, false})
      @ CFITSIO ~/.julia/packages/CFITSIO/zfTMn/src/CFITSIO.jl:1219
    [5] fits_write_pix(f::FITSFile, data::Base.ReinterpretArray{Float64, 1, ComplexF64, Vector{ComplexF64}, false})
      @ CFITSIO ~/.julia/packages/CFITSIO/zfTMn/src/CFITSIO.jl:1244

Here, the ccall in fits_write_pix on line 1219 takes the form

ccall(
        (:ffppxll, libcfitsio),
        Cint,
        (Ptr{Cvoid}, Cint, Ptr{NTuple{N,Int64}}, Int64, Ptr{Cvoid}, Ref{Cint}),
        f.ptr,
        cfitsio_typecode(eltype(data)),
        fpixelr,
        nelements,
        data,
        status,
    )

where data is a ReinterpretArray array.

Some other info:

julia> versioninfo()
Julia Version 1.11.0-beta2
Commit edb3c92d6a6 (2024-05-29 09:37 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, tigerlake)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)
Environment:
  LD_LIBRARY_PATH = :/usr/lib/x86_64-linux-gnu/gtk-3.0/modules
  JULIA_EDITOR = subl

and julia is installed through juliaup.

@jishnub jishnub added the regression 1.11 Regression in the 1.11 release label Jun 7, 2024
@nsajko nsajko added the arrays [a, r, r, a, y, s] label Jun 7, 2024
@nsajko
Copy link
Contributor

nsajko commented Jun 7, 2024

xref #51962?

@jishnub
Copy link
Contributor Author

jishnub commented Jun 7, 2024

It's probably a different issue, as cconvert is defined for a ReinterpretArray and a pointer may be obtained from it, but a direct unsafe_convert isn't defined anymore. It may simply be a matter of redefining the method, but I wonder if it was removed for a reason.

@vchuravy
Copy link
Member

vchuravy commented Jun 28, 2024

I ran into this just now as well.

 Error: Error in render loop!
│   exception = conversion to pointer not defined for Base.ReinterpretArray{ColorTypes.RGB{Float32}, 2, Float32, Array{Float32, 3}, true}
└ @ NeuralGraphicsGL ~/.julia/packages/NeuralGraphicsGL/5ny5N/src/NeuralGraphicsGL.jl:285

Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] unsafe_convert(::Type{Ptr{ColorTypes.RGB{Float32}}}, a::Base.ReinterpretArray{ColorTypes.RGB{Float32}, 2, Float32, Array{Float32, 3}, true})
    @ Base ./pointer.jl:68
  [3] unsafe_convert(::Type{Ptr{Nothing}}, a::Base.ReinterpretArray{ColorTypes.RGB{Float32}, 2, Float32, Array{Float32, 3}, true})
    @ Base ./pointer.jl:66
  [4] glTexImage2D(target::UInt32, level::Int64, internalformat::UInt32, width::UInt32, height::UInt32, border::Int64, format::UInt32, type_::UInt32, pixels::Base.ReinterpretArray{ColorTypes.RGB{Float32}, 2, Float32, Array{Float32, 3}, true})
    @ ModernGL ~/.julia/packages/ModernGL/yNrOu/src/functionloading.jl:64
  [5] macro expansion
    @ ~/.julia/packages/NeuralGraphicsGL/5ny5N/src/NeuralGraphicsGL.jl:72 [inlined]
  [6] set_data!(t::NeuralGraphicsGL.Texture, data::Base.ReinterpretArray{ColorTypes.RGB{Float32}, 2, Float32, Array{Float32, 3}, true})
    @ NeuralGraphicsGL ~/.julia/packages/NeuralGraphicsGL/5ny5N/src/texture.jl:89
  [7] set_data!
    @ ~/.julia/packages/NeuralGraphicsGL/5ny5N/src/quad.jl:77 [inlined]
  [8] render!(ngui::NerfGUI.NGUI)
    @ NerfGUI ~/src/NerfGUI/src/NerfGUI.jl:206
  [9] loop!(ngui::NerfGUI.NGUI)
    @ NerfGUI ~/src/NerfGUI/src/NerfGUI.jl:446
 [10] #32
    @ ~/src/NerfGUI/src/NerfGUI.jl:213 [inlined]
 [11] render_loop(draw_function::NerfGUI.var"#32#33"{NerfGUI.NGUI}, c::NeuralGraphicsGL.Context; destroy_context::Bool)
    @ NeuralGraphicsGL ~/.julia/packages/NeuralGraphicsGL/5ny5N/src/NeuralGraphicsGL.jl:281
 [12] render_loop
    @ ~/.julia/packages/NeuralGraphicsGL/5ny5N/src/NeuralGraphicsGL.jl:278 [inlined]
 [13] launch!
    @ ~/src/NerfGUI/src/NerfGUI.jl:211 [inlined]
 [14] main()
    @ NerfGUI ~/src/NerfGUI/src/NerfGUI.jl:487

Weirdly enough there is no direct call to unsafe_convert in sight.

https://github.com/JuliaGL/ModernGL.jl/blob/90200d81d1d0194f9855163524ecb499b8f2c881/src/functionloading.jl#L64

julia> @macroexpand ModernGL.@glfunc glTexImage2D(target::GLenum, level::GLint, internalformat::GLint, width::GLsizei, height::GLsizei, border::GLint, format::GLenum, type_::GLenum, pixels::Ptr{Cvoid})::Cvoid
quote
    #= /home/vchuravy/.julia/packages/ModernGL/yNrOu/src/functionloading.jl:59 =#
    const var"##glTexImage2D_func_pointer#231" = Ref{Ptr{Cvoid}}(C_NULL)
    #= /home/vchuravy/.julia/packages/ModernGL/yNrOu/src/functionloading.jl:60 =#
    function glTexImage2D(target, level, internalformat, width, height, border, format, type_, pixels)
        #= /home/vchuravy/.julia/packages/ModernGL/yNrOu/src/functionloading.jl:60 =#
        #= /home/vchuravy/.julia/packages/ModernGL/yNrOu/src/functionloading.jl:61 =#
        if var"##glTexImage2D_func_pointer#231"[]::Ptr{Cvoid} == C_NULL
            #= /home/vchuravy/.julia/packages/ModernGL/yNrOu/src/functionloading.jl:62 =#
            var"##glTexImage2D_func_pointer#231"[]::Ptr{Cvoid} = getprocaddress_e("glTexImage2D")
        end
        #= /home/vchuravy/.julia/packages/ModernGL/yNrOu/src/functionloading.jl:64 =#
        result = ccall(var"##glTexImage2D_func_pointer#231"[]::Ptr{Cvoid}, Cvoid, (GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, Ptr{Cvoid}), target, level, internalformat, width, height, border, format, type_, pixels)
        #= /home/vchuravy/.julia/packages/ModernGL/yNrOu/src/functionloading.jl:65 =#
        ()
        #= /home/vchuravy/.julia/packages/ModernGL/yNrOu/src/functionloading.jl:66 =#
        result
    end
    #= /home/vchuravy/.julia/packages/ModernGL/yNrOu/src/functionloading.jl:68 =#
    export glTexImage2D
end

-- edit:

cconvert

cconvert(::Type{Ptr{T}}, a::ReinterpretArray{T,N,S} where N) where {T,S} = cconvert(Ptr{S}, a.parent)
is only defined for Ptr{T}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] regression 1.11 Regression in the 1.11 release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants