Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ This section lists changes that do not have deprecation warnings.

* Juxtaposing string literals (e.g. `"x"y`) is now a syntax error ([#20575]).

* `finalizer(function, object)` now returns `object` rather than `nothing` ([#24679]).

* Macro calls with `for` expressions are now parsed as generators inside
function argument lists ([#18650]). Examples:

Expand Down
6 changes: 5 additions & 1 deletion base/distributed/remotecall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ end

function finalize_ref(r::AbstractRemoteRef)
if r.where > 0 # Handle the case of the finalizer having been called manually
islocked(client_refs) && return finalizer(finalize_ref, r) # delay finalizer for later, when it's not already locked
if islocked(client_refs)
# delay finalizer for later, when it's not already locked
finalizer(finalize_ref, r)
return nothing
end
delete!(client_refs, r)
if isa(r, RemoteChannel)
send_del_client(r)
Expand Down
6 changes: 4 additions & 2 deletions base/gcutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
finalizer(f, x)

Register a function `f(x)` to be called when there are no program-accessible references to
`x`. The type of `x` must be a `mutable struct`, otherwise the behavior of this function is
unpredictable.
`x`, and return `x`. The type of `x` must be a `mutable struct`, otherwise the behavior of
this function is unpredictable.
"""
function finalizer(@nospecialize(f), @nospecialize(o))
if isimmutable(o)
error("objects of type ", typeof(o), " cannot be finalized")
end
ccall(:jl_gc_add_finalizer_th, Void, (Ptr{Void}, Any, Any),
Core.getptls(), o, f)
return o
end

function finalizer(f::Ptr{Void}, o::T) where T
Expand All @@ -26,6 +27,7 @@ function finalizer(f::Ptr{Void}, o::T) where T
end
ccall(:jl_gc_add_ptr_finalizer, Void, (Ptr{Void}, Any, Ptr{Void}),
Core.getptls(), o, f)
return o
end

"""
Expand Down
5 changes: 4 additions & 1 deletion base/weakkeydict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ mutable struct WeakKeyDict{K,V} <: Associative{K,V}
t = new(Dict{Any,V}(), Threads.RecursiveSpinLock(), identity)
t.finalizer = function (k)
# when a weak key is finalized, remove from dictionary if it is still there
islocked(t) && return finalizer(t.finalizer, k)
if islocked(t)
finalizer(t.finalizer, k)
return nothing
end
delete!(t, k)
end
return t
Expand Down