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

replace osutils macros with @static #16219

Merged
merged 3 commits into from
May 21, 2016
Merged
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
13 changes: 11 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,13 @@ Library improvements
* Concatenating dense and sparse matrices now returns a sparse matrix ([#15172]).

* The `libjulia` library is now properly versioned and installed to the public `<prefix>/lib`
directory, instead of the private `<prefix>/lib/julia` directory.
directory, instead of the private `<prefix>/lib/julia` directory ([#16362]).

* System reflection is now more consistently exposed from Sys and not Base.
`OS_NAME` has been replaced by `Sys.KERNEL` and always reports the name of the kernel (as reported by `uname`).
The `@windows_only` and `@osx` family of macros have been replaced with functions such as `is_windows()` and
or `is_apple()`. There's now also an `@static` macro that will evaluate the condition of an if-statement at
compile time, for when a static branch is required ([#16219]).

Deprecated or removed
---------------------
Expand Down Expand Up @@ -227,13 +233,16 @@ Deprecated or removed
[#14759]: https://github.com/JuliaLang/julia/issues/14759
[#14798]: https://github.com/JuliaLang/julia/issues/14798
[#15032]: https://github.com/JuliaLang/julia/issues/15032
[#15172]: https://github.com/JuliaLang/julia/issues/15172
[#15192]: https://github.com/JuliaLang/julia/issues/15192
[#15242]: https://github.com/JuliaLang/julia/issues/15242
[#15258]: https://github.com/JuliaLang/julia/issues/15258
[#15409]: https://github.com/JuliaLang/julia/issues/15409
[#15431]: https://github.com/JuliaLang/julia/issues/15431
[#15550]: https://github.com/JuliaLang/julia/issues/15550
[#15609]: https://github.com/JuliaLang/julia/issues/15609
[#15731]: https://github.com/JuliaLang/julia/issues/15731
[#15763]: https://github.com/JuliaLang/julia/issues/15763
[#16219]: https://github.com/JuliaLang/julia/issues/16219
[#16362]: https://github.com/JuliaLang/julia/issues/16362
[#16403]: https://github.com/JuliaLang/julia/issues/16403
[#15172]: https://github.com/JuliaLang/julia/issues/15172
6 changes: 3 additions & 3 deletions base/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function refresh_multi_line(termbuf::TerminalBuffer, terminal::UnixTerminal, buf
write_prompt(termbuf, prompt)
prompt = prompt_string(prompt)
# Count the '\n' at the end of the line if the terminal emulator does (specific to DOS cmd prompt)
miscountnl = @windows ? (isa(Terminals.pipe_reader(terminal), Base.TTY) && !Base.ispty(Terminals.pipe_reader(terminal))) : false
miscountnl = @static is_windows() ? (isa(Terminals.pipe_reader(terminal), Base.TTY) && !Base.ispty(Terminals.pipe_reader(terminal))) : false
lindent = strwidth(prompt)

# Now go through the buffer line by line
Expand Down Expand Up @@ -1564,7 +1564,7 @@ function run_interface(terminal, m::ModalInterface)
p = s.current_mode
buf, ok, suspend = prompt!(terminal, m, s)
while suspend
@unix_only ccall(:jl_repl_raise_sigtstp, Cint, ())
@static if is_unix(); ccall(:jl_repl_raise_sigtstp, Cint, ()); end
buf, ok, suspend = prompt!(terminal, m, s)
end
mode(state(s, s.current_mode)).on_done(s, buf, ok)
Expand Down Expand Up @@ -1604,7 +1604,7 @@ function prompt!(term, prompt, s = init_state(term, prompt))
elseif state == :done
return buffer(s), true, false
elseif state == :suspend
@unix_only begin
if is_unix()
return buffer(s), true, true
end
else
Expand Down
1 change: 0 additions & 1 deletion base/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ $(BUILDDIR)/uv_constants.jl: $(SRCDIR)/../src/uv_constants.h $(build_includedir)

$(BUILDDIR)/build_h.jl.phony:
@echo "# This file is automatically generated in base/Makefile" > $@
@echo "const ARCH = :$(ARCH)" >> $@
ifeq ($(XC_HOST),)
@echo "const MACHINE = \"$(BUILD_MACHINE)\"" >> $@
else
Expand Down
6 changes: 3 additions & 3 deletions base/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function complete_keyword(s::String)
end

function complete_path(path::AbstractString, pos; use_envpath=false)
if Base.is_unix(OS_NAME) && ismatch(r"^~(?:/|$)", path)
if Base.is_unix() && ismatch(r"^~(?:/|$)", path)
# if the path is just "~", don't consider the expanded username as a prefix
if path == "~"
dir, prefix = homedir(), ""
Expand Down Expand Up @@ -128,13 +128,13 @@ function complete_path(path::AbstractString, pos; use_envpath=false)
if startswith(file, prefix)
id = try isdir(joinpath(dir, file)) catch; false end
# joinpath is not used because windows needs to complete with double-backslash
push!(matches, id ? file * (@windows? "\\\\" : "/") : file)
push!(matches, id ? file * (@static is_windows() ? "\\\\" : "/") : file)
end
end

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

for pathdir in pathdirs
local actualpath
Expand Down
21 changes: 12 additions & 9 deletions base/Terminals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ cmove_line_up(t::UnixTerminal, n) = (cmove_up(t, n); cmove_col(t, 0))
cmove_line_down(t::UnixTerminal, n) = (cmove_down(t, n); cmove_col(t, 0))
cmove_col(t::UnixTerminal, n) = write(t.out_stream, "$(CSI)$(n)G")

@windows ? begin
if is_windows()
function raw!(t::TTYTerminal,raw::Bool)
check_open(t.in_stream)
if Base.ispty(t.in_stream)
Expand All @@ -132,7 +132,7 @@ cmove_col(t::UnixTerminal, n) = write(t.out_stream, "$(CSI)$(n)G")
t.in_stream.handle, raw) != -1
end
end
end : begin
else
function raw!(t::TTYTerminal, raw::Bool)
check_open(t.in_stream)
ccall(:jl_tty_set_mode, Int32, (Ptr{Void},Int32), t.in_stream.handle, raw) != -1
Expand All @@ -151,14 +151,17 @@ clear(t::UnixTerminal) = write(t.out_stream, "\x1b[H\x1b[2J")
clear_line(t::UnixTerminal) = write(t.out_stream, "\x1b[0G\x1b[0K")
#beep(t::UnixTerminal) = write(t.err_stream,"\x7")

@unix_only function hascolor(t::TTYTerminal)
startswith(t.term_type, "xterm") && return true
try
return success(`tput setaf 0`)
catch
return false
if is_windows()
hascolor(t::TTYTerminal) = true
else
function hascolor(t::TTYTerminal)
startswith(t.term_type, "xterm") && return true
try
return success(`tput setaf 0`)
catch
return false
end
end
end
@windows_only hascolor(t::TTYTerminal) = true

end # module
2 changes: 1 addition & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ function vcat{T}(arrays::Vector{T}...)
if isbits(T)
elsz = sizeof(T)
else
elsz = div(WORD_SIZE,8)
elsz = Core.sizeof(Ptr{Void})
end
for a in arrays
nba = length(a)*elsz
Expand Down
5 changes: 3 additions & 2 deletions base/atomics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Core.Intrinsics: llvmcall

import Base: setindex!, getindex, unsafe_convert
import Base.Sys: ARCH, WORD_SIZE

export
Atomic,
Expand All @@ -16,8 +17,8 @@ export
# Disable 128-bit types on 32-bit Intel sytems due to LLVM problems;
# see <https://github.com/JuliaLang/julia/issues/14818> (fixed on LLVM 3.9)
# 128-bit atomics do not exist on AArch32.
if (VersionNumber(Base.libllvm_version) < v"3.9-" && Base.ARCH === :i686) ||
startswith(string(Base.ARCH), "arm")
if (VersionNumber(Base.libllvm_version) < v"3.9-" && ARCH === :i686) ||
startswith(string(ARCH), "arm")
const inttypes = (Int8, Int16, Int32, Int64,
UInt8, UInt16, UInt32, UInt64)
else
Expand Down
8 changes: 5 additions & 3 deletions base/c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ typealias Cshort Int16
typealias Cushort UInt16
typealias Cint Int32
typealias Cuint UInt32
if OS_NAME === :Windows
if is_windows()
typealias Clong Int32
typealias Culong UInt32
typealias Cwchar_t UInt16
Expand All @@ -35,7 +35,7 @@ typealias Culonglong UInt64
typealias Cfloat Float32
typealias Cdouble Float64

if OS_NAME !== :Windows
if !is_windows()
const sizeof_mode_t = ccall(:jl_sizeof_mode_t, Cint, ())
if sizeof_mode_t == 2
typealias Cmode_t Int16
Expand Down Expand Up @@ -95,11 +95,13 @@ convert(::Type{Cstring}, s::Symbol) = Cstring(unsafe_convert(Ptr{Cchar}, s))
# in string.jl: unsafe_convert(::Type{Cwstring}, s::WString)

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

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

Expand Down
2 changes: 1 addition & 1 deletion base/checked.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ brokenSignedInt = Union{}
brokenUnsignedInt = Union{}
brokenSignedIntMul = Int128
brokenUnsignedIntMul = UInt128
if WORD_SIZE == 32
if Core.sizeof(Ptr{Void}) == 4
brokenSignedIntMul = Union{brokenSignedIntMul, Int64}
brokenUnsignedIntMul = Union{brokenUnsignedIntMul, UInt64}
end
Expand Down
19 changes: 11 additions & 8 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ text_colors
have_color = false
default_color_warn = :red
default_color_info = :blue
@unix_only default_color_input = :bold
@unix_only default_color_answer = :bold
@windows_only default_color_input = :normal
@windows_only default_color_answer = :normal
if is_windows()
default_color_input = :normal
default_color_answer = :normal
else
default_color_input = :bold
default_color_answer = :bold
end
color_normal = text_colors[:normal]

function repl_color(key, default)
Expand Down Expand Up @@ -77,15 +80,15 @@ function repl_cmd(cmd, out)
end
cd(ENV["OLDPWD"])
else
cd(@windows? dir : readchomp(`$shell -c "echo $(shell_escape(dir))"`))
cd(@static is_windows() ? dir : readchomp(`$shell -c "echo $(shell_escape(dir))"`))
end
else
cd()
end
ENV["OLDPWD"] = new_oldpwd
println(out, pwd())
else
run(ignorestatus(@windows? cmd : (isa(STDIN, TTY) ? `$shell -i -c "($(shell_escape(cmd))) && true"` : `$shell -c "($(shell_escape(cmd))) && true"`)))
run(ignorestatus(@static is_windows() ? cmd : (isa(STDIN, TTY) ? `$shell -i -c "($(shell_escape(cmd))) && true"` : `$shell -c "($(shell_escape(cmd))) && true"`)))
end
nothing
end
Expand Down Expand Up @@ -323,10 +326,10 @@ function _start()
global active_repl_backend
if repl
if !isa(STDIN,TTY)
global is_interactive |= !isa(STDIN,Union{File,IOStream})
global is_interactive |= !isa(STDIN, Union{File, IOStream})
color_set || (global have_color = false)
else
term = Terminals.TTYTerminal(get(ENV,"TERM",@windows? "" : "dumb"),STDIN,STDOUT,STDERR)
term = Terminals.TTYTerminal(get(ENV, "TERM", @static is_windows() ? "" : "dumb"), STDIN, STDOUT, STDERR)
global is_interactive = true
color_set || (global have_color = Terminals.hascolor(term))
quiet || REPL.banner(term,term)
Expand Down
10 changes: 0 additions & 10 deletions base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -760,22 +760,12 @@ function lexcmp(a::Complex, b::Complex)
end

#Rounding complex numbers
# Superfluous tuple splatting in return arguments is a work around for 32-bit systems (#10027)
#Requires two different RoundingModes for the real and imaginary components

if WORD_SIZE==32
function round{T<:AbstractFloat, MR, MI}(z::Complex{T}, ::RoundingMode{MR}, ::RoundingMode{MI})
Complex((round(real(z), RoundingMode{MR}()),
round(imag(z), RoundingMode{MI}()))...)
end
round(z::Complex) = Complex((round(real(z)), round(imag(z)))...)
else
function round{T<:AbstractFloat, MR, MI}(z::Complex{T}, ::RoundingMode{MR}, ::RoundingMode{MI})
Complex(round(real(z), RoundingMode{MR}()),
round(imag(z), RoundingMode{MI}()))
end
round(z::Complex) = Complex(round(real(z)), round(imag(z)))
end

@vectorize_1arg Complex round
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grr fine, but this should at least have been a separate commit


Expand Down
4 changes: 2 additions & 2 deletions base/dSFMT.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ end

## Windows entropy

@windows_only begin
if is_windows()
function win32_SystemFunction036!{T}(a::Array{T})
ccall((:SystemFunction036,:Advapi32),stdcall,UInt8,(Ptr{Void},UInt32),a,sizeof(a))
ccall((:SystemFunction036, :Advapi32), stdcall, UInt8, (Ptr{Void}, UInt32), a, sizeof(a))
end
end

Expand Down
2 changes: 1 addition & 1 deletion base/datafmt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ readdlm(input, dlm::Char, T::Type, eol::Char; opts...) =

function readdlm_auto(input, dlm::Char, T::Type, eol::Char, auto::Bool; opts...)
optsd = val_opts(opts)
use_mmap = get(optsd, :use_mmap, @windows ? false : true)
use_mmap = get(optsd, :use_mmap, is_windows() ? false : true)
if isa(input, AbstractString)
fsz = filesize(input)
if use_mmap && fsz > 0 && fsz < typemax(Int)
Expand Down
Loading