Skip to content

Commit

Permalink
Use Ref for lpMsgBuf (JuliaLang#20051)
Browse files Browse the repository at this point in the history
* Use Ref for lpMsgBuf

* Prettify
  • Loading branch information
musm authored and tkelman committed Jan 18, 2017
1 parent 25f77d0 commit 9f2ca88
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions base/libc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9f2ca88

Please sign in to comment.