Skip to content

Commit f342c7d

Browse files
committed
implement @static macro for replacing osutils macros
implements #5892 closes #6674 and #4233
1 parent e0e93fc commit f342c7d

Some content is hidden

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

57 files changed

+824
-666
lines changed

base/LineEdit.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function refresh_multi_line(termbuf::TerminalBuffer, terminal::UnixTerminal, buf
204204
write_prompt(termbuf, prompt)
205205
prompt = prompt_string(prompt)
206206
# Count the '\n' at the end of the line if the terminal emulator does (specific to DOS cmd prompt)
207-
miscountnl = @windows ? (isa(Terminals.pipe_reader(terminal), Base.TTY) && !Base.ispty(Terminals.pipe_reader(terminal))) : false
207+
miscountnl = @static is_windows() ? (isa(Terminals.pipe_reader(terminal), Base.TTY) && !Base.ispty(Terminals.pipe_reader(terminal))) : false
208208
lindent = strwidth(prompt)
209209

210210
# Now go through the buffer line by line
@@ -1564,7 +1564,7 @@ function run_interface(terminal, m::ModalInterface)
15641564
p = s.current_mode
15651565
buf, ok, suspend = prompt!(terminal, m, s)
15661566
while suspend
1567-
@unix_only ccall(:jl_repl_raise_sigtstp, Cint, ())
1567+
@static if is_unix(); ccall(:jl_repl_raise_sigtstp, Cint, ()); end
15681568
buf, ok, suspend = prompt!(terminal, m, s)
15691569
end
15701570
mode(state(s, s.current_mode)).on_done(s, buf, ok)
@@ -1604,7 +1604,7 @@ function prompt!(term, prompt, s = init_state(term, prompt))
16041604
elseif state == :done
16051605
return buffer(s), true, false
16061606
elseif state == :suspend
1607-
@unix_only begin
1607+
if is_unix()
16081608
return buffer(s), true, true
16091609
end
16101610
else

base/REPLCompletions.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,13 @@ function complete_path(path::AbstractString, pos; use_envpath=false)
128128
if startswith(file, prefix)
129129
id = try isdir(joinpath(dir, file)) catch; false end
130130
# joinpath is not used because windows needs to complete with double-backslash
131-
push!(matches, id ? file * (@windows? "\\\\" : "/") : file)
131+
push!(matches, id ? file * (@static is_windows() ? "\\\\" : "/") : file)
132132
end
133133
end
134134

135135
if use_envpath && length(dir) == 0
136136
# Look for files in PATH as well
137-
local pathdirs = split(ENV["PATH"], @unix? ":" : ";")
137+
local pathdirs = split(ENV["PATH"], @static is_windows() ? ";" : ":")
138138

139139
for pathdir in pathdirs
140140
local actualpath

base/Terminals.jl

+12-9
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ cmove_line_up(t::UnixTerminal, n) = (cmove_up(t, n); cmove_col(t, 0))
116116
cmove_line_down(t::UnixTerminal, n) = (cmove_down(t, n); cmove_col(t, 0))
117117
cmove_col(t::UnixTerminal, n) = write(t.out_stream, "$(CSI)$(n)G")
118118

119-
@windows ? begin
119+
if is_windows()
120120
function raw!(t::TTYTerminal,raw::Bool)
121121
check_open(t.in_stream)
122122
if Base.ispty(t.in_stream)
@@ -132,7 +132,7 @@ cmove_col(t::UnixTerminal, n) = write(t.out_stream, "$(CSI)$(n)G")
132132
t.in_stream.handle, raw) != -1
133133
end
134134
end
135-
end : begin
135+
else
136136
function raw!(t::TTYTerminal, raw::Bool)
137137
check_open(t.in_stream)
138138
ccall(:jl_tty_set_mode, Int32, (Ptr{Void},Int32), t.in_stream.handle, raw) != -1
@@ -151,14 +151,17 @@ clear(t::UnixTerminal) = write(t.out_stream, "\x1b[H\x1b[2J")
151151
clear_line(t::UnixTerminal) = write(t.out_stream, "\x1b[0G\x1b[0K")
152152
#beep(t::UnixTerminal) = write(t.err_stream,"\x7")
153153

