Skip to content

Commit 067925b

Browse files
authored
MDString: deprecate string in favor of convert. (#470)
1 parent 248d382 commit 067925b

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/core/metadata.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Metadata(val::Value) = Metadata(API.LLVMValueAsMetadata(val))
8383
Base.convert(T::Type{<:Metadata}, val::Value) = Metadata(val)::T
8484

8585

86-
## values
86+
## strings
8787

8888
export MDString
8989

@@ -95,7 +95,7 @@ register(MDString, API.LLVMMDStringMetadataKind)
9595
MDString(val::String) =
9696
MDString(API.LLVMMDStringInContext2(context(), val, length(val)))
9797

98-
function Base.string(md::MDString)
98+
function Base.convert(::Type{String}, md::MDString)
9999
len = Ref{Cuint}()
100100
ptr = API.LLVMGetMDString2(md, len)
101101
return unsafe_string(convert(Ptr{Int8}, ptr), len[])

src/deprecated.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ Base.@deprecate_binding ValueMetadataDict LLVM.InstructionMetadataDict
3333
@deprecate unsafe_delete!(::Module, f::Function) erase!(f)
3434
@deprecate unsafe_delete!(::Function, bb::BasicBlock) erase!(bb)
3535
@deprecate unsafe_delete!(::BasicBlock, inst::Instruction) erase!(inst)
36+
37+
@deprecate Base.string(md::MDString) convert(String, md) false
38+
function Base.show(io::IO, ::MIME"text/plain", md::MDString)
39+
str = @invoke string(md::Metadata)
40+
print(io, strip(str))
41+
end

test/core_tests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ end
870870

871871
@dispose ctx=Context() begin
872872
str = MDString("foo")
873-
@test string(str) == "foo"
873+
@test convert(String, str) == "foo"
874874

875875
# wrap as Value
876876
val = Value(str)

0 commit comments

Comments
 (0)