Skip to content

Commit 7122b2e

Browse files
committed
Deprecate is_<os> functions in favor of Sys.is<os>
This makes them consistent with the vast majority of Base predicates, which simply prefix with `is` rather than `is_`. It also moves to requiring the `Sys.` prefix, which helps explain the intent behind the function names.
1 parent c67c523 commit 7122b2e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+345
-333
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ Deprecated or removed
139139
* The method `replace(s::AbstractString, pat, r, count)` with `count <= 0` is deprecated
140140
in favor of `replace(s::AbstractString, pat, r, typemax(Int))` ([#22325]).
141141

142+
* The operating system identification functions: `is_linux`, `is_bsd`, `is_apple`, `is_unix`,
143+
and `is_windows`, have been deprecated in favor of `Sys.islinux`, `Sys.isbsd`, `Sys.isapple`,
144+
`Sys.isunix`, and `Sys.iswindows`, respectively ([#22182]).
145+
142146

143147
Julia v0.6.0 Release Notes
144148
==========================
@@ -932,6 +936,7 @@ Command-line option changes
932936
[#22038]: https://github.com/JuliaLang/julia/issues/22038
933937
[#22062]: https://github.com/JuliaLang/julia/issues/22062
934938
[#22064]: https://github.com/JuliaLang/julia/issues/22064
939+
[#22182]: https://github.com/JuliaLang/julia/issues/22182
935940
[#22187]: https://github.com/JuliaLang/julia/issues/22187
936941
[#22188]: https://github.com/JuliaLang/julia/issues/22188
937942
[#22224]: https://github.com/JuliaLang/julia/issues/22224

base/c.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
import Core.Intrinsics: cglobal, bitcast
66

7+
# This is equivalent to Sys.iswindows(), but that's not defined yet.
8+
# FIXME: Do not use this constant outside of this file! We're only using it here
9+
# rather than repeating the ccall as needed to avoid a weird SIGABRT on Windows.
10+
# See PR #22182 for reference.
11+
const _jl_get_UNAME_eq_NT = ccall(:jl_get_UNAME, Any, ()) === :NT
12+
713
cfunction(f, r, a) = ccall(:jl_function_ptr, Ptr{Void}, (Any, Any, Any), f, r, a)
814

915
if ccall(:jl_is_char_signed, Ref{Bool}, ())
@@ -18,7 +24,8 @@ Equivalent to the native `char` c-type.
1824
"""
1925
Cchar
2026

21-
if is_windows()
27+
# The ccall is equivalent to Sys.iswindows(), but that's not defined yet
28+
if _jl_get_UNAME_eq_NT
2229
const Clong = Int32
2330
const Culong = UInt32
2431
const Cwchar_t = UInt16
@@ -49,7 +56,7 @@ Equivalent to the native `wchar_t` c-type ([`Int32`](@ref)).
4956
"""
5057
Cwchar_t
5158

52-
if !is_windows()
59+
if !_jl_get_UNAME_eq_NT
5360
const sizeof_mode_t = ccall(:jl_sizeof_mode_t, Cint, ())
5461
if sizeof_mode_t == 2
5562
const Cmode_t = Int16
@@ -118,7 +125,7 @@ end
118125
# symbols are guaranteed not to contain embedded NUL
119126
convert(::Type{Cstring}, s::Symbol) = Cstring(unsafe_convert(Ptr{Cchar}, s))
120127

121-
if is_windows()
128+
if _jl_get_UNAME_eq_NT
122129
"""
123130
Base.cwstring(s)
124131

base/client.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ function repl_cmd(cmd, out)
102102
end
103103
cd(ENV["OLDPWD"])
104104
else
105-
cd(@static is_windows() ? dir : readchomp(`$shell -c "echo $(shell_escape(dir))"`))
105+
cd(@static Sys.iswindows() ? dir : readchomp(`$shell -c "echo $(shell_escape(dir))"`))
106106
end
107107
else
108108
cd()
109109
end
110110
ENV["OLDPWD"] = new_oldpwd
111111
println(out, pwd())
112112
else
113-
run(ignorestatus(@static is_windows() ? cmd : (isa(STDIN, TTY) ? `$shell -i -c "$(shell_wrap_true(shell_name, cmd))"` : `$shell -c "$(shell_wrap_true(shell_name, cmd))"`)))
113+
run(ignorestatus(@static Sys.iswindows() ? cmd : (isa(STDIN, TTY) ? `$shell -i -c "$(shell_wrap_true(shell_name, cmd))"` : `$shell -c "$(shell_wrap_true(shell_name, cmd))"`)))
114114
end
115115
nothing
116116
end
@@ -390,7 +390,7 @@ function _start()
390390
global is_interactive |= !isa(STDIN, Union{File, IOStream})
391391
color_set || (global have_color = false)
392392
else
393-
term = Terminals.TTYTerminal(get(ENV, "TERM", @static is_windows() ? "" : "dumb"), STDIN, STDOUT, STDERR)
393+
term = Terminals.TTYTerminal(get(ENV, "TERM", @static Sys.iswindows() ? "" : "dumb"), STDIN, STDOUT, STDERR)
394394
global is_interactive = true
395395
color_set || (global have_color = Terminals.hascolor(term))
396396
quiet || REPL.banner(term,term)

base/dSFMT.jl

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

164164
## Windows entropy
165165

166-
if is_windows()
166+
if Sys.iswindows()
167167
function win32_SystemFunction036!(a::Array)
168168
ccall((:SystemFunction036, :Advapi32), stdcall, UInt8, (Ptr{Void}, UInt32), a, sizeof(a))
169169
end

base/datafmt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ readdlm_auto(input::IO, dlm::Char, T::Type, eol::Char, auto::Bool; opts...) =
120120
readdlm_string(readstring(input), dlm, T, eol, auto, val_opts(opts))
121121
function readdlm_auto(input::AbstractString, dlm::Char, T::Type, eol::Char, auto::Bool; opts...)
122122
optsd = val_opts(opts)
123-
use_mmap = get(optsd, :use_mmap, is_windows() ? false : true)
123+
use_mmap = get(optsd, :use_mmap, Sys.iswindows() ? false : true)
124124
fsz = filesize(input)
125125
if use_mmap && fsz > 0 && fsz < typemax(Int)
126126
a = open(input, "r") do f

base/deprecated.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,6 +1543,13 @@ end
15431543
@deprecate cat_t{N,T}(::Type{Val{N}}, ::Type{T}, A, B) cat_t(Val(N), T, A, B) false
15441544
@deprecate reshape{N}(A::AbstractArray, ::Type{Val{N}}) reshape(A, Val(N))
15451545

1546+
# PR #22182
1547+
@deprecate is_apple Sys.isapple
1548+
@deprecate is_bsd Sys.isbsd
1549+
@deprecate is_linux Sys.islinux
1550+
@deprecate is_unix Sys.isunix
1551+
@deprecate is_windows Sys.iswindows
1552+
15461553
# END 0.7 deprecations
15471554

15481555
# BEGIN 1.0 deprecations

base/distributed/cluster.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ end
975975
function disable_nagle(sock)
976976
# disable nagle on all OSes
977977
ccall(:uv_tcp_nodelay, Cint, (Ptr{Void}, Cint), sock.handle, 1)
978-
@static if is_linux()
978+
@static if Sys.islinux()
979979
# tcp_quickack is a linux only option
980980
if ccall(:jl_tcp_quickack, Cint, (Ptr{Void}, Cint), sock.handle, 1) < 0
981981
warn_once("Networking unoptimized ( Error enabling TCP_QUICKACK : ", Libc.strerror(Libc.errno()), " )")

base/distributed/managers.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ function socket_reuse_port()
460460
s = TCPSocket(delay = false)
461461

462462
# Some systems (e.g. Linux) require the port to be bound before setting REUSEPORT
463-
bind_early = is_linux()
463+
bind_early = Sys.islinux()
464464

465465
bind_early && bind_client_port(s)
466466
rc = ccall(:jl_tcp_reuseport, Int32, (Ptr{Void},), s.handle)

base/env.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
if is_windows()
3+
if Sys.iswindows()
44
const ERROR_ENVVAR_NOT_FOUND = UInt32(203)
55

66
_getenvlen(var::Vector{UInt16}) = ccall(:GetEnvironmentVariableW,stdcall,UInt32,(Ptr{UInt16},Ptr{UInt16},UInt32),var,C_NULL,0)
@@ -84,7 +84,7 @@ delete!(::EnvHash, k::AbstractString) = (_unsetenv(k); ENV)
8484
setindex!(::EnvHash, v, k::AbstractString) = _setenv(k,string(v))
8585
push!(::EnvHash, k::AbstractString, v) = setindex!(ENV, v, k)
8686

87-
if is_windows()
87+
if Sys.iswindows()
8888
start(hash::EnvHash) = (pos = ccall(:GetEnvironmentStringsW,stdcall,Ptr{UInt16},()); (pos,pos))
8989
function done(hash::EnvHash, block::Tuple{Ptr{UInt16},Ptr{UInt16}})
9090
if unsafe_load(block[1]) == 0

base/event.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ function wait()
247247
# unreachable
248248
end
249249

250-
if is_windows()
250+
if Sys.iswindows()
251251
pause() = ccall(:Sleep, stdcall, Void, (UInt32,), 0xffffffff)
252252
else
253253
pause() = ccall(:pause, Void, ())

0 commit comments

Comments
 (0)