diff --git a/NEWS.md b/NEWS.md index 7d1277a02dc3a..ef33b8e5262f4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -294,13 +294,7 @@ This section lists changes that do not have deprecation warnings. * The return type of `reinterpret` has changed to `ReinterpretArray`. `reinterpret` on sparse arrays has been discontinued. - * `Base.find_in_path` is now `Base.find_package` or `Base.find_source_file` ([#24320]). - - * `finalizer` now takes functions or pointers as its first argument, and the object being - finalized as its second (rather than the reverse). For the majority of use cases - deprecation warnings will be triggered. However, deprecation warnings will not trigger where - (1) the callable argument is not a subtype of `Function`; or (2) both arguments are - `Function`s or `Ptr{Void}`s ([#24605]). + * `Base.find_in_path` is now `Base.find_package` or `Base.find_source_file` ([#24320]) * The `kill` function now throws errors on user error (e.g. on permission errors), but returns successfully if the process had previously exited. diff --git a/base/deprecated.jl b/base/deprecated.jl index bc953759b22f9..63ad85a42626e 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -2138,16 +2138,6 @@ end @deprecate cumsum(A::AbstractArray) cumsum(A, 1) @deprecate cumprod(A::AbstractArray) cumprod(A, 1) -# issue #16307 -@deprecate finalizer(o, f::Function) finalizer(f, o) -# This misses other callables but they are very rare in the wild -@deprecate finalizer(o, f::Ptr{Void}) finalizer(f, o) - -# Avoid ambiguity, can remove when deprecations are removed: -# This is almost certainly going to be a silent failure for code that is not updated. -finalizer(f::Ptr{Void}, o::Ptr{Void}) = invoke(finalizer, Tuple{Ptr{Void}, Any}, f, o) -finalizer(f::Ptr{Void}, o::Function) = invoke(finalizer, Tuple{Ptr{Void}, Any}, f, o) - # Broadcast extension API (#23939) @eval Broadcast begin Base.@deprecate_binding containertype combine_styles false diff --git a/base/distributed/cluster.jl b/base/distributed/cluster.jl index 76a682691288e..9ec2811359f94 100644 --- a/base/distributed/cluster.jl +++ b/base/distributed/cluster.jl @@ -518,11 +518,7 @@ function create_worker(manager, wconfig) w = Worker(w.id, r_s, w_s, manager; config=wconfig) # install a finalizer to perform cleanup if necessary - finalizer(w) do w - if myid() == 1 - manage(w.manager, w.id, w.config, :finalize) - end - end + finalizer(w, (w)->if myid() == 1 manage(w.manager, w.id, w.config, :finalize) end) # set when the new worker has finshed connections with all other workers ntfy_oid = RRID() diff --git a/base/distributed/clusterserialize.jl b/base/distributed/clusterserialize.jl index 4a61f59710a2e..2a42f35a7f572 100644 --- a/base/distributed/clusterserialize.jl +++ b/base/distributed/clusterserialize.jl @@ -74,9 +74,7 @@ function serialize(s::ClusterSerializer, t::TypeName) serialize_typename(s, t) s.anonfunc_id = prev push!(s.tn_obj_sent, identifier) - finalizer(t) do x - cleanup_tname_glbs(s, identifier) - end + finalizer(t, x->cleanup_tname_glbs(s, identifier)) end # Send global refs if required. @@ -135,9 +133,7 @@ function serialize_global_from_main(s::ClusterSerializer, sym) elseif !haskey(s.glbs_sent, oid) # set up a finalizer the first time this object is sent try - finalizer(v) do x - delete_global_tracker(s,x) - end + finalizer(v, x->delete_global_tracker(s,x)) catch ex # Do not track objects that cannot be finalized. if isa(ex, ErrorException) diff --git a/base/distributed/remotecall.jl b/base/distributed/remotecall.jl index 442c0b66b5abe..8aaedcd8717ed 100644 --- a/base/distributed/remotecall.jl +++ b/base/distributed/remotecall.jl @@ -52,7 +52,7 @@ function test_existing_ref(r::AbstractRemoteRef) end client_refs[r] = nothing - finalizer(finalize_ref, r) + finalizer(r, finalize_ref) return r end @@ -60,7 +60,7 @@ function finalize_ref(r::AbstractRemoteRef) if r.where > 0 # Handle the case of the finalizer having been called manually if islocked(client_refs) # delay finalizer for later, when it's not already locked - finalizer(finalize_ref, r) + finalizer(r, finalize_ref) return nothing end delete!(client_refs, r) diff --git a/base/distributed/workerpool.jl b/base/distributed/workerpool.jl index 1c444062e6a4f..5fc2c83837e3f 100644 --- a/base/distributed/workerpool.jl +++ b/base/distributed/workerpool.jl @@ -223,7 +223,7 @@ mutable struct CachingPool <: AbstractWorkerPool function CachingPool() wp = new(Channel{Int}(typemax(Int)), Set{Int}(), Dict{Int, Function}()) - finalizer(clear!, wp) + finalizer(wp, clear!) wp end end diff --git a/base/event.jl b/base/event.jl index 87784f934a978..5f48595dea76b 100644 --- a/base/event.jl +++ b/base/event.jl @@ -303,7 +303,7 @@ mutable struct AsyncCondition function AsyncCondition() this = new(Libc.malloc(_sizeof_uv_async), Condition(), true) associate_julia_struct(this.handle, this) - finalizer(uvfinalize, this) + finalizer(this, uvfinalize) err = ccall(:uv_async_init, Cint, (Ptr{Void}, Ptr{Void}, Ptr{Void}), eventloop(), this, uv_jl_asynccb::Ptr{Void}) if err != 0 @@ -372,7 +372,7 @@ mutable struct Timer end associate_julia_struct(this.handle, this) - finalizer(uvfinalize, this) + finalizer(this, uvfinalize) ccall(:uv_update_time, Void, (Ptr{Void},), eventloop()) ccall(:uv_timer_start, Cint, (Ptr{Void}, Ptr{Void}, UInt64, UInt64), diff --git a/base/gcutils.jl b/base/gcutils.jl index 0ff53bceb6894..3f887c2f98c14 100644 --- a/base/gcutils.jl +++ b/base/gcutils.jl @@ -5,13 +5,13 @@ ==(w, v::WeakRef) = isequal(w, v.value) """ - finalizer(f, x) + finalizer(x, f) Register a function `f(x)` to be called when there are no program-accessible references to `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)) +function finalizer(@nospecialize(o), @nospecialize(f)) if isimmutable(o) error("objects of type ", typeof(o), " cannot be finalized") end @@ -20,7 +20,7 @@ function finalizer(@nospecialize(f), @nospecialize(o)) return o end -function finalizer(f::Ptr{Void}, o::T) where T +function finalizer(o::T, f::Ptr{Void}) where T @_inline_meta if isimmutable(T) error("objects of type ", T, " cannot be finalized") diff --git a/base/gmp.jl b/base/gmp.jl index 5cb20f3189e77..33eaa6e704c9a 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -55,7 +55,7 @@ mutable struct BigInt <: Signed function BigInt() b = new(zero(Cint), zero(Cint), C_NULL) MPZ.init!(b) - finalizer(cglobal((:__gmpz_clear, :libgmp)), b) + finalizer(b, cglobal((:__gmpz_clear, :libgmp))) return b end end diff --git a/base/iostream.jl b/base/iostream.jl index 117bf77e7f8a6..eff717baa0d29 100644 --- a/base/iostream.jl +++ b/base/iostream.jl @@ -18,7 +18,7 @@ function IOStream(name::AbstractString, finalize::Bool) buf = zeros(UInt8,sizeof_ios_t) x = IOStream(name, buf) if finalize - finalizer(close, x) + finalizer(x, close) end return x end diff --git a/base/libgit2/gitcredential.jl b/base/libgit2/gitcredential.jl index 75da9c85f921b..c6f9aeb39ec4f 100644 --- a/base/libgit2/gitcredential.jl +++ b/base/libgit2/gitcredential.jl @@ -19,7 +19,7 @@ mutable struct GitCredential username::Nullable{<:AbstractString}, password::Nullable{<:AbstractString}) c = new(protocol, host, path, username, password, true) - finalizer(securezero!, c) + finalizer(c, securezero!) return c end end diff --git a/base/libgit2/types.jl b/base/libgit2/types.jl index 9ba668e0a41e6..00b1f820c4c5f 100644 --- a/base/libgit2/types.jl +++ b/base/libgit2/types.jl @@ -944,7 +944,7 @@ for (typ, owntyp, sup, cname) in [ obj = new(ptr) if fin Threads.atomic_add!(REFCOUNT, UInt(1)) - finalizer(Base.close, obj) + finalizer(obj, Base.close) end return obj end @@ -958,7 +958,7 @@ for (typ, owntyp, sup, cname) in [ obj = new(owner, ptr) if fin Threads.atomic_add!(REFCOUNT, UInt(1)) - finalizer(Base.close, obj) + finalizer(obj, Base.close) end return obj end @@ -1000,7 +1000,7 @@ mutable struct GitSignature <: AbstractGitObject function GitSignature(ptr::Ptr{SignatureStruct}) @assert ptr != C_NULL obj = new(ptr) - finalizer(Base.close, obj) + finalizer(obj, Base.close) return obj end end @@ -1143,7 +1143,7 @@ mutable struct UserPasswordCredential <: AbstractCredential pass::String function UserPasswordCredential(user::AbstractString="", pass::AbstractString="") c = new(user, pass) - finalizer(securezero!, c) + finalizer(c, securezero!) return c end @@ -1181,7 +1181,7 @@ mutable struct SSHCredential <: AbstractCredential function SSHCredential(user::AbstractString="", pass::AbstractString="", prvkey::AbstractString="", pubkey::AbstractString="") c = new(user, pass, prvkey, pubkey) - finalizer(securezero!, c) + finalizer(c, securezero!) return c end diff --git a/base/locks.jl b/base/locks.jl index 6bf9c1274bc74..e674d5d877191 100644 --- a/base/locks.jl +++ b/base/locks.jl @@ -185,7 +185,7 @@ mutable struct Mutex <: AbstractLock function Mutex() m = new(zero(Int16), Libc.malloc(UV_MUTEX_SIZE)) ccall(:uv_mutex_init, Void, (Ptr{Void},), m.handle) - finalizer(_uv_hook_close, m) + finalizer(m, _uv_hook_close) return m end end diff --git a/base/mpfr.jl b/base/mpfr.jl index 3069431c297e8..e2e482e32ac9c 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -60,7 +60,7 @@ mutable struct BigFloat <: AbstractFloat prec = precision(BigFloat) z = new(zero(Clong), zero(Cint), zero(Clong), C_NULL) ccall((:mpfr_init2,:libmpfr), Void, (Ref{BigFloat}, Clong), z, prec) - finalizer(cglobal((:mpfr_clear, :libmpfr)), z) + finalizer(z, cglobal((:mpfr_clear, :libmpfr))) return z end @@ -967,7 +967,7 @@ function Base.deepcopy_internal(x::BigFloat, stackdict::ObjectIdDict) prec = precision(x) y = BigFloat(zero(Clong), zero(Cint), zero(Clong), C_NULL) ccall((:mpfr_init2,:libmpfr), Void, (Ref{BigFloat}, Clong), y, prec) - finalizer(cglobal((:mpfr_clear, :libmpfr)), y) + finalizer(y, cglobal((:mpfr_clear, :libmpfr))) ccall((:mpfr_set, :libmpfr), Int32, (Ref{BigFloat}, Ref{BigFloat}, Int32), y, x, ROUNDING_MODE[]) stackdict[x] = y return y diff --git a/base/precompile.jl b/base/precompile.jl index 76e4718b7ecb6..620ab3ea042fe 100644 --- a/base/precompile.jl +++ b/base/precompile.jl @@ -16,7 +16,7 @@ precompile(Tuple{typeof(Base.copy!), Array{String, 1}, Int64, Array{Any, 1}, Int precompile(Tuple{typeof(Base.empty!), Base.Dict{Int64, Union{Base.Distributed.Worker, Base.Distributed.LocalProcess}}}) precompile(Tuple{typeof(Core.Inference.isbits), Base.Distributed.DefaultClusterManager}) precompile(Tuple{typeof(Base.Distributed.init_worker), String, Base.Distributed.DefaultClusterManager}) -precompile(Tuple{typeof(Base.finalizer), typeof(Base.uvfinalize), Base.TCPServer}) +precompile(Tuple{typeof(Base.finalizer), Base.TCPServer, typeof(Base.uvfinalize)}) precompile(Tuple{Type{Base.TCPServer}, Ptr{Void}, Int64}) precompile(Tuple{typeof(Base.show), Base.IOContext{Base.GenericIOBuffer{Array{UInt8, 1}}}, Int32}) precompile(Tuple{typeof(Base.print), Base.GenericIOBuffer{Array{UInt8, 1}}, Base.Libc.RawFD}) @@ -102,7 +102,7 @@ precompile(Tuple{typeof(Core.Inference.start), Core.Inference.Generator{Tuple{Tu precompile(Tuple{typeof(Core.Inference.done), Core.Inference.Generator{Tuple{Tuple{Base.DevNullStream, Base.DevNullStream, Base.DevNullStream}}, Type{QuoteNode}}, Int64}) precompile(Tuple{typeof(Core.Inference.next), Core.Inference.Generator{Tuple{Tuple{Base.DevNullStream, Base.DevNullStream, Base.DevNullStream}}, Type{QuoteNode}}, Int64}) precompile(Tuple{typeof(Core.Inference.isbits), Base.DevNullStream}) -precompile(Tuple{typeof(Base.finalizer), typeof(Base.uvfinalize), Base.Process}) +precompile(Tuple{typeof(Base.finalizer), Base.Process, typeof(Base.uvfinalize)}) precompile(Tuple{typeof(Core.Inference.isbits), Tuple{Base.DevNullStream, Bool}}) precompile(Tuple{Type{Ref{Base.Cstring}}, Array{String, 1}}) precompile(Tuple{typeof(Core.Inference.eltype), Type{Array{String, 1}}}) @@ -1544,7 +1544,7 @@ precompile(Tuple{typeof(Base.rehash!), Base.Dict{WeakRef, Void}, Int64}) precompile(Tuple{typeof(Base.ht_keyindex2!), Base.Dict{WeakRef, Void}, WeakRef}) precompile(Tuple{typeof(Base._setindex!), Base.Dict{WeakRef, Void}, Void, WeakRef, Int64}) precompile(Tuple{typeof(Base.setindex!), Base.Dict{WeakRef, Void}, Void, WeakRef}) -precompile(Tuple{typeof(Base.finalizer), typeof(Base.Distributed.finalize_ref), Base.Distributed.RemoteChannel{Base.Channel{Any}}}) +precompile(Tuple{typeof(Base.finalizer), Base.Distributed.RemoteChannel{Base.Channel{Any}}, typeof(Base.Distributed.finalize_ref)}) precompile(Tuple{typeof(Base.Distributed.test_existing_ref), Base.Distributed.RemoteChannel{Base.Channel{Any}}}) precompile(Tuple{Type{Base.Distributed.RemoteChannel{T} where T<:Base.AbstractChannel}, Int64}) precompile(Tuple{Type{Base.Channel{Int64}}, Int64}) @@ -1704,7 +1704,7 @@ precompile(Tuple{typeof(Base.Filesystem.mkdir), String, UInt16}) precompile(Tuple{typeof(Base.Filesystem.mkpath), String, UInt16}) precompile(Tuple{typeof(Base.Filesystem.samefile), String, String}) precompile(Tuple{typeof(Base.Filesystem.unlink), String}) -precompile(Tuple{typeof(Base.finalizer), typeof(Base.Distributed.finalize_ref), Base.Distributed.Future}) +precompile(Tuple{typeof(Base.finalizer), Base.Distributed.Future, typeof(Base.Distributed.finalize_ref)}) precompile(Tuple{typeof(Base.find_all_in_cache_path), Symbol}) precompile(Tuple{typeof(Base.find_package), String}) precompile(Tuple{typeof(Base.find_source_file), String}) diff --git a/base/process.jl b/base/process.jl index 0d56aaee5b2f1..84b921e607748 100644 --- a/base/process.jl +++ b/base/process.jl @@ -328,7 +328,7 @@ mutable struct Process <: AbstractPipe typemin(fieldtype(Process, :exitcode)), typemin(fieldtype(Process, :termsignal)), Condition(), Condition()) - finalizer(uvfinalize, this) + finalizer(this, uvfinalize) return this end end diff --git a/base/regex.jl b/base/regex.jl index 344730007d7ec..b82b7b75e3a05 100644 --- a/base/regex.jl +++ b/base/regex.jl @@ -29,10 +29,10 @@ mutable struct Regex end re = compile(new(pattern, compile_options, match_options, C_NULL, C_NULL, Csize_t[], C_NULL)) - finalizer(re) do re - re.regex == C_NULL || PCRE.free_re(re.regex) - re.match_data == C_NULL || PCRE.free_match_data(re.match_data) - end + finalizer(re, re->begin + re.regex == C_NULL || PCRE.free_re(re.regex) + re.match_data == C_NULL || PCRE.free_match_data(re.match_data) + end) re end end diff --git a/base/repl/REPL.jl b/base/repl/REPL.jl index c291bd7de8ca4..b24c0c69ed097 100644 --- a/base/repl/REPL.jl +++ b/base/repl/REPL.jl @@ -832,9 +832,7 @@ function setup_interface( try hist_path = find_hist_file() f = open(hist_path, true, true, true, false, false) - finalizer(replc) do replc - close(f) - end + finalizer(replc, replc->close(f)) hist_from_file(hp, f, hist_path) catch e print_response(repl, e, catch_backtrace(), true, Base.have_color) diff --git a/base/socket.jl b/base/socket.jl index 19aa7b0a2108c..324835d0fc758 100644 --- a/base/socket.jl +++ b/base/socket.jl @@ -278,7 +278,7 @@ mutable struct TCPSocket <: LibuvStream ReentrantLock(), DEFAULT_READ_BUFFER_SZ) associate_julia_struct(tcp.handle, tcp) - finalizer(uvfinalize, tcp) + finalizer(tcp, uvfinalize) return tcp end end @@ -308,7 +308,7 @@ mutable struct TCPServer <: LibuvServer Condition(), Condition()) associate_julia_struct(tcp.handle, tcp) - finalizer(uvfinalize, tcp) + finalizer(tcp, uvfinalize) return tcp end end @@ -370,7 +370,7 @@ mutable struct UDPSocket <: LibuvStream Condition(), Condition()) associate_julia_struct(udp.handle, udp) - finalizer(uvfinalize, udp) + finalizer(udp, uvfinalize) return udp end end diff --git a/base/stream.jl b/base/stream.jl index 4cf2d753f67ef..15d050dc0ee60 100644 --- a/base/stream.jl +++ b/base/stream.jl @@ -120,7 +120,7 @@ mutable struct PipeEndpoint <: LibuvStream ReentrantLock(), DEFAULT_READ_BUFFER_SZ) associate_julia_struct(handle, p) - finalizer(uvfinalize, p) + finalizer(p, uvfinalize) return p end end @@ -136,7 +136,7 @@ mutable struct PipeServer <: LibuvServer Condition(), Condition()) associate_julia_struct(p.handle, p) - finalizer(uvfinalize, p) + finalizer(p, uvfinalize) return p end end @@ -169,7 +169,7 @@ mutable struct TTY <: LibuvStream nothing, ReentrantLock(), DEFAULT_READ_BUFFER_SZ) associate_julia_struct(handle, tty) - finalizer(uvfinalize, tty) + finalizer(tty, uvfinalize) @static if Sys.iswindows() tty.ispty = ccall(:jl_ispty, Cint, (Ptr{Void},), handle) != 0 end diff --git a/base/weakkeydict.jl b/base/weakkeydict.jl index f07d2f29f5ea0..1ea042f3280e0 100644 --- a/base/weakkeydict.jl +++ b/base/weakkeydict.jl @@ -22,7 +22,7 @@ mutable struct WeakKeyDict{K,V} <: Associative{K,V} t.finalizer = function (k) # when a weak key is finalized, remove from dictionary if it is still there if islocked(t) - finalizer(t.finalizer, k) + finalizer(k, t.finalizer) return nothing end delete!(t, k) @@ -91,7 +91,7 @@ trylock(f, wkh::WeakKeyDict) = trylock(f, wkh.lock) function setindex!(wkh::WeakKeyDict{K}, v, key) where K k = convert(K, key) - finalizer(wkh.finalizer, k) + finalizer(k, wkh.finalizer) lock(wkh) do wkh.ht[WeakRef(k)] = v end @@ -121,12 +121,12 @@ length(t::WeakKeyDict) = length(t.ht) function start(t::WeakKeyDict{K,V}) where V where K gc_token = Ref{Bool}(false) # no keys will be deleted via finalizers until this token is gc'd - finalizer(gc_token) do r + finalizer(gc_token, function(r) if r[] r[] = false unlock(t.lock) end - end + end) s = lock(t.lock) gc_token[] = true return (start(t.ht), gc_token) diff --git a/stdlib/Base64/src/encode.jl b/stdlib/Base64/src/encode.jl index be44d5da07b92..37dda446cd525 100644 --- a/stdlib/Base64/src/encode.jl +++ b/stdlib/Base64/src/encode.jl @@ -39,7 +39,7 @@ struct Base64EncodePipe <: IO # The buffer size must be at least 3. buffer = Buffer(512) pipe = new(io, buffer) - finalizer(_ -> close(pipe), buffer) + finalizer(buffer, _ -> close(pipe)) return pipe end end diff --git a/stdlib/FileWatching/src/FileWatching.jl b/stdlib/FileWatching/src/FileWatching.jl index 8512cae6b9e2b..03c6c707eda5d 100644 --- a/stdlib/FileWatching/src/FileWatching.jl +++ b/stdlib/FileWatching/src/FileWatching.jl @@ -77,7 +77,7 @@ mutable struct FileMonitor Libc.free(handle) throw(UVError("FileMonitor", err)) end - finalizer(uvfinalize, this) + finalizer(this, uvfinalize) return this end end @@ -98,7 +98,7 @@ mutable struct PollingFileWatcher Libc.free(handle) throw(UVError("PollingFileWatcher", err)) end - finalizer(uvfinalize, this) + finalizer(this, uvfinalize) return this end end @@ -146,7 +146,7 @@ mutable struct _FDWatcher Libc.free(handle) throw(UVError("FDWatcher", err)) end - finalizer(uvfinalize, this) + finalizer(this, uvfinalize) FDWatchers[fdnum] = this return this end @@ -195,7 +195,7 @@ mutable struct _FDWatcher Libc.free(handle) throw(UVError("FDWatcher", err)) end - finalizer(uvfinalize, this) + finalizer(this, uvfinalize) return this end end @@ -208,13 +208,13 @@ mutable struct FDWatcher # WARNING: make sure `close` has been manually called on this watcher before closing / destroying `fd` function FDWatcher(fd::RawFD, readable::Bool, writable::Bool) this = new(_FDWatcher(fd, readable, writable), readable, writable) - finalizer(close, this) + finalizer(this, close) return this end @static if Sys.iswindows() function FDWatcher(fd::WindowsRawSocket, readable::Bool, writable::Bool) this = new(_FDWatcher(fd, readable, writable), readable, writable) - finalizer(close, this) + finalizer(this, close) return this end end diff --git a/stdlib/FileWatching/test/runtests.jl b/stdlib/FileWatching/test/runtests.jl index e2dde2eac3be6..3bd67c4fbec8e 100644 --- a/stdlib/FileWatching/test/runtests.jl +++ b/stdlib/FileWatching/test/runtests.jl @@ -133,7 +133,7 @@ end # make sure repeating timers work @noinline function make_unrooted_timer(a) t = Timer(0.0, 0.1) - finalizer(t -> a[] += 1, t) + finalizer(t, t -> a[] += 1) wait(t) e = @elapsed for i = 1:5 wait(t) diff --git a/stdlib/Mmap/src/Mmap.jl b/stdlib/Mmap/src/Mmap.jl index 8e91cb940dd72..1cc4c795e0347 100644 --- a/stdlib/Mmap/src/Mmap.jl +++ b/stdlib/Mmap/src/Mmap.jl @@ -208,7 +208,7 @@ function mmap(io::IO, end # os-test # convert mmapped region to Julia Array at `ptr + (offset - offset_page)` since file was mapped at offset_page A = unsafe_wrap(Array, convert(Ptr{T}, UInt(ptr) + UInt(offset - offset_page)), dims) - finalizer(A) do x + finalizer(A, function(x) @static if Sys.isunix() systemerror("munmap", ccall(:munmap, Cint, (Ptr{Void}, Int), ptr, mmaplen) != 0) else @@ -216,7 +216,7 @@ function mmap(io::IO, status |= ccall(:CloseHandle, stdcall, Cint, (Ptr{Void},), handle)!=0 status || error("could not unmap view: $(Libc.FormatMessage())") end - end + end) return A end diff --git a/stdlib/SharedArrays/src/SharedArrays.jl b/stdlib/SharedArrays/src/SharedArrays.jl index 543e73cb29340..834709891a1aa 100644 --- a/stdlib/SharedArrays/src/SharedArrays.jl +++ b/stdlib/SharedArrays/src/SharedArrays.jl @@ -257,7 +257,7 @@ function initialize_shared_array(S, onlocalhost, init, pids) end end - finalizer(finalize_refs, S) + finalizer(S, finalize_refs) S end diff --git a/stdlib/SuiteSparse/src/cholmod.jl b/stdlib/SuiteSparse/src/cholmod.jl index c6d99bf1d7c8f..71c0e9c667d8f 100644 --- a/stdlib/SuiteSparse/src/cholmod.jl +++ b/stdlib/SuiteSparse/src/cholmod.jl @@ -206,7 +206,7 @@ mutable struct Dense{T<:VTypes} <: DenseMatrix{T} "unknown reasons. Please submit a bug report.")) end A = new(p) - finalizer(free!, A) + finalizer(A, free!) return A end end @@ -258,7 +258,7 @@ mutable struct Sparse{Tv<:VTypes} <: AbstractSparseMatrix{Tv,SuiteSparse_long} "unknown reasons. Please submit a bug report.")) end A = new(p) - finalizer(free!, A) + finalizer(A, free!) return A end end @@ -342,7 +342,7 @@ mutable struct Factor{Tv} <: Factorization{Tv} end F = new(p) if register_finalizer - finalizer(free!, F) + finalizer(F, free!) end return F end diff --git a/stdlib/SuiteSparse/src/umfpack.jl b/stdlib/SuiteSparse/src/umfpack.jl index 0749ddcf2f3f9..c1bce7aca1277 100644 --- a/stdlib/SuiteSparse/src/umfpack.jl +++ b/stdlib/SuiteSparse/src/umfpack.jl @@ -146,7 +146,7 @@ function lufact(S::SparseMatrixCSC{<:UMFVTypes,<:UMFITypes}) zerobased ? copy(S.colptr) : decrement(S.colptr), zerobased ? copy(S.rowval) : decrement(S.rowval), copy(S.nzval)) - finalizer(umfpack_free_symbolic, res) + finalizer(res, umfpack_free_symbolic) umfpack_numeric!(res) end lufact(A::SparseMatrixCSC{<:Union{Float16,Float32},Ti}) where {Ti<:UMFITypes} = diff --git a/test/ccall.jl b/test/ccall.jl index 1b243b1dba6fd..2f26ba5fae1e1 100644 --- a/test/ccall.jl +++ b/test/ccall.jl @@ -881,13 +881,13 @@ end let A = [1] ccall((:set_c_int, libccalltest), Void, (Cint,), 1) @test ccall((:get_c_int, libccalltest), Cint, ()) == 1 - finalizer(cglobal((:finalizer_cptr, libccalltest), Void), A) + finalizer(A, cglobal((:finalizer_cptr, libccalltest), Void)) finalize(A) @test ccall((:get_c_int, libccalltest), Cint, ()) == -1 end # Pointer finalizer at exit (PR #19911) -let result = read(`$(Base.julia_cmd()) --startup-file=no -e "A = Ref{Cint}(42); finalizer(cglobal((:c_exit_finalizer, \"$libccalltest\"), Void), A)"`, String) +let result = read(`$(Base.julia_cmd()) --startup-file=no -e "A = Ref{Cint}(42); finalizer(A, cglobal((:c_exit_finalizer, \"$libccalltest\"), Void))"`, String) @test result == "c_exit_finalizer: 42, 0" end diff --git a/test/channels.jl b/test/channels.jl index d6ed03a0d8387..c68cce2e88c4b 100644 --- a/test/channels.jl +++ b/test/channels.jl @@ -227,7 +227,7 @@ end # test for yield/wait/event failures -@noinline garbage_finalizer(f) = finalizer(f, "gar" * "bage") +@noinline garbage_finalizer(f) = finalizer("gar" * "bage", f) let t, run = Ref(0) gc_enable(false) # test for finalizers trying to yield leading to failed attempts to context switch diff --git a/test/codegen.jl b/test/codegen.jl index 7664b90d29854..d308ff81aa375 100644 --- a/test/codegen.jl +++ b/test/codegen.jl @@ -227,7 +227,7 @@ let was_gced = false function foo22770() b = Ref(2) - finalizer(x -> was_gced = true, b) + finalizer(b, x -> was_gced = true) y = make_tuple(b) x = y[1] a = Ref(1) diff --git a/test/core.jl b/test/core.jl index 254ccdd38afb8..7f6757923c4d0 100644 --- a/test/core.jl +++ b/test/core.jl @@ -896,7 +896,7 @@ end # finalizers let A = [1] local x = 0 - finalizer(a->(x+=1), A) + finalizer(A, a->(x+=1)) finalize(A) @test x == 1 A = 0 @@ -3594,7 +3594,7 @@ end let obj = Ref(1) finalized = 0 - finalizer((obj) -> (finalized = 1), obj) + finalizer(obj, (obj) -> (finalized = 1)) # obj should be marked for promotion after the second gc and be promoted # after the third GC # GC_CLEAN; age = 0 @@ -3624,10 +3624,10 @@ let obj1 = Ref(1) obj2 = Ref(1) finalized = 0 - finalizer((obj) -> (finalized += 1), obj1) - finalizer((obj) -> (finalized += 1), obj1) - finalizer((obj) -> (finalized += 1; finalize(obj1)), obj2) - finalizer((obj) -> (finalized += 1; finalize(obj1)), obj2) + finalizer(obj1, (obj) -> (finalized += 1)) + finalizer(obj1, (obj) -> (finalized += 1)) + finalizer(obj2, (obj) -> (finalized += 1; finalize(obj1))) + finalizer(obj2, (obj) -> (finalized += 1; finalize(obj1))) finalize(obj2) @test finalized == 4 end @@ -3964,10 +3964,10 @@ end # doesn't keep the object alive. @noinline function create_dead_object13995(finalized) obj = Ref(1) - finalizer((x)->(finalized[1] = true), obj) - finalizer((x)->(finalized[2] = true), obj) - finalizer((x)->(finalized[3] = true), obj) - finalizer((x)->(finalized[4] = true), obj) + finalizer(obj, (x)->(finalized[1] = true)) + finalizer(obj, (x)->(finalized[2] = true)) + finalizer(obj, (x)->(finalized[3] = true)) + finalizer(obj, (x)->(finalized[4] = true)) nothing end # disable GC to make sure no collection/promotion happens diff --git a/test/dict.jl b/test/dict.jl index 7212022e51ea4..13de4f652529d 100644 --- a/test/dict.jl +++ b/test/dict.jl @@ -621,9 +621,9 @@ Dict(1 => rand(2,3), 'c' => "asdf") # just make sure this does not trigger a dep local x = 0 local y = 0 local z = 0 - finalizer(a->(x+=1), A) - finalizer(b->(y+=1), B) - finalizer(c->(z+=1), C) + finalizer(A, a->(x+=1)) + finalizer(B, b->(y+=1)) + finalizer(C, c->(z+=1)) # construction wkd = WeakKeyDict() diff --git a/test/misc.jl b/test/misc.jl index e70a5e8274f2c..e139f155d7358 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -269,7 +269,7 @@ end @noinline function f6597(c) t = @schedule nothing - finalizer(t -> c[] += 1, t) + finalizer(t, t -> c[] += 1) wait(t) @test c[] == 0 wait(t)