GraphViz.jl icon indicating copy to clipboard operation
GraphViz.jl copied to clipboard

Wrong conversion of String to C String?

Open bvdmitri opened this issue 1 year ago • 3 comments

I noticed this line of code in GraphViz.jl package, but later on a String object being used here (note the format="julia:cairo"). It doesn't seem right? The function expects C string, not Julia string? Could it be the reason for https://github.com/JuliaLang/julia/issues/56150?

related PR https://github.com/JuliaLang/julia/pull/51275

bvdmitri avatar Dec 23 '24 12:12 bvdmitri

I couldn't patch it and test it with the change due to #44

bvdmitri avatar Dec 23 '24 12:12 bvdmitri

Also see this comment https://github.com/JuliaLang/julia/issues/56150#issuecomment-2559741955

bvdmitri avatar Dec 23 '24 14:12 bvdmitri

I found the line ccall((:gvRenderContext,libgvc),Cint,(Ptr{Cvoid},Ptr{Cvoid},Ptr{UInt8},Ptr{Cvoid}),context.handle,g.handle,format,C_NULL) returns -1 and prints the error Error: renderer for julia:cairo is unavailable. By changing the lines

const julia_cairo_name = Vector{UInt8}("julia:cairo")
const julia_cairo_libname = Vector{UInt8}("julia:cairo")

to

const julia_cairo_name = Base.unsafe_convert(Cstring,"julia:cairo")
const julia_cairo_libname = Base.unsafe_convert(Cstring,"julia:cairo")

it returns 0 with no error.

jhlq avatar Feb 04 '25 13:02 jhlq