Skip to content

Commit 184da04

Browse files
musmararslan
authored andcommitted
Use Ref for lpMsgBuf (#20051)
* Use Ref for lpMsgBuf * Prettify
1 parent fab13f2 commit 184da04

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

base/libc.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,23 +270,23 @@ Convert a Win32 system call error code to a descriptive string [only available o
270270
function FormatMessage end
271271

272272
if is_windows()
273-
GetLastError() = ccall(:GetLastError,stdcall,UInt32,())
273+
GetLastError() = ccall(:GetLastError, stdcall, UInt32, ())
274274

275275
function FormatMessage(e=GetLastError())
276276
const FORMAT_MESSAGE_ALLOCATE_BUFFER = UInt32(0x100)
277277
const FORMAT_MESSAGE_FROM_SYSTEM = UInt32(0x1000)
278278
const FORMAT_MESSAGE_IGNORE_INSERTS = UInt32(0x200)
279279
const FORMAT_MESSAGE_MAX_WIDTH_MASK = UInt32(0xFF)
280-
lpMsgBuf = Array{Ptr{UInt16},0}()
281-
lpMsgBuf[1] = 0
282-
len = ccall(:FormatMessageW,stdcall,UInt32,(Cint, Ptr{Void}, Cint, Cint, Ptr{Ptr{UInt16}}, Cint, Ptr{Void}),
280+
lpMsgBuf = Ref{Ptr{UInt16}}()
281+
lpMsgBuf[] = 0
282+
len = ccall(:FormatMessageW, stdcall, UInt32, (Cint, Ptr{Void}, Cint, Cint, Ptr{Ptr{UInt16}}, Cint, Ptr{Void}),
283283
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
284284
C_NULL, e, 0, lpMsgBuf, 0, C_NULL)
285-
p = lpMsgBuf[1]
285+
p = lpMsgBuf[]
286286
len == 0 && return ""
287287
buf = Array{UInt16}(len)
288288
unsafe_copy!(pointer(buf), p, len)
289-
ccall(:LocalFree,stdcall,Ptr{Void},(Ptr{Void},),p)
289+
ccall(:LocalFree, stdcall, Ptr{Void}, (Ptr{Void},), p)
290290
return transcode(String, buf)
291291
end
292292
end

0 commit comments

Comments
 (0)