Skip to content

Commit

Permalink
Avoid useless OOB checks for ccall array arguments.
Browse files Browse the repository at this point in the history
use Ref intead of single-element arrays instead.
  • Loading branch information
maleadt committed Jul 12, 2016
1 parent 38c803d commit 93dbfda
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 82 deletions.
2 changes: 1 addition & 1 deletion base/irrationals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ macro irrational(sym, val, def)
c = BigFloat()
ccall(($(string("mpfr_const_", def)), :libmpfr),
Cint, (Ptr{BigFloat}, Int32),
&c, MPFR.ROUNDING_MODE[end])
&c, MPFR.ROUNDING_MODE[])
return c
end
end : quote
Expand Down
8 changes: 4 additions & 4 deletions base/libgit2/reference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,24 +192,24 @@ end

function Base.start(bi::GitBranchIter)
ref_ptr_ptr = Ref{Ptr{Void}}(C_NULL)
btype = Cint[0]
btype = Ref{Cint}()
err = ccall((:git_branch_next, :libgit2), Cint,
(Ptr{Ptr{Void}}, Ptr{Cint}, Ptr{Void}),
ref_ptr_ptr, btype, bi.ptr)
err != Int(Error.GIT_OK) && return (nothing, -1, true)
return (GitReference(ref_ptr_ptr[]), btype[1], false)
return (GitReference(ref_ptr_ptr[]), btype[], false)
end

Base.done(bi::GitBranchIter, state) = Bool(state[3])

function Base.next(bi::GitBranchIter, state)
ref_ptr_ptr = Ref{Ptr{Void}}(C_NULL)
btype = Cint[0]
btype = Ref{Cint}()
err = ccall((:git_branch_next, :libgit2), Cint,
(Ptr{Ptr{Void}}, Ptr{Cint}, Ptr{Void}),
ref_ptr_ptr, btype, bi.ptr)
err != Int(Error.GIT_OK) && return (state[1:2], (nothing, -1, true))
return (state[1:2], (GitReference(ref_ptr_ptr[]), btype[1], false))
return (state[1:2], (GitReference(ref_ptr_ptr[]), btype[], false))
end

Base.iteratorsize(::Type{GitBranchIter}) = Base.SizeUnknown()
Expand Down
8 changes: 4 additions & 4 deletions base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,16 +278,16 @@ end

modf(x) = rem(x,one(x)), trunc(x)

const _modff_temp = Float32[0]
const _modff_temp = Ref{Float32}()
function modf(x::Float32)
f = ccall((:modff,libm), Float32, (Float32,Ptr{Float32}), x, _modff_temp)
f, _modff_temp[1]
f, _modff_temp[]
end

const _modf_temp = Float64[0]
const _modf_temp = Ref{Float64}()
function modf(x::Float64)
f = ccall((:modf,libm), Float64, (Float64,Ptr{Float64}), x, _modf_temp)
f, _modf_temp[1]
f, _modf_temp[]
end

^(x::Float64, y::Float64) = nan_dom_err(ccall((:pow,libm), Float64, (Float64,Float64), x, y), x+y)
Expand Down
Loading

0 comments on commit 93dbfda

Please sign in to comment.