Skip to content

Commit df848f8

Browse files
authored
Merge pull request #28396 from JuliaLang/ksh/docstrings
Doc Cstring and Cwstring
2 parents 17a5754 + 65b9f88 commit df848f8

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

base/c.jl

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,31 @@ Equivalent to the native `wchar_t` c-type ([`Int32`](@ref)).
122122
"""
123123
Cwchar_t
124124

125+
"""
126+
Cwstring
127+
128+
A C-style string composed of the native wide character type
129+
[`Cwchar_t`](@ref)s. `Cwstring`s are NUL-terminated. For
130+
C-style strings composed of the native character
131+
type, see [`Cstring`](@ref). For more information
132+
about string interopability with C, see the
133+
[manual](@ref man-bits-types).
134+
135+
"""
136+
Cwstring
137+
138+
"""
139+
Cstring
140+
141+
A C-style string composed of the native character type
142+
[`Cchar`](@ref)s. `Cstring`s are NUL-terminated. For
143+
C-style strings composed of the native wide character
144+
type, see [`Cwstring`](@ref). For more information
145+
about string interopability with C, see the
146+
[manual](@ref man-bits-types).
147+
"""
148+
Cstring
149+
125150
@static if ccall(:jl_get_UNAME, Any, ()) !== :NT
126151
const sizeof_mode_t = ccall(:jl_sizeof_mode_t, Cint, ())
127152
if sizeof_mode_t == 2
@@ -214,7 +239,7 @@ unsafe_convert(::Type{Cstring}, s::Symbol) = Cstring(unsafe_convert(Ptr{Cchar},
214239
215240
Converts a string `s` to a NUL-terminated `Vector{Cwchar_t}`, suitable for passing to C
216241
functions expecting a `Ptr{Cwchar_t}`. The main advantage of using this over the implicit
217-
conversion provided by `Cwstring` is if the function is called multiple times with the
242+
conversion provided by [`Cwstring`](@ref) is if the function is called multiple times with the
218243
same argument.
219244
220245
This is only available on Windows.
@@ -236,7 +261,7 @@ Convert string data between Unicode encodings. `src` is either a
236261
`String` or a `Vector{UIntXX}` of UTF-XX code units, where
237262
`XX` is 8, 16, or 32. `T` indicates the encoding of the return value:
238263
`String` to return a (UTF-8 encoded) `String` or `UIntXX`
239-
to return a `Vector{UIntXX}` of UTF-`XX` data. (The alias `Cwchar_t`
264+
to return a `Vector{UIntXX}` of UTF-`XX` data. (The alias [`Cwchar_t`](@ref)
240265
can also be used as the integer type, for converting `wchar_t*` strings
241266
used by external C libraries.)
242267
@@ -428,7 +453,7 @@ end
428453
reenable_sigint(f::Function)
429454
430455
Re-enable Ctrl-C handler during execution of a function.
431-
Temporarily reverses the effect of `disable_sigint`.
456+
Temporarily reverses the effect of [`disable_sigint`](@ref).
432457
"""
433458
function reenable_sigint(f::Function)
434459
sigatomic_end()

doc/src/base/c.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Core.Ref
2424
Base.Cchar
2525
Base.Cuchar
2626
Base.Cshort
27+
Base.Cstring
2728
Base.Cushort
2829
Base.Cint
2930
Base.Cuint
@@ -37,6 +38,7 @@ Base.Csize_t
3738
Base.Cssize_t
3839
Base.Cptrdiff_t
3940
Base.Cwchar_t
41+
Base.Cwstring
4042
Base.Cfloat
4143
Base.Cdouble
4244
```

doc/src/manual/calling-c-and-fortran-code.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ First, a review of some relevant Julia type terminology:
287287
| `struct ...; end` | `nothing` | "Singleton" :: a Leaf Type or Struct with no fields. |
288288
| `(...)` or `tuple(...)` | `(1, 2, 3)` | "Tuple" :: an immutable data-structure similar to an anonymous struct type, or a constant array. Represented as either an array or a struct. |
289289

290-
### Bits Types:
290+
### [Bits Types](@id man-bits-types)
291291

292292
There are several special types to be aware of, as no other type can be defined to behave the
293293
same:
@@ -374,7 +374,7 @@ an `Int` in Julia).
374374
| `va_arg` |   |   | Not supported |
375375
| `...` (variadic function specification) |   |   | `T...` (where `T` is one of the above types, variadic functions of different argument types are not supported) |
376376

377-
The `Cstring` type is essentially a synonym for `Ptr{UInt8}`, except the conversion to `Cstring`
377+
The [`Cstring`](@ref) type is essentially a synonym for `Ptr{UInt8}`, except the conversion to `Cstring`
378378
throws an error if the Julia string contains any embedded NUL characters (which would cause the
379379
string to be silently truncated if the C routine treats NUL as the terminator). If you are passing
380380
a `char*` to a C routine that does not assume NUL termination (e.g. because you pass an explicit
@@ -413,7 +413,7 @@ checks and is only meant to improve readability of the call.
413413
(`void`) but do return, use `Cvoid` instead.
414414

415415
!!! note
416-
For `wchar_t*` arguments, the Julia type should be `Cwstring` (if the C routine expects a NUL-terminated
416+
For `wchar_t*` arguments, the Julia type should be [`Cwstring`](@ref) (if the C routine expects a NUL-terminated
417417
string) or `Ptr{Cwchar_t}` otherwise. Note also that UTF-8 string data in Julia is internally
418418
NUL-terminated, so it can be passed to C functions expecting NUL-terminated data without making
419419
a copy (but using the `Cwstring` type will cause an error to be thrown if the string itself contains

0 commit comments

Comments
 (0)