From 9f2ca884dd20f2acba81b87e23dba92ff51e29c0 Mon Sep 17 00:00:00 2001 From: Mus M Date: Tue, 17 Jan 2017 13:25:33 -0500 Subject: [PATCH] Use Ref for lpMsgBuf (#20051) * Use Ref for lpMsgBuf * Prettify --- base/libc.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/base/libc.jl b/base/libc.jl index 03abe0746a9a41..ea0e4b3698348a 100644 --- a/base/libc.jl +++ b/base/libc.jl @@ -270,23 +270,23 @@ Convert a Win32 system call error code to a descriptive string [only available o function FormatMessage end if is_windows() - GetLastError() = ccall(:GetLastError,stdcall,UInt32,()) + GetLastError() = ccall(:GetLastError, stdcall, UInt32, ()) function FormatMessage(e=GetLastError()) const FORMAT_MESSAGE_ALLOCATE_BUFFER = UInt32(0x100) const FORMAT_MESSAGE_FROM_SYSTEM = UInt32(0x1000) const FORMAT_MESSAGE_IGNORE_INSERTS = UInt32(0x200) const FORMAT_MESSAGE_MAX_WIDTH_MASK = UInt32(0xFF) - lpMsgBuf = Array{Ptr{UInt16},0}() - lpMsgBuf[1] = 0 - len = ccall(:FormatMessageW,stdcall,UInt32,(Cint, Ptr{Void}, Cint, Cint, Ptr{Ptr{UInt16}}, Cint, Ptr{Void}), + lpMsgBuf = Ref{Ptr{UInt16}}() + lpMsgBuf[] = 0 + len = ccall(:FormatMessageW, stdcall, UInt32, (Cint, Ptr{Void}, Cint, Cint, Ptr{Ptr{UInt16}}, Cint, Ptr{Void}), FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK, C_NULL, e, 0, lpMsgBuf, 0, C_NULL) - p = lpMsgBuf[1] + p = lpMsgBuf[] len == 0 && return "" buf = Array{UInt16}(len) unsafe_copy!(pointer(buf), p, len) - ccall(:LocalFree,stdcall,Ptr{Void},(Ptr{Void},),p) + ccall(:LocalFree, stdcall, Ptr{Void}, (Ptr{Void},), p) return transcode(String, buf) end end