From ff8b0c1106374d33e55f1a80db0bff4bb16a68c7 Mon Sep 17 00:00:00 2001 From: Mus M Date: Thu, 17 Aug 2017 11:25:20 -0400 Subject: [PATCH 1/3] Misc remove `&x` ccall syntax --- base/hashing2.jl | 2 +- base/irrationals.jl | 3 +-- base/libc.jl | 13 ++++++------- base/printf.jl | 6 +++--- base/socket.jl | 8 ++++---- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/base/hashing2.jl b/base/hashing2.jl index 37a401ac974f0..b4c548b2ccab1 100644 --- a/base/hashing2.jl +++ b/base/hashing2.jl @@ -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 diff --git a/base/irrationals.jl b/base/irrationals.jl index 27b94a5968903..1d53477674423 100644 --- a/base/irrationals.jl +++ b/base/irrationals.jl @@ -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 diff --git a/base/libc.jl b/base/libc.jl index 810cda11e448f..c8be53ed64eee 100644 --- a/base/libc.jl +++ b/base/libc.jl @@ -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 @@ -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 @@ -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. @@ -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 @@ -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() diff --git a/base/printf.jl b/base/printf.jl index 47ade06597171..99e10d6aa55e6 100644 --- a/base/printf.jl +++ b/base/printf.jl @@ -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) @@ -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, ()) diff --git a/base/socket.jl b/base/socket.jl index 588e0097a69a5..3bc64c8722e71 100644 --- a/base/socket.jl +++ b/base/socket.jl @@ -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 """ @@ -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 From 72c0911fdc1110e28ebf49ffe793871019a46fe1 Mon Sep 17 00:00:00 2001 From: Mus M Date: Thu, 17 Aug 2017 16:52:16 -0400 Subject: [PATCH 2/3] Address comment --- base/printf.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/printf.jl b/base/printf.jl index 99e10d6aa55e6..c64a78fcdf4e4 100644 --- a/base/printf.jl +++ b/base/printf.jl @@ -1130,7 +1130,7 @@ function bigfloat_printf(out, d::BigFloat, flags::String, width::Int, precision: @assert length(printf_fmt) == fmt_len bufsiz = length(DIGITS) lng = ccall((:mpfr_snprintf,:libmpfr), Int32, - (Ptr{UInt8}, Culong, Ptr{UInt8}, Ref{BigFloat}), + (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)) From df9257f8fcc91491f9a380cd2ea29b84d4fe9199 Mon Sep 17 00:00:00 2001 From: Mus M Date: Tue, 22 Aug 2017 17:13:10 -0400 Subject: [PATCH 3/3] align --- base/socket.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/socket.jl b/base/socket.jl index 3bc64c8722e71..997e6d2a5cb04 100644 --- a/base/socket.jl +++ b/base/socket.jl @@ -727,7 +727,7 @@ function connect!(sock::TCPSocket, host::IPv6, port::Integer) throw(ArgumentError("port out of range, must be 0 ≤ port ≤ 65535, got $port")) end 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.handle, hton(host.host), hton(UInt16(port)), uv_jl_connectcb::Ptr{Void})) sock.status = StatusConnecting nothing end