Skip to content

Commit

Permalink
Misc remove &x ccall syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
musm committed Aug 17, 2017
1 parent b12c778 commit ff8b0c1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion base/hashing2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function decompose(x::BigFloat)::Tuple{BigInt, Int, Int}
s = BigInt()
s.size = cld(x.prec, 8*sizeof(GMP.Limb)) # limbs
b = s.size * sizeof(GMP.Limb) # bytes
ccall((:__gmpz_realloc2, :libgmp), Void, (Ptr{BigInt}, Culong), &s, 8b) # bits
ccall((:__gmpz_realloc2, :libgmp), Void, (Ref{BigInt}, Culong), s, 8b) # bits
ccall(:memcpy, Ptr{Void}, (Ptr{Void}, Ptr{Void}, Csize_t), s.d, x.d, b) # bytes
s, x.exp - 8b, x.sign
end
Expand Down
3 changes: 1 addition & 2 deletions base/irrationals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ macro irrational(sym, val, def)
function Base.convert(::Type{BigFloat}, ::Irrational{$qsym})
c = BigFloat()
ccall(($(string("mpfr_const_", def)), :libmpfr),
Cint, (Ptr{BigFloat}, Int32),
&c, MPFR.ROUNDING_MODE[])
Cint, (Ref{BigFloat}, Int32), c, MPFR.ROUNDING_MODE[])
return c
end
end : quote
Expand Down
13 changes: 6 additions & 7 deletions base/libc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ mutable struct TmStruct
t = floor(t)
tm = TmStruct()
# TODO: add support for UTC via gmtime_r()
ccall(:localtime_r, Ptr{TmStruct}, (Ptr{Int}, Ptr{TmStruct}), &t, &tm)
ccall(:localtime_r, Ptr{TmStruct}, (Ref{Int}, Ref{TmStruct}), t, tm)
return tm
end
end
Expand All @@ -171,8 +171,8 @@ strftime(t) = strftime("%c", t)
strftime(fmt::AbstractString, t::Real) = strftime(fmt, TmStruct(t))
function strftime(fmt::AbstractString, tm::TmStruct)
timestr = Vector{UInt8}(128)
n = ccall(:strftime, Int, (Ptr{UInt8}, Int, Cstring, Ptr{TmStruct}),
timestr, length(timestr), fmt, &tm)
n = ccall(:strftime, Int, (Ptr{UInt8}, Int, Cstring, Ref{TmStruct}),
timestr, length(timestr), fmt, tm)
if n == 0
return ""
end
Expand All @@ -192,8 +192,7 @@ determine the timezone.
strptime(timestr::AbstractString) = strptime("%c", timestr)
function strptime(fmt::AbstractString, timestr::AbstractString)
tm = TmStruct()
r = ccall(:strptime, Cstring, (Cstring, Cstring, Ptr{TmStruct}),
timestr, fmt, &tm)
r = ccall(:strptime, Cstring, (Cstring, Cstring, Ref{TmStruct}), timestr, fmt, tm)
# the following would tell mktime() that this is a local time, and that
# it should try to guess the timezone. not sure if/how this should be
# exposed in the API.
Expand All @@ -206,7 +205,7 @@ function strptime(fmt::AbstractString, timestr::AbstractString)
# if we didn't explicitly parse the weekday or year day, use mktime
# to fill them in automatically.
if !ismatch(r"([^%]|^)%(a|A|j|w|Ow)", fmt)
ccall(:mktime, Int, (Ptr{TmStruct},), &tm)
ccall(:mktime, Int, (Ref{TmStruct},), tm)
end
end
return tm
Expand All @@ -219,7 +218,7 @@ end
Converts a `TmStruct` struct to a number of seconds since the epoch.
"""
time(tm::TmStruct) = Float64(ccall(:mktime, Int, (Ptr{TmStruct},), &tm))
time(tm::TmStruct) = Float64(ccall(:mktime, Int, (Ref{TmStruct},), tm))

"""
time()
Expand Down
6 changes: 3 additions & 3 deletions base/printf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ ini_hex(out, d::BigFloat, ndigits::Int, flags::String, width::Int, precision::In
ini_HEX(out, d::BigFloat, ndigits::Int, flags::String, width::Int, precision::Int, c::Char) = bigfloat_printf(out, d, flags, width, precision, c)
ini_hex(out, d::BigFloat, flags::String, width::Int, precision::Int, c::Char) = bigfloat_printf(out, d, flags, width, precision, c)
ini_HEX(out, d::BigFloat, flags::String, width::Int, precision::Int, c::Char) = bigfloat_printf(out, d, flags, width, precision, c)
function bigfloat_printf(out, d, flags::String, width::Int, precision::Int, c::Char)
function bigfloat_printf(out, d::BigFloat, flags::String, width::Int, precision::Int, c::Char)
fmt_len = sizeof(flags)+4
if width > 0
fmt_len += ndigits(width)
Expand Down Expand Up @@ -1130,8 +1130,8 @@ function bigfloat_printf(out, d, flags::String, width::Int, precision::Int, c::C
@assert length(printf_fmt) == fmt_len
bufsiz = length(DIGITS)
lng = ccall((:mpfr_snprintf,:libmpfr), Int32,
(Ptr{UInt8}, Culong, Ptr{UInt8}, Ptr{BigFloat}...),
DIGITS, bufsiz, printf_fmt, &d)
(Ptr{UInt8}, Culong, Ptr{UInt8}, Ref{BigFloat}),
DIGITS, bufsiz, printf_fmt, d)
lng > 0 || error("invalid printf formatting for BigFloat")
unsafe_write(out, pointer(DIGITS), min(lng, bufsiz-1))
return (false, ())
Expand Down
8 changes: 4 additions & 4 deletions base/socket.jl
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,8 @@ function _send(sock::UDPSocket, ipaddr::IPv4, port::UInt16, buf)
end

function _send(sock::UDPSocket, ipaddr::IPv6, port::UInt16, buf)
ccall(:jl_udp_send6, Cint, (Ptr{Void}, UInt16, Ptr{UInt128}, Ptr{UInt8}, Csize_t, Ptr{Void}),
sock.handle, hton(port), &hton(ipaddr.host), buf, sizeof(buf), uv_jl_sendcb::Ptr{Void})
ccall(:jl_udp_send6, Cint, (Ptr{Void}, UInt16, Ref{UInt128}, Ptr{UInt8}, Csize_t, Ptr{Void}),
sock.handle, hton(port), hton(ipaddr.host), buf, sizeof(buf), uv_jl_sendcb::Ptr{Void})
end

"""
Expand Down Expand Up @@ -726,8 +726,8 @@ function connect!(sock::TCPSocket, host::IPv6, port::Integer)
if !(0 <= port <= typemax(UInt16))
throw(ArgumentError("port out of range, must be 0 ≤ port ≤ 65535, got $port"))
end
uv_error("connect", ccall(:jl_tcp6_connect, Int32, (Ptr{Void}, Ptr{UInt128}, UInt16, Ptr{Void}),
sock.handle, &hton(host.host), hton(UInt16(port)), uv_jl_connectcb::Ptr{Void}))
uv_error("connect", ccall(:jl_tcp6_connect, Int32, (Ptr{Void}, Ref{UInt128}, UInt16, Ptr{Void}),
sock.handle, hton(host.host), hton(UInt16(port)), uv_jl_connectcb::Ptr{Void}))
sock.status = StatusConnecting
nothing
end
Expand Down

0 comments on commit ff8b0c1

Please sign in to comment.