Skip to content

Commit 9a3acdc

Browse files
authored
Merge pull request #19403 from JuliaLang/ksh/docptr
Move some pointer docstrings inline
2 parents b8b2634 + b77329a commit 9a3acdc

File tree

3 files changed

+41
-47
lines changed

3 files changed

+41
-47
lines changed

base/docs/helpdb/Base.jl

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,18 +2135,6 @@ and then the complex square root of the triangular factor.
21352135
"""
21362136
sqrtm
21372137

2138-
"""
2139-
unsafe_store!(p::Ptr{T}, x, [i::Integer=1])
2140-
2141-
Store a value of type `T` to the address of the ith element (1-indexed) starting at `p`.
2142-
This is equivalent to the C expression `p[i-1] = x`.
2143-
2144-
The `unsafe` prefix on this function indicates that no validation is performed on the
2145-
pointer `p` to ensure that it is valid. Incorrect usage may corrupt or segfault your
2146-
program, in the same manner as C.
2147-
"""
2148-
unsafe_store!
2149-
21502138
"""
21512139
readcsv(source, [T::Type]; options...)
21522140
@@ -2736,18 +2724,6 @@ Determine whether `x` is of the given `type`.
27362724
"""
27372725
isa
27382726

2739-
"""
2740-
unsafe_load(p::Ptr{T}, [i::Integer=1])
2741-
2742-
Load a value of type `T` from the address of the ith element (1-indexed) starting at `p`.
2743-
This is equivalent to the C expression `p[i-1]`.
2744-
2745-
The `unsafe` prefix on this function indicates that no validation is performed on the
2746-
pointer `p` to ensure that it is valid. Incorrect usage may segfault your program or return
2747-
garbage answers, in the same manner as C.
2748-
"""
2749-
unsafe_load
2750-
27512727
"""
27522728
catch_backtrace()
27532729
@@ -2891,15 +2867,6 @@ options.
28912867
"""
28922868
eigvals
28932869

2894-
"""
2895-
pointer_from_objref(object_instance)
2896-
2897-
Get the memory address of a Julia object as a `Ptr`. The existence of the resulting `Ptr`
2898-
will not protect the object from garbage collection, so you must ensure that the object
2899-
remains referenced for the whole time that the `Ptr` will be used.
2900-
"""
2901-
pointer_from_objref
2902-
29032870
"""
29042871
copy!(dest, src)
29052872
@@ -3314,15 +3281,6 @@ Integer division was attempted with a denominator value of 0.
33143281
"""
33153282
DivideError
33163283

3317-
"""
3318-
unsafe_pointer_to_objref(p::Ptr)
3319-
3320-
Convert a `Ptr` to an object reference. Assumes the pointer refers to a valid heap-allocated
3321-
Julia object. If this is not the case, undefined behavior results, hence this function is
3322-
considered "unsafe" and should be used with care.
3323-
"""
3324-
unsafe_pointer_to_objref
3325-
33263284
"""
33273285
dawson(x)
33283286

base/pointer.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,28 @@ end
6868
unsafe_wrap{N,I<:Integer}(Atype::Type, p::Ptr, dims::NTuple{N,I}, own::Bool=false) =
6969
unsafe_wrap(Atype, p, convert(Tuple{Vararg{Int}}, dims), own)
7070

71+
"""
72+
unsafe_load(p::Ptr{T}, i::Integer=1)
73+
74+
Load a value of type `T` from the address of the `i`th element (1-indexed) starting at `p`.
75+
This is equivalent to the C expression `p[i-1]`.
76+
77+
The `unsafe` prefix on this function indicates that no validation is performed on the
78+
pointer `p` to ensure that it is valid. Incorrect usage may segfault your program or return
79+
garbage answers, in the same manner as C.
80+
"""
7181
unsafe_load(p::Ptr, i::Integer=1) = pointerref(p, Int(i), 1)
82+
83+
"""
84+
unsafe_store!(p::Ptr{T}, x, i::Integer=1)
85+
86+
Store a value of type `T` to the address of the `i`th element (1-indexed) starting at `p`.
87+
This is equivalent to the C expression `p[i-1] = x`.
88+
89+
The `unsafe` prefix on this function indicates that no validation is performed on the
90+
pointer `p` to ensure that it is valid. Incorrect usage may corrupt or segfault your
91+
program, in the same manner as C.
92+
"""
7293
unsafe_store!(p::Ptr{Any}, x::ANY, i::Integer=1) = pointerset(p, x, Int(i), 1)
7394
unsafe_store!{T}(p::Ptr{T}, x, i::Integer=1) = pointerset(p, convert(T,x), Int(i), 1)
7495

