Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Preserve GValues from GC (fixes #581)
Browse files Browse the repository at this point in the history
As a consequence of the forced specialization on the `RT` argument
of `signal_emit` in #552, the compiler now knows whether
`RT === Nothing`. In that case, it also knows that
`return_value` will not be used, so it is free to be garbage-collected.
When that happens, it triggers segfaults.

This puts both potential `GValue`-arguments inside a `GC.@preserve`
to prevent garbage collection. Fixes #581.
  • Loading branch information
timholy committed Dec 6, 2021
1 parent fc3a648 commit 2e41a91
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/GLib/signals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ function signal_emit(w::GObject, sig::AbstractStringLike, ::Type{RT}, args...) w
end
signal_id = ccall((:g_signal_lookup, libgobject), Cuint, (Ptr{UInt8}, Csize_t), sig, G_OBJECT_CLASS_TYPE(w))
return_value = RT === Nothing ? C_NULL : gvalue(RT)
ccall((:g_signal_emitv, libgobject), Nothing, (Ptr{GValue}, Cuint, UInt32, Ptr{GValue}), gvalues(w, args...), signal_id, detail, return_value)
gvals = gvalues(w, args...)
GC.@preserve gvals return_value ccall((:g_signal_emitv, libgobject), Nothing, (Ptr{GValue}, Cuint, UInt32, Ptr{GValue}), gvals, signal_id, detail, return_value)
RT === Nothing ? nothing : return_value[RT]
end

Expand Down

0 comments on commit 2e41a91

Please sign in to comment.