Skip to content

Commit

Permalink
Merge pull request JuliaLang#19911 from barche/c_finalizer
Browse files Browse the repository at this point in the history
Run non-Julia finalizers at exit
  • Loading branch information
yuyichao authored Jan 19, 2017
2 parents d1ed1ff + 2044088 commit 4331b29
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ccalltest.c
Original file line number Diff line number Diff line change
Expand Up @@ -973,3 +973,7 @@ JL_DLLEXPORT float32x4_t test_ppc64_vec2(int64_t d1, float32x4_t a, float32x4_t
JL_DLLEXPORT int threadcall_args(int a, int b) {
return a + b;
}

JL_DLLEXPORT void c_exit_finalizer(void* v) {
printf("c_exit_finalizer: %d, %u", *(int*)v, (unsigned)((uintptr_t)v & (uintptr_t)1));
}
3 changes: 3 additions & 0 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ static void schedule_all_finalizers(arraylist_t *flist)
if (!gc_ptr_tag(v, 1)) {
schedule_finalization(v, f);
}
else {
((void (*)(void*))f)(gc_ptr_clear_tag(v, 1));
}
}
flist->len = 0;
}
Expand Down
5 changes: 5 additions & 0 deletions test/ccall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,11 @@ let A = [1]
@test ccall((:get_c_int, libccalltest), Cint, ()) == -1
end

# Pointer finalizer at exit (PR #19911)
let result = readstring(`$(Base.julia_cmd()) --startup-file=no -e "A = Ref{Cint}(42); finalizer(A, cglobal((:c_exit_finalizer, \"$libccalltest\"), Void))"`)
@test result == "c_exit_finalizer: 42, 0"
end

# SIMD Registers

typealias VecReg{N,T} NTuple{N,VecElement{T}}
Expand Down

0 comments on commit 4331b29

Please sign in to comment.