154-
@unix_only function hascolor(t::TTYTerminal)
155-
startswith(t.term_type, "xterm") && return true
156-
try
157-
return success(`tput setaf 0`)
158-
catch
159-
return false
154+
if is_windows()
155+
hascolor(t::TTYTerminal) = true
156+
else
157+
function hascolor(t::TTYTerminal)
158+
startswith(t.term_type, "xterm") && return true
159+
try
160+
return success(`tput setaf 0`)
161+
catch
162+
return false
163+
end
160164
end
161165
end
162-
@windows_only hascolor(t::TTYTerminal) = true
163166

164167
end # module

base/c.jl

+6-4
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,12 @@ convert(::Type{Cstring}, s::Symbol) = Cstring(unsafe_convert(Ptr{Cchar}, s))
9595
# in string.jl: unsafe_convert(::Type{Cwstring}, s::WString)
9696

9797
# FIXME: this should be handled by implicit conversion to Cwstring, but good luck with that
98-
@windows_only function cwstring(s::AbstractString)
99-
bytes = bytestring(s).data
100-
0 in bytes && throw(ArgumentError("embedded NULs are not allowed in C strings: $(repr(s))"))
101-
return push!(utf8to16(bytes), 0)
98+
if is_windows()
99+
function cwstring(s::AbstractString)
100+
bytes = bytestring(s).data
101+
0 in bytes && throw(ArgumentError("embedded NULs are not allowed in C strings: $(repr(s))"))
102+
return push!(utf8to16(bytes), 0)
103+
end
102104
end
103105

104106
# conversions between UTF-8 and UTF-16 for Windows APIs

base/client.jl

+11-8
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ text_colors
3737
have_color = false
3838
default_color_warn = :red
3939
default_color_info = :blue
40-
@unix_only default_color_input = :bold
41-
@unix_only default_color_answer = :bold
42-
@windows_only default_color_input = :normal
43-
@windows_only default_color_answer = :normal
40+
if is_windows()
41+
default_color_input = :normal
42+
default_color_answer = :normal
43+
else
44+
default_color_input = :bold
45+
default_color_answer = :bold
46+
end
4447
color_normal = text_colors[:normal]
4548

4649
function repl_color(key, default)
@@ -77,15 +80,15 @@ function repl_cmd(cmd, out)
7780
end
7881
cd(ENV["OLDPWD"])
7982
else
80-
cd(@windows? dir : readchomp(`$shell -c "echo $(shell_escape(dir))"`))
83+
cd(@static is_windows() ? dir : readchomp(`$shell -c "echo $(shell_escape(dir))"`))
8184
end
8285
else
8386
cd()
8487
end
8588
ENV["OLDPWD"] = new_oldpwd
8689
println(out, pwd())
8790
else
88-
run(ignorestatus(@windows? cmd : (isa(STDIN, TTY) ? `$shell -i -c "($(shell_escape(cmd))) && true"` : `$shell -c "($(shell_escape(cmd))) && true"`)))
91+
run(ignorestatus(@static is_windows() ? cmd : (isa(STDIN, TTY) ? `$shell -i -c "($(shell_escape(cmd))) && true"` : `$shell -c "($(shell_escape(cmd))) && true"`)))
8992
end
9093
nothing
9194
end
@@ -323,10 +326,10 @@ function _start()
323326
global active_repl_backend
324327
if repl
325328
if !isa(STDIN,TTY)
326-
global is_interactive |= !isa(STDIN,Union{File,IOStream})
329+
global is_interactive |= !isa(STDIN, Union{File, IOStream})
327330
color_set || (global have_color = false)
328331
else
329-
term = Terminals.TTYTerminal(get(ENV,"TERM",@windows? "" : "dumb"),STDIN,STDOUT,STDERR)
332+
term = Terminals.TTYTerminal(get(ENV, "TERM", @static is_windows() ? "" : "dumb"), STDIN, STDOUT, STDERR)
330333
global is_interactive = true
331334
color_set || (global have_color = Terminals.hascolor(term))
332335
quiet || REPL.banner(term,term)

base/dSFMT.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ end
151151

152152
## Windows entropy
153153

