Skip to content

Commit

Permalink
Look for fesetround() in libm, not in the Julia executable
Browse files Browse the repository at this point in the history
Because we now do not link against libm in the executable, we must
explicitly pass `Base.libm_name` to `ccall()`.  In order to do this, we
need to re-arrange a few pieces of `base/Base.jl`, including creating a
`strcat()` from closer to first principles than we'd like.
  • Loading branch information
staticfloat committed Aug 28, 2020
1 parent 25be74c commit acd6ed3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
18 changes: 14 additions & 4 deletions base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@ using .Iterators: Flatten, Filter, product # for generators

include("namedtuple.jl")

# For OS specific stuff
# We need to strcat things here, before strings are really defined
function strcat(x::String, y::String)
out = ccall(:jl_alloc_string, Ref{String}, (Csize_t,), Core.sizeof(x) + Core.sizeof(y))
GC.@preserve x y out begin
out_ptr = unsafe_convert(Ptr{UInt8}, out)
unsafe_copyto!(out_ptr, unsafe_convert(Ptr{UInt8}, x), Core.sizeof(x))
unsafe_copyto!(out_ptr + Core.sizeof(x), unsafe_convert(Ptr{UInt8}, y), Core.sizeof(y))
end
return out
end
include(strcat((length(Core.ARGS)>=2 ? Core.ARGS[2] : ""), "build_h.jl")) # include($BUILDROOT/base/build_h.jl)
include(strcat((length(Core.ARGS)>=2 ? Core.ARGS[2] : ""), "version_git.jl")) # include($BUILDROOT/base/version_git.jl)

# numeric operations
include("hashing.jl")
include("rounding.jl")
Expand Down Expand Up @@ -163,10 +177,6 @@ include("strings/basic.jl")
include("strings/string.jl")
include("strings/substring.jl")

# For OS specific stuff
include(string((length(Core.ARGS)>=2 ? Core.ARGS[2] : ""), "build_h.jl")) # include($BUILDROOT/base/build_h.jl)
include(string((length(Core.ARGS)>=2 ? Core.ARGS[2] : ""), "version_git.jl")) # include($BUILDROOT/base/version_git.jl)

# Initialize DL_LOAD_PATH as early as possible. We are defining things here in
# a slightly more verbose fashion than usual, because we're running so early.
const DL_LOAD_PATH = String[]
Expand Down
4 changes: 2 additions & 2 deletions base/rounding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ See [`RoundingMode`](@ref) for available modes.
"""
:rounding

setrounding_raw(::Type{<:Union{Float32,Float64}}, i::Integer) = ccall(:fesetround, Int32, (Int32,), i)
rounding_raw(::Type{<:Union{Float32,Float64}}) = ccall(:fegetround, Int32, ())
setrounding_raw(::Type{<:Union{Float32,Float64}}, i::Integer) = ccall((:fesetround, Base.libm_name), Int32, (Int32,), i)
rounding_raw(::Type{<:Union{Float32,Float64}}) = ccall((:fegetround, Base.libm_name), Int32, ())

rounding(::Type{T}) where {T<:Union{Float32,Float64}} = from_fenv(rounding_raw(T))

Expand Down

0 comments on commit acd6ed3

Please sign in to comment.