Skip to content

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

Closed
@jishnub

Description

@jishnub

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.

Metadata

Metadata

Assignees

Labels

arrays[a, r, r, a, y, s]regression 1.11Regression in the 1.11 release

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions