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

Deprecate utf16_is_*, utf16_get_supplementary, is_utf8_*, add @unexportedwarning macro, add tests #11976

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,55 @@ end

export MathConst, @math_const

# 11551

macro unexportedwarn(old, new)
meta = Expr(:meta, :noinline)
if isa(old,Symbol)
oldname = Expr(:quote, old)
newname = Expr(:quote, new)
Expr(:toplevel,
:(function $old(args...)
$meta
depwarn(string("Base.", $oldname, " was undocumented and unexported,\n",
"and has been removed. Use ", $newname, " instead,\n",
"however it is also undocumented and unexported, and may change in the future."),
$oldname)
$new(args...)
end))
elseif isa(old,Expr) && old.head == :call
oldcall = sprint(io->show_unquoted(io,old))
newcall = sprint(io->show_unquoted(io,new))
oldsym = if isa(old.args[1],Symbol)
old.args[1]
elseif isa(old.args[1],Expr) && old.args[1].head == :curly
old.args[1].args[1]
else
error("invalid usage of @unexportedwarn")
end
oldname = Expr(:quote, oldsym)
Expr(:toplevel,
:($(esc(old)) = begin
$meta
depwarn(string("Base.", $oldcall, " was undocumented and unexported,\n",
"and has been removed. Use ", $newcall, " instead,\n",
"however it is also undocumented and unexported, and may change in the future."),
$oldname)
$(esc(new))
end))
else
error("invalid usage of @unexportedwarn")
end
end

@unexportedwarn utf16_is_surrogate(ch::Uint16) Base.is_surrogate_codeunit(ch)
@unexportedwarn utf16_is_lead(ch::UInt16) Base.is_surrogate_lead(ch)
@unexportedwarn utf16_is_trail(ch::UInt16) Base.is_surrogate_trail(ch)
@unexportedwarn utf16_get_supplementary(lead::UInt16, trail::UInt16) Base.get_supplementary(lead, trail)

@unexportedwarn is_utf8_start(ch::UInt8) !Base.is_valid_continuation(ch)
@unexportedwarn is_utf8_continuation(ch::UInt8) Base.is_valid_continuation(ch)

# 11280, mmap

export msync
Expand Down
2 changes: 1 addition & 1 deletion test/choosetests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function choosetests(choices = [])
"arrayops", "tuple", "subarray", "reduce", "reducedim", "random",
"abstractarray", "intfuncs", "simdloop", "blas", "sparse",
"bitarray", "copy", "math", "fastmath", "functional",
"operators", "path", "ccall", "parse", "loading",
"operators", "path", "ccall", "parse", "loading", "deprecated",
"bigint", "sorting", "statistics", "spawn", "backtrace",
"priorityqueue", "file", "mmap", "version", "resolve",
"pollfd", "mpfr", "broadcast", "complex", "socket",
Expand Down
23 changes: 23 additions & 0 deletions test/deprecated.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

if (Base.JLOptions()).depwarn > 1
@test_throws ErrorException Base.utf16_is_surrogate(0xdc00)
@test_throws ErrorException Base.utf16_is_lead(0xd800)
@test_throws ErrorException Base.utf16_is_trail(0xdc00)
@test_throws ErrorException Base.utf16_get_supplementary(0xd800, 0xdc00)
@test_throws ErrorException Base.is_utf8_start(0x40)
@test_throws ErrorException Base.is_utf8_continuation(0x90)
else
olderr = STDERR
try
rd, wr = redirect_stderr()
@test Base.utf16_is_surrogate(0xdc00)
@test Base.utf16_is_lead(0xd800)
@test Base.utf16_is_trail(0xdc00)
@test Base.utf16_get_supplementary(0xd800, 0xdc00) == 0x10000
@test Base.is_utf8_start(0x40)
@test Base.is_utf8_continuation(0x90)
finally
redirect_stderr(olderr)
end
end