Skip to content

Commit

Permalink
Insert the GC preserve into the expanded docs (JuliaLang#51884)
Browse files Browse the repository at this point in the history
The expanded form is not fully correct since it misses the preservation
of
the return value from `cconvert`. The text below talks about the fact
that
`cconvert` should do the allocations necessary, but the expanded code is
incorrect for any `cconvert` that actually does this.
  • Loading branch information
vchuravy committed Oct 27, 2023
1 parent 909bcea commit 8382d51
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions doc/src/manual/calling-c-and-fortran-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,14 @@ to the specified type. For example, the following call:
will behave as if it were written like this:

```julia
@ccall "libfoo".foo(
Base.unsafe_convert(Int32, Base.cconvert(Int32, x))::Int32,
Base.unsafe_convert(Float64, Base.cconvert(Float64, y))::Float64
c_x = Base.cconvert(Int32, x)
c_y = Base.cconvert(Float64, y)
GC.@preserve c_x c_y begin
@ccall "libfoo".foo(
Base.unsafe_convert(Int32, c_x)::Int32,
Base.unsafe_convert(Float64, c_y)::Float64
)::Cvoid
end
```

[`Base.cconvert`](@ref) normally just calls [`convert`](@ref), but can be defined to return an
Expand Down

0 comments on commit 8382d51

Please sign in to comment.