Skip to content

Commit 457071c

Browse files
yuyichaotkelman
authored andcommitted
Support @doc "" -> f() syntax early in bootstrap and move windows only doc string to julia.
(cherry picked from commit 2305d49) ref #13370
1 parent 3cdc2c6 commit 457071c

File tree

3 files changed

+47
-21
lines changed

3 files changed

+47
-21
lines changed

base/docs/bootstrap.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,22 @@ _expand_ = nothing
1919

2020
setexpand!(f) = global _expand_ = f
2121

22-
setexpand!() do str, obj
22+
function __bootexpand(str, obj)
2323
global docs = List((ccall(:jl_get_current_module, Any, ()), str, obj), docs)
24-
(isa(obj, Expr) && obj.head == :call) ? nothing : esc(Expr(:toplevel, obj))
24+
(isa(obj, Expr) && obj.head == :call) && return nothing
25+
(isa(obj, Expr) && obj.head == :module) && return esc(Expr(:toplevel, obj))
26+
esc(obj)
2527
end
2628

29+
function __bootexpand(expr::Expr)
30+
if expr.head !== :->
31+
throw(ArgumentError("Wrong argument to @doc"))
32+
end
33+
__bootexpand(expr.args...)
34+
end
35+
36+
setexpand!(__bootexpand)
37+
2738
"""
2839
DocBootstrap :: Module
2940

base/libc.jl

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -167,25 +167,36 @@ strerror(e::Integer) = bytestring(ccall(:strerror, Ptr{UInt8}, (Int32,), e))
167167
strerror() = strerror(errno())
168168

169169
@windows_only begin
170-
GetLastError() = ccall(:GetLastError,stdcall,UInt32,())
171-
function FormatMessage(e=GetLastError())
172-
const FORMAT_MESSAGE_ALLOCATE_BUFFER = UInt32(0x100)
173-
const FORMAT_MESSAGE_FROM_SYSTEM = UInt32(0x1000)
174-
const FORMAT_MESSAGE_IGNORE_INSERTS = UInt32(0x200)
175-
const FORMAT_MESSAGE_MAX_WIDTH_MASK = UInt32(0xFF)
176-
lpMsgBuf = Array(Ptr{UInt16})
177-
lpMsgBuf[1] = 0
178-
len = ccall(:FormatMessageW,stdcall,UInt32,(Cint, Ptr{Void}, Cint, Cint, Ptr{Ptr{UInt16}}, Cint, Ptr{Void}),
179-
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
180-
C_NULL, e, 0, lpMsgBuf, 0, C_NULL)
181-
p = lpMsgBuf[1]
182-
len == 0 && return utf8("")
183-
len = len + 1
184-
buf = Array(UInt16, len)
185-
unsafe_copy!(pointer(buf), p, len)
186-
ccall(:LocalFree,stdcall,Ptr{Void},(Ptr{Void},),p)
187-
return utf8(UTF16String(buf))
188-
end
170+
@doc """
171+
GetLastError()
172+
173+
Call the Win32 `GetLastError` function [only available on Windows].
174+
""" ->
175+
GetLastError() = ccall(:GetLastError,stdcall,UInt32,())
176+
177+
@doc """
178+
FormatMessage(n=GetLastError())
179+
180+
Convert a Win32 system call error code to a descriptive string [only available on Windows].
181+
""" ->
182+
function FormatMessage(e=GetLastError())
183+
const FORMAT_MESSAGE_ALLOCATE_BUFFER = UInt32(0x100)
184+
const FORMAT_MESSAGE_FROM_SYSTEM = UInt32(0x1000)
185+
const FORMAT_MESSAGE_IGNORE_INSERTS = UInt32(0x200)
186+
const FORMAT_MESSAGE_MAX_WIDTH_MASK = UInt32(0xFF)
187+
lpMsgBuf = Array(Ptr{UInt16})
188+
lpMsgBuf[1] = 0
189+
len = ccall(:FormatMessageW,stdcall,UInt32,(Cint, Ptr{Void}, Cint, Cint, Ptr{Ptr{UInt16}}, Cint, Ptr{Void}),
190+
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
191+
C_NULL, e, 0, lpMsgBuf, 0, C_NULL)
192+
p = lpMsgBuf[1]
193+
len == 0 && return utf8("")
194+
len = len + 1
195+
buf = Array(UInt16, len)
196+
unsafe_copy!(pointer(buf), p, len)
197+
ccall(:LocalFree,stdcall,Ptr{Void},(Ptr{Void},),p)
198+
return utf8(UTF16String(buf))
199+
end
189200
end
190201

191202
## Memory related ##

doc/stdlib/libc.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@
4646

4747
.. function:: GetLastError()
4848

49+
.. Docstring generated from Julia source
50+
4951
Call the Win32 ``GetLastError`` function [only available on Windows].
5052

5153
.. function:: FormatMessage(n=GetLastError())
5254

55+
.. Docstring generated from Julia source
56+
5357
Convert a Win32 system call error code to a descriptive string [only available on Windows].
5458

5559
.. function:: time(t::TmStruct)

0 commit comments

Comments
 (0)