154-
@windows_only begin
154+
if is_windows()
155155
function win32_SystemFunction036!{T}(a::Array{T})
156-
ccall((:SystemFunction036,:Advapi32),stdcall,UInt8,(Ptr{Void},UInt32),a,sizeof(a))
156+
ccall((:SystemFunction036, :Advapi32), stdcall, UInt8, (Ptr{Void}, UInt32), a, sizeof(a))
157157
end
158158
end
159159

base/datafmt.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ readdlm(input, dlm::Char, T::Type, eol::Char; opts...) =
4242

4343
function readdlm_auto(input, dlm::Char, T::Type, eol::Char, auto::Bool; opts...)
4444
optsd = val_opts(opts)
45-
use_mmap = get(optsd, :use_mmap, @windows ? false : true)
45+
use_mmap = get(optsd, :use_mmap, is_windows() ? false : true)
4646
if isa(input, AbstractString)
4747
fsz = filesize(input)
4848
if use_mmap && fsz > 0 && fsz < typemax(Int)

base/deprecated.jl

+49-4
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ function msync end
582582
msync{T}(A::Array{T}) = msync(pointer(A), length(A)*sizeof(T))
583583
msync(B::BitArray) = msync(pointer(B.chunks), length(B.chunks)*sizeof(UInt64))
584584

585-
@unix_only begin
585+
if is_unix()
586586
export mmap
587587
@noinline function mmap(len::Integer, prot::Integer, flags::Integer, fd, offset::Integer)
588588
depwarn("`mmap` is deprecated, use `Mmap.mmap(io, Array{T,N}, dims, offset)` instead to return an mmapped-array", :mmap)
@@ -619,7 +619,7 @@ end
619619
end
620620

621621

622-
@windows_only begin
622+
if is_windows()
623623
@noinline function munmap(viewhandle::Ptr, mmaphandle::Ptr)
624624
depwarn("`munmap` is deprecated, `mmap` Arrays are automatically munmapped when finalized", :munmap)
625625
status = ccall(:UnmapViewOfFile, stdcall, Cint, (Ptr{Void},), viewhandle)!=0
@@ -639,9 +639,11 @@ end
639639

640640
end
641641

642-
@unix_only @deprecate mmap_array{T,N}(::Type{T}, dims::NTuple{N,Integer}, s::IO, offset=position(s)) Mmap.mmap(s, Array{T,N}, dims, offset)
642+
if is_unix()
643+
@deprecate mmap_array{T,N}(::Type{T}, dims::NTuple{N,Integer}, s::IO, offset=position(s)) Mmap.mmap(s, Array{T,N}, dims, offset)
644+
end
643645

644-
@windows_only begin
646+
if is_windows()
645647
type SharedMemSpec
646648
name :: AbstractString
647649
readonly :: Bool
@@ -1123,6 +1125,49 @@ end
11231125
@deprecate_binding UTF8String String
11241126
@deprecate_binding ByteString String
11251127

1128+
#6674 and #4233
1129+
macro windows(qm,ex)
1130+
depwarn("`@windows` is deprecated, use `@static is_windows()` instead", Symbol("@windows"))
1131+
return @static is_windows() ? esc(ex.args[1]) : esc(ex.args[2])
1132+
end
1133+
macro unix(qm,ex)
1134+
depwarn("`@unix` is deprecated, use `@static is_unix()` instead", Symbol("@unix"))
1135+
return @static is_unix() ? esc(ex.args[1]) : esc(ex.args[2])
1136+
end
1137+
macro osx(qm,ex)
1138+
depwarn("`@osx` is deprecated, use `@static is_apple()` instead", Symbol("@osx"))
1139+
return @static is_apple() ? esc(ex.args[1]) : esc(ex.args[2])
1140+
end
1141+
macro linux(qm,ex)
1142+
depwarn("`@linux` is deprecated, use `@static is_linux()` instead", Symbol("@linux"))
1143+
return @static is_linux() ? esc(ex.args[1]) : esc(ex.args[2])
1144+
end
1145+
macro windows_only(ex)
1146+
depwarn("`@windows_only` is deprecated, use `@static is_windows()` instead", Symbol("@windows_only"))
1147+
return @static if is_windows() esc(ex) end
1148+
end
1149+
macro unix_only(ex)
1150+
depwarn("`@unix_only` is deprecated, use `@static is_unix()` instead", Symbol("@unix_only"))
1151+
return @static if is_unix() esc(ex) end
1152+
end
1153+
macro osx_only(ex)
1154+
depwarn("`@osx_only` is deprecated, use `@static is_apple()` instead", Symbol("@osx_only"))
1155+
return @static if is_apple() esc(ex) end
1156+
end
1157+
macro linux_only(ex)
1158+
depwarn("`@linux_only` is deprecated, use `@static is_linux()` instead", Symbol("@linux_only"))
1159+
return @static if is_linux() esc(ex) end
1160+
end
1161+
export
1162+
@windows,
1163+
@unix,
1164+
@osx,
1165+
@linux,
1166+
@windows_only,
1167+
@unix_only,
1168+
@osx_only,
1169+
@linux_only
1170+
11261171
# During the 0.5 development cycle, do not add any deprecations below this line
11271172
# To be deprecated in 0.6
11281173

base/docs/helpdb/Base.jl

-58
Original file line numberDiff line numberDiff line change
@@ -2055,36 +2055,6 @@ of a string.
20552055
"""
20562056
isdigit
20572057

2058-
"""
2059-
@windows
2060-
2061-
Given `@windows? a : b`, do `a` on Windows and `b` elsewhere. See documentation in [Handling Operating System Variation](:ref:`Handling Operating System Variation <man-handling-operating-system-variation>`).
2062-
"""
2063-
:@windows
2064-
2065-
"""
2066-
@unix
2067-
2068-
Given `@unix? a : b`, do `a` on Unix systems (including Linux and OS X) and `b` elsewhere.
2069-
See documentation in [Handling Operating System Variation](:ref:`Handling Operating System Variation <man-handling-operating-system-variation>`).
2070-
"""
2071-
:@unix
2072-
2073-
"""
2074-
@windows_only
2075-
2076-
A macro that evaluates the given expression only on Windows systems. See documentation in [Handling Operating System Variation](:ref:`Handling Operating System Variation <man-handling-operating-system-variation>`).
2077-
"""
2078-
:@windows_only
2079-
2080-
"""
2081-
@unix_only
2082-
2083-
A macro that evaluates the given expression only on Unix systems (including Linux and OS X). See
2084-
documentation in [Handling Operating System Variation](:ref:`Handling Operating System Variation <man-handling-operating-system-variation>`).
2085-
"""
2086-
:@unix_only
2087-
20882058
"""
20892059
num2hex(f)
20902060
@@ -6407,20 +6377,6 @@ Returns the number of dimensions of `A`.
64076377
"""
64086378
ndims
64096379

6410-
"""
6411-
@osx
6412-
6413-
Given `@osx? a : b`, do `a` on OS X and `b` elsewhere. See documentation in [Handling Operating System Variation](:ref:`Handling Operating System Variation <man-handling-operating-system-variation>`).
6414-
"""
6415-
:@osx
6416-
6417-
"""
6418-
@osx_only
6419-
6420-
A macro that evaluates the given expression only on OS X systems. See documentation in [Handling Operating System Variation](:ref:`Handling Operating System Variation <man-handling-operating-system-variation>`).
6421-
"""
6422-
:@osx_only
6423-
64246380
"""
64256381
ishermitian(A) -> Bool
64266382
@@ -8063,20 +8019,6 @@ Cumulative product of `A` along a dimension, storing the result in `B`. The dime
80638019
"""
80648020
cumprod!
80658021

8066-
"""
8067-
@linux
8068-
8069-
Given `@linux? a : b`, do `a` on Linux and `b` elsewhere. See documentation [Handling Operating System Variation](:ref:`Handling Operating System Variation <man-handling-operating-system-variation>`).
8070-
"""
8071-
:@linux
8072-
8073-
"""
8074-
@linux_only
8075-
8076-
A macro that evaluates the given expression only on Linux systems. See documentation in [Handling Operating System Variation](:ref:`Handling Operating System Variation <man-handling-operating-system-variation>`).
8077-
"""
8078-
:@linux_only
8079-
80808022
"""
80818023
complement(s)
80828024

0 commit comments

Comments
 (0)