@@ -99,7 +120,22 @@ unsafe_wrap(::Type{String}, p::Union{Ptr{UInt8},Ptr{Int8}}, own::Bool=false) =
99120
unsafe_wrap(String, p, ccall(:strlen, Csize_t, (Ptr{UInt8},), p), own)
100121

101122
# convert a raw Ptr to an object reference, and vice-versa
123+
"""
124+
unsafe_pointer_to_objref(p::Ptr)
125+
126+
Convert a `Ptr` to an object reference. Assumes the pointer refers to a valid heap-allocated
127+
Julia object. If this is not the case, undefined behavior results, hence this function is
128+
considered "unsafe" and should be used with care.
129+
"""
102130
unsafe_pointer_to_objref(x::Ptr) = ccall(:jl_value_ptr, Any, (Ptr{Void},), x)
131+
132+
"""
133+
pointer_from_objref(x)
134+
135+
Get the memory address of a Julia object as a `Ptr`. The existence of the resulting `Ptr`
136+
will not protect the object from garbage collection, so you must ensure that the object
137+
remains referenced for the whole time that the `Ptr` will be used.
138+
"""
103139
pointer_from_objref(x::ANY) = ccall(:jl_value_ptr, Ptr{Void}, (Any,), x)
104140
data_pointer_from_objref(x::ANY) = pointer_from_objref(x)::Ptr{Void}
105141

doc/stdlib/c.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,19 @@
6060

6161
Neither ``convert`` nor ``cconvert`` should take a Julia object and turn it into a ``Ptr``\ .
6262

63-
.. function:: unsafe_load(p::Ptr{T}, [i::Integer=1])
63+
.. function:: unsafe_load(p::Ptr{T}, i::Integer=1)
6464

6565
.. Docstring generated from Julia source
6666
67-
Load a value of type ``T`` from the address of the ith element (1-indexed) starting at ``p``\ . This is equivalent to the C expression ``p[i-1]``\ .
67+
Load a value of type ``T`` from the address of the ``i``\ th element (1-indexed) starting at ``p``\ . This is equivalent to the C expression ``p[i-1]``\ .
6868

6969
The ``unsafe`` prefix on this function indicates that no validation is performed on the pointer ``p`` to ensure that it is valid. Incorrect usage may segfault your program or return garbage answers, in the same manner as C.
7070

71-
.. function:: unsafe_store!(p::Ptr{T}, x, [i::Integer=1])
71+
.. function:: unsafe_store!(p::Ptr{T}, x, i::Integer=1)
7272

7373
.. Docstring generated from Julia source
7474
75-
Store a value of type ``T`` to the address of the ith element (1-indexed) starting at ``p``\ . This is equivalent to the C expression ``p[i-1] = x``\ .
75+
Store a value of type ``T`` to the address of the ``i``\ th element (1-indexed) starting at ``p``\ . This is equivalent to the C expression ``p[i-1] = x``\ .
7676

7777
The ``unsafe`` prefix on this function indicates that no validation is performed on the pointer ``p`` to ensure that it is valid. Incorrect usage may corrupt or segfault your program, in the same manner as C.
7878

@@ -120,7 +120,7 @@
120120

121121
This function is labelled "unsafe" because it will crash if ``pointer`` is not a valid memory address to data of the requested length.
122122

123-
.. function:: pointer_from_objref(object_instance)
123+
.. function:: pointer_from_objref(x)
124124

125125
.. Docstring generated from Julia source
126126

0 commit comments

Comments
 (0)