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

Preserve GValues from GC (fixes #581) #600

Merged
merged 2 commits into from
Dec 6, 2021
Merged

Conversation

timholy
Copy link
Member

@timholy timholy commented Dec 6, 2021

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. EDIT: actually, that can't
be correct, because it doesn't create them when RT===Nothing.
So probably #552 didn't trigger this.

This puts both potential GValue-arguments inside a GC.@preserve
to prevent garbage collection. Fixes #581.

A reproducer of the crash is with GtkObservables:

/some/path/GtkObservables$ julia --check-bounds=yes --color=yes --depwarn=yes --inline=yes --project=@. -e 'import Pkg; Pkg.test(; coverage=true)'

but that is obviously difficult to convert into a test. I've run it 5 times locally and have yet to see a crash, which did not happen before this commit.

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.
@timholy
Copy link
Member Author

timholy commented Dec 6, 2021

CC @BioTurboNick

@codecov
Copy link

codecov bot commented Dec 6, 2021

Codecov Report

Merging #600 (b7ec83c) into master (fc3a648) will increase coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #600      +/-   ##
==========================================
+ Coverage   48.60%   48.66%   +0.05%     
==========================================
  Files          32       32              
  Lines        2660     2661       +1     
==========================================
+ Hits         1293     1295       +2     
+ Misses       1367     1366       -1     
Impacted Files Coverage Δ
src/GLib/signals.jl 75.81% <100.00%> (+0.09%) ⬆️
src/events.jl 44.89% <0.00%> (+1.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fc3a648...b7ec83c. Read the comment docs.

@timholy
Copy link
Member Author

timholy commented Dec 6, 2021

I ran the tests 20 more times and never got a segfault. I think we can safely say this fixes the problem that has been holding back GtkObservables.

@tknopp
Copy link
Collaborator

tknopp commented Dec 6, 2021

then go ahead and press the button + release. It certainly does not hurt to prevent GC to collect that value during that call.

@timholy timholy merged commit d28f725 into master Dec 6, 2021
@timholy timholy deleted the teh/gvalues_preserve branch December 6, 2021 21:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New segfaults on nightly
2 participants