Skip to content

Commit

Permalink
use sizeof(::String) instead of length(::String) for conversion to Ml…
Browse files Browse the repository at this point in the history
…irStringRef

otherwise, we can't use 🍕 as a string attribute.
  • Loading branch information
Pangoraw authored and vchuravy committed Jan 16, 2024
1 parent aece250 commit 992a68e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/MLIR.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Base.cconvert(::Type{API.MlirStringRef}, s::AbstractString) =
# Directly create `MlirStringRef` instead of adding an extra ccall.
function Base.unsafe_convert(::Type{API.MlirStringRef}, s::Union{Symbol, String, AbstractVector{UInt8}})
p = Base.unsafe_convert(Ptr{Cchar}, s)
return API.MlirStringRef(p, length(s))
return API.MlirStringRef(p, sizeof(s))
end

module IR
Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@ using Test

include("examples.jl")
include("executionengine.jl")

@testset "MlirStringRef conversion" begin
s = "mlir 😄 α γ 🍕"

ms = Base.unsafe_convert(MLIR.API.MlirStringRef, s)
reconstructed = unsafe_string(Ptr{Cchar}(ms.data), ms.length)

@test s == reconstructed
end

0 comments on commit 992a68e

Please sign in to comment.