From cec49f398e53b3d0739c0b4b2dcbf7ecc41935ef Mon Sep 17 00:00:00 2001 From: Jake Bolewski Date: Tue, 11 Aug 2015 21:01:04 -0400 Subject: [PATCH] change finalizer argument order to allow for do-block syntax closes #6454 --- base/REPL.jl | 4 +++- base/base.jl | 2 +- base/base64.jl | 4 ++-- base/deprecated.jl | 9 ++++++++ base/dict.jl | 2 +- base/docs/helpdb.jl | 2 +- base/fft/FFTW.jl | 2 +- base/gmp.jl | 2 +- base/iostream.jl | 2 +- base/mmap.jl | 8 ++++--- base/mpfr.jl | 2 +- base/multi.jl | 9 ++++++-- base/poll.jl | 8 +++---- base/process.jl | 2 +- base/regex.jl | 8 +++---- base/socket.jl | 6 ++--- base/sparse/cholmod.jl | 52 +++++++++++++++++++++--------------------- base/sparse/spqr.jl | 8 +++---- base/sparse/umfpack.jl | 2 +- base/stream.jl | 11 +++++---- test/core.jl | 4 +++- 21 files changed, 85 insertions(+), 64 deletions(-) diff --git a/base/REPL.jl b/base/REPL.jl index a3fdb2a20f39d..fb8524a0131c5 100644 --- a/base/REPL.jl +++ b/base/REPL.jl @@ -738,7 +738,9 @@ function setup_interface(repl::LineEditREPL; hascolor = repl.hascolor, extra_rep if repl.history_file try f = open(find_hist_file(), true, true, true, false, false) - finalizer(replc, replc->close(f)) + finalizer(replc) do _ + close(f) + end hist_from_file(hp, f) catch e print_response(repl, e, catch_backtrace(), true, Base.have_color) diff --git a/base/base.jl b/base/base.jl index ba6105d8a9166..b78e285bf9ce7 100644 --- a/base/base.jl +++ b/base/base.jl @@ -66,7 +66,7 @@ ccall(:jl_get_system_hooks, Void, ()) ==(w::WeakRef, v) = isequal(w.value, v) ==(w, v::WeakRef) = isequal(w, v.value) -function finalizer(o::ANY, f::Union{Function,Ptr}) +function finalizer(f::Union{Function,Ptr}, o::ANY) if isimmutable(o) error("objects of type ", typeof(o), " cannot be finalized") end diff --git a/base/base64.jl b/base/base64.jl index f91282a172d50..3dc794a0b553a 100644 --- a/base/base64.jl +++ b/base/base64.jl @@ -23,7 +23,7 @@ type Base64EncodePipe <: IO function Base64EncodePipe(io::IO) b = new(io,0,0,0) - finalizer(b, close) + finalizer(close,b) return b end end @@ -173,7 +173,7 @@ type Base64DecodePipe <: IO function Base64DecodePipe(io::IO) b = new(io,[],[]) - finalizer(b, close) + finalizer(close,b) return b end end diff --git a/base/deprecated.jl b/base/deprecated.jl index 8d5b220ef0f82..545a4eab0d21e 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -766,3 +766,12 @@ end const FloatingPoint = AbstractFloat export FloatingPoint + +finalizer(::Union{Function,Ptr}, ::Union{Function,Ptr}) = + error("finalizer(f1::Union(Function,Ptr), f2::Union(Function,Ptr)) is ambiguous due to deprecation") + +function finalizer(o::ANY, f::Union{Function,Ptr}) + depwarn(string("finalizer(o::ANY, f::Union(Function,Ptr)) is deprecated, ", + "use finalizer(f::Union(Function,Ptr), o::ANY) instead"), :finalizer) + finalizer(f, o) +end diff --git a/base/dict.jl b/base/dict.jl index d19d9ed448a05..54558205aa5c5 100644 --- a/base/dict.jl +++ b/base/dict.jl @@ -796,7 +796,7 @@ function setindex!{K}(wkh::WeakKeyDict{K}, v, key) # TODO: it might be better to avoid the finalizer, allow # wiped WeakRefs to remain in the table, and delete them as # they are discovered by getindex and setindex!. - finalizer(k, wkh.deleter) + finalizer(wkh.deleter,k) return t end diff --git a/base/docs/helpdb.jl b/base/docs/helpdb.jl index b2b629b18bcec..13f8bbce8d5a6 100644 --- a/base/docs/helpdb.jl +++ b/base/docs/helpdb.jl @@ -11436,7 +11436,7 @@ issubtype doc""" ```rst :: - finalizer(x, function) + finalizer(function,x) Register a function ``f(x)`` to be called when there are no program-accessible references to ``x``. The behavior of this function is unpredictable if ``x`` is of a bits type. ``` diff --git a/base/fft/FFTW.jl b/base/fft/FFTW.jl index dce63807cbf37..3042c2fdd72be 100644 --- a/base/fft/FFTW.jl +++ b/base/fft/FFTW.jl @@ -215,7 +215,7 @@ for P in (:cFFTWPlan, :rFFTWPlan, :r2rFFTWPlan) # complex, r2c/c2r, and r2r X::StridedArray{T, N}, Y::StridedArray) p = new(plan, size(X), size(Y), strides(X), strides(Y), alignment_of(X), alignment_of(Y), flags, R) - finalizer(p, destroy_plan) + finalizer(destroy_plan,p) p end end diff --git a/base/gmp.jl b/base/gmp.jl index 61cac9d78f7c7..2e7741a1bf703 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -44,7 +44,7 @@ type BigInt <: Integer function BigInt() b = new(zero(Cint), zero(Cint), C_NULL) ccall((:__gmpz_init,:libgmp), Void, (Ptr{BigInt},), &b) - finalizer(b, _gmp_clear_func) + finalizer(_gmp_clear_func,b) return b end end diff --git a/base/iostream.jl b/base/iostream.jl index 010e6865f9e98..6d810710ff4be 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(x, close) + finalizer(close,x) end return x end diff --git a/base/mmap.jl b/base/mmap.jl index b1de73dec7224..37d66bc5016de 100644 --- a/base/mmap.jl +++ b/base/mmap.jl @@ -134,12 +134,14 @@ function mmap{T,N}(io::IO, end # @windows_only # convert mmapped region to Julia Array at `ptr + (offset - offset_page)` since file was mapped at offset_page A = pointer_to_array(convert(Ptr{T}, UInt(ptr) + UInt(offset - offset_page)), dims) - @unix_only finalizer(A, x -> systemerror("munmap", ccall(:munmap,Cint,(Ptr{Void},Int),ptr,mmaplen) != 0)) - @windows_only finalizer(A, x -> begin + @unix_only finalizer(A) do _ + systemerror("munmap", ccall(:munmap,Cint,(Ptr{Void},Int),ptr,mmaplen) != 0) + end + @windows_only finalizer(A) do _ status = ccall(:UnmapViewOfFile, stdcall, Cint, (Ptr{Void},), ptr)!=0 status |= ccall(:CloseHandle, stdcall, Cint, (Ptr{Void},), handle)!=0 status || error("could not unmap view: $(Libc.FormatMessage())") - end) + end return A end diff --git a/base/mpfr.jl b/base/mpfr.jl index 5ac9dcf965300..89a6d3e3c84a7 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -49,7 +49,7 @@ type BigFloat <: AbstractFloat N = get_bigfloat_precision() z = new(zero(Clong), zero(Cint), zero(Clong), C_NULL) ccall((:mpfr_init2,:libmpfr), Void, (Ptr{BigFloat}, Clong), &z, N) - finalizer(z, Base.GMP._mpfr_clear_func) + finalizer(Base.GMP._mpfr_clear_func,z) return z end # Not recommended for general use diff --git a/base/multi.jl b/base/multi.jl index 7a24852aa8d66..3ae66e547fad9 100644 --- a/base/multi.jl +++ b/base/multi.jl @@ -473,7 +473,7 @@ type RemoteRef{RemoteStore} return found end client_refs[r] = true - finalizer(r, send_del_client) + finalizer(send_del_client,r) r end end @@ -1198,8 +1198,13 @@ function create_worker(manager, wconfig) (r_s, w_s) = connect(manager, w.id, wconfig) w = Worker(w.id, r_s, w_s, manager, wconfig) + # install a finalizer to perform cleanup if necessary - finalizer(w, (w)->if myid() == 1 manage(w.manager, w.id, w.config, :finalize) end) + finalizer(w) do w + if myid() == 1 + manage(w.manager, w.id, w.config, :finalize) + end + end # set when the new worker has finshed connections with all other workers ntfy_oid = next_rrid_tuple() diff --git a/base/poll.jl b/base/poll.jl index c7bf9f14d3d18..1a3077391a63e 100644 --- a/base/poll.jl +++ b/base/poll.jl @@ -47,7 +47,7 @@ type FileMonitor Libc.free(handle) throw(UVError("PollingFileWatcher", err)) end - finalizer(this, uvfinalize) + finalizer(uvfinalize,this) this end end @@ -69,7 +69,7 @@ type PollingFileWatcher <: UVPollingWatcher Libc.free(handle) throw(UVError("PollingFileWatcher", err)) end - finalizer(this, uvfinalize) + finalizer(uvfinalize,this) return this end end @@ -156,12 +156,12 @@ type FDWatcher <: UVPollingWatcher writable::Bool function FDWatcher(fd::RawFD, readable::Bool, writable::Bool) this = new(_FDWatcher(fd, readable, writable), readable, writable) - finalizer(this, close) + finalizer(close,this) return this end @windows_only function FDWatcher(fd::WindowsRawSocket, readable::Bool, writable::Bool) this = new(_FDWatcher(fd, readable, writable), readable, writable) - finalizer(this, close) + finalizer(close,this) return this end end diff --git a/base/process.jl b/base/process.jl index 2034a3c5971e7..e18f3f7ea883a 100644 --- a/base/process.jl +++ b/base/process.jl @@ -196,7 +196,7 @@ type Process err=DevNull end this = new(cmd, handle, in, out, err, typemin(Int32), typemin(Int32), false, Condition(), false, Condition()) - finalizer(this, uvfinalize) + finalizer(uvfinalize,this) this end end diff --git a/base/regex.jl b/base/regex.jl index ce9e3d958b58c..f9f33b83903d5 100644 --- a/base/regex.jl +++ b/base/regex.jl @@ -29,10 +29,10 @@ type Regex end re = compile(new(pattern, compile_options, match_options, C_NULL, C_NULL, Csize_t[], C_NULL)) - 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) + 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 re end end diff --git a/base/socket.jl b/base/socket.jl index 99ae4eb4b78cb..a95f3d1bb5638 100644 --- a/base/socket.jl +++ b/base/socket.jl @@ -281,7 +281,7 @@ end function TCPSocket() this = TCPSocket(Libc.malloc(_sizeof_uv_tcp)) associate_julia_struct(this.handle,this) - finalizer(this,uvfinalize) + finalizer(uvfinalize,this) err = ccall(:uv_tcp_init,Cint,(Ptr{Void},Ptr{Void}), eventloop(),this.handle) if err != 0 @@ -312,7 +312,7 @@ end function TCPServer() this = TCPServer(Libc.malloc(_sizeof_uv_tcp)) associate_julia_struct(this.handle, this) - finalizer(this,uvfinalize) + finalizer(uvfinalize,this) err = ccall(:uv_tcp_init,Cint,(Ptr{Void},Ptr{Void}), eventloop(),this.handle) if err != 0 @@ -377,7 +377,7 @@ function UDPSocket() associate_julia_struct(this.handle, this) err = ccall(:uv_udp_init,Cint,(Ptr{Void},Ptr{Void}), eventloop(),this.handle) - finalizer(this, uvfinalize) + finalizer(uvfinalize,this) if err != 0 #TODO: this codepath is not currently tested Libc.free(this.handle) diff --git a/base/sparse/cholmod.jl b/base/sparse/cholmod.jl index cc47734a91137..82801112190c3 100644 --- a/base/sparse/cholmod.jl +++ b/base/sparse/cholmod.jl @@ -345,14 +345,14 @@ function allocate_dense(nrow::Integer, ncol::Integer, d::Integer, ::Type{Float64 d = Dense(ccall((:cholmod_l_allocate_dense, :libcholmod), Ptr{C_Dense{Float64}}, (Csize_t, Csize_t, Csize_t, Cint, Ptr{Void}), nrow, ncol, d, REAL, common())) - finalizer(d, free!) + finalizer(free!,d) d end function allocate_dense(nrow::Integer, ncol::Integer, d::Integer, ::Type{Complex{Float64}}) d = Dense(ccall((:cholmod_l_allocate_dense, :libcholmod), Ptr{C_Dense{Complex{Float64}}}, (Csize_t, Csize_t, Csize_t, Cint, Ptr{Void}), nrow, ncol, d, COMPLEX, common())) - finalizer(d, free!) + finalizer(free!,d) d end @@ -362,7 +362,7 @@ function zeros{T<:VTypes}(m::Integer, n::Integer, ::Type{T}) d = Dense(ccall((:cholmod_l_zeros, :libcholmod), Ptr{C_Dense{T}}, (Csize_t, Csize_t, Cint, Ptr{UInt8}), m, n, xtyp(T), common())) - finalizer(d, free!) + finalizer(free!,d) d end zeros(m::Integer, n::Integer) = zeros(m, n, Float64) @@ -371,7 +371,7 @@ function ones{T<:VTypes}(m::Integer, n::Integer, ::Type{T}) d = Dense(ccall((:cholmod_l_ones, :libcholmod), Ptr{C_Dense{T}}, (Csize_t, Csize_t, Cint, Ptr{UInt8}), m, n, xtyp(T), common())) - finalizer(d, free!) + finalizer(free!,d) d end ones(m::Integer, n::Integer) = ones(m, n, Float64) @@ -380,7 +380,7 @@ function eye{T<:VTypes}(m::Integer, n::Integer, ::Type{T}) d = Dense(ccall((:cholmod_l_eye, :libcholmod), Ptr{C_Dense{T}}, (Csize_t, Csize_t, Cint, Ptr{UInt8}), m, n, xtyp(T), common())) - finalizer(d, free!) + finalizer(free!,d) d end eye(m::Integer, n::Integer) = eye(m, n, Float64) @@ -390,7 +390,7 @@ function copy_dense{Tv<:VTypes}(A::Dense{Tv}) d = Dense(ccall((:cholmod_l_copy_dense, :libcholmod), Ptr{C_Dense{Tv}}, (Ptr{C_Dense{Tv}}, Ptr{UInt8}), A.p, common())) - finalizer(d, free!) + finalizer(free!,d) d end @@ -424,7 +424,7 @@ function allocate_sparse(nrow::Integer, ncol::Integer, nzmax::Integer, sorted::B Cint, Cint, Cint, Ptr{Void}), nrow, ncol, nzmax, sorted, packed, stype, REAL, common())) - finalizer(s, free!) + finalizer(free!,s) s end function allocate_sparse(nrow::Integer, ncol::Integer, nzmax::Integer, sorted::Bool, packed::Bool, stype::Integer, ::Type{Complex{Float64}}) @@ -434,7 +434,7 @@ function allocate_sparse(nrow::Integer, ncol::Integer, nzmax::Integer, sorted::B Cint, Cint, Cint, Ptr{Void}), nrow, ncol, nzmax, sorted, packed, stype, COMPLEX, common())) - finalizer(s, free!) + finalizer(free!,s) s end function free_sparse!{Tv<:VTypes}(ptr::Ptr{C_Sparse{Tv}}) @@ -461,7 +461,7 @@ function aat{Tv<:VRealTypes}(A::Sparse{Tv}, fset::Vector{SuiteSparse_long}, mode Ptr{C_Sparse{Tv}}, (Ptr{C_Sparse{Tv}}, Ptr{SuiteSparse_long}, Csize_t, Cint, Ptr{UInt8}), A.p, fset, length(fset), mode, common())) - finalizer(s, free!) + finalizer(free!,s) s end @@ -470,7 +470,7 @@ function sparse_to_dense{Tv<:VTypes}(A::Sparse{Tv}) Ptr{C_Dense{Tv}}, (Ptr{C_Sparse{Tv}}, Ptr{UInt8}), A.p, common())) - finalizer(d, free!) + finalizer(free!,d) d end function dense_to_sparse{Tv<:VTypes}(D::Dense{Tv}, ::Type{SuiteSparse_long}) @@ -478,7 +478,7 @@ function dense_to_sparse{Tv<:VTypes}(D::Dense{Tv}, ::Type{SuiteSparse_long}) Ptr{C_Sparse{Tv}}, (Ptr{C_Dense{Tv}}, Cint, Ptr{UInt8}), D.p, true, common())) - finalizer(s, free!) + finalizer(free!,s) s end @@ -489,7 +489,7 @@ function factor_to_sparse!{Tv<:VTypes}(F::Factor{Tv}) Ptr{C_Sparse{Tv}}, (Ptr{C_Factor{Tv}}, Ptr{UInt8}), F.p, common())) - finalizer(s, free!) + finalizer(free!,s) s end @@ -530,7 +530,7 @@ function speye{Tv<:VTypes}(m::Integer, n::Integer, ::Type{Tv}) Ptr{C_Sparse{Tv}}, (Csize_t, Csize_t, Cint, Ptr{UInt8}), m, n, xtyp(Tv), common())) - finalizer(s, free!) + finalizer(free!,s) s end @@ -539,7 +539,7 @@ function spzeros{Tv<:VTypes}(m::Integer, n::Integer, nzmax::Integer, ::Type{Tv}) Ptr{C_Sparse{Tv}}, (Csize_t, Csize_t, Csize_t, Cint, Ptr{UInt8}), m, n, nzmax, xtyp(Tv), common())) - finalizer(s, free!) + finalizer(free!,s) s end @@ -548,7 +548,7 @@ function transpose_{Tv<:VTypes}(A::Sparse{Tv}, values::Integer) Ptr{C_Sparse{Tv}}, (Ptr{C_Sparse{Tv}}, Cint, Ptr{UInt8}), A.p, values, common())) - finalizer(s, free!) + finalizer(free!,s) s end @@ -557,7 +557,7 @@ function copy_factor{Tv<:VTypes}(F::Factor{Tv}) Ptr{C_Factor{Tv}}, (Ptr{C_Factor{Tv}}, Ptr{UInt8}), F.p, common())) - finalizer(f, free!) + finalizer(free!,f) f end function copy_sparse{Tv<:VTypes}(A::Sparse{Tv}) @@ -565,7 +565,7 @@ function copy_sparse{Tv<:VTypes}(A::Sparse{Tv}) Ptr{C_Sparse{Tv}}, (Ptr{C_Sparse{Tv}}, Ptr{UInt8}), A.p, common())) - finalizer(s, free!) + finalizer(free!,s) s end function copy{Tv<:VRealTypes}(A::Sparse{Tv}, stype::Integer, mode::Integer) @@ -573,7 +573,7 @@ function copy{Tv<:VRealTypes}(A::Sparse{Tv}, stype::Integer, mode::Integer) Ptr{C_Sparse{Tv}}, (Ptr{C_Sparse{Tv}}, Cint, Cint, Ptr{UInt8}), A.p, stype, mode, common())) - finalizer(s, free!) + finalizer(free!,s) s end @@ -608,7 +608,7 @@ function ssmult{Tv<:VRealTypes}(A::Sparse{Tv}, B::Sparse{Tv}, stype::Integer, va Cint, Ptr{UInt8}), A.p, B.p, stype, values, sorted, common())) - finalizer(s, free!) + finalizer(free!,s) s end @@ -626,7 +626,7 @@ function horzcat{Tv<:VRealTypes}(A::Sparse{Tv}, B::Sparse{Tv}, values::Bool) Ptr{C_Sparse{Tv}}, (Ptr{C_Sparse{Tv}}, Ptr{C_Sparse{Tv}}, Cint, Ptr{UInt8}), A.p, B.p, values, common())) - finalizer(s, free!) + finalizer(free!,s) s end @@ -674,7 +674,7 @@ function vertcat{Tv<:VRealTypes}(A::Sparse{Tv}, B::Sparse{Tv}, values::Bool) s = Sparse(ccall((@cholmod_name("vertcat", SuiteSparse_long), :libcholmod), Ptr{C_Sparse{Tv}}, (Ptr{C_Sparse{Tv}}, Ptr{C_Sparse{Tv}}, Cint, Ptr{UInt8}), A.p, B.p, values, common())) - finalizer(s, free!) + finalizer(free!,s) s end @@ -699,7 +699,7 @@ function analyze{Tv<:VTypes}(A::Sparse{Tv}, cmmn::Vector{UInt8}) Ptr{C_Factor{Tv}}, (Ptr{C_Sparse{Tv}}, Ptr{UInt8}), A.p, cmmn)) - finalizer(f, free!) + finalizer(free!,f) f end function analyze_p{Tv<:VTypes}(A::Sparse{Tv}, perm::Vector{SuiteSparse_long}, @@ -709,7 +709,7 @@ function analyze_p{Tv<:VTypes}(A::Sparse{Tv}, perm::Vector{SuiteSparse_long}, Ptr{C_Factor{Tv}}, (Ptr{C_Sparse{Tv}}, Ptr{SuiteSparse_long}, Ptr{SuiteSparse_long}, Csize_t, Ptr{UInt8}), A.p, perm, C_NULL, 0, cmmn)) - finalizer(f, free!) + finalizer(free!,f) f end function factorize!{Tv<:VTypes}(A::Sparse{Tv}, F::Factor{Tv}, cmmn::Vector{UInt8}) @@ -735,7 +735,7 @@ function solve{Tv<:VTypes}(sys::Integer, F::Factor{Tv}, B::Dense{Tv}) d = Dense(ccall((@cholmod_name("solve", SuiteSparse_long),:libcholmod), Ptr{C_Dense{Tv}}, (Cint, Ptr{C_Factor{Tv}}, Ptr{C_Dense{Tv}}, Ptr{UInt8}), sys, F.p, B.p, common())) - finalizer(d, free!) + finalizer(free!,d) d end @@ -747,7 +747,7 @@ function spsolve{Tv<:VTypes}(sys::Integer, F::Factor{Tv}, B::Sparse{Tv}) Ptr{C_Sparse{Tv}}, (Cint, Ptr{C_Factor{Tv}}, Ptr{C_Sparse{Tv}}, Ptr{UInt8}), sys, F.p, B.p, common())) - finalizer(s, free!) + finalizer(free!,s) s end @@ -761,7 +761,7 @@ function read_sparse(file::Libc.FILE, ::Type{SuiteSparse_long}) throw(ArgumentError("sparse matrix construction failed. Check that input file is valid.")) end s = Sparse(ptr) - finalizer(s, free!) + finalizer(free!,s) s end diff --git a/base/sparse/spqr.jl b/base/sparse/spqr.jl index bf9fe5b5365e6..976db05dfec45 100644 --- a/base/sparse/spqr.jl +++ b/base/sparse/spqr.jl @@ -92,7 +92,7 @@ function backslash{Tv<:VTypes}(ordering::Integer, tol::Real, A::Sparse{Tv}, B::D d = Dense(ccall((:SuiteSparseQR_C_backslash, :libspqr), Ptr{C_Dense{Tv}}, (Cint, Cdouble, Ptr{C_Sparse{Tv}}, Ptr{C_Dense{Tv}}, Ptr{Void}), ordering, tol, A.p, B.p, common())) - finalizer(d, free!) + finalizer(free!,d) d end @@ -104,7 +104,7 @@ function factorize{Tv<:VTypes}(ordering::Integer, tol::Real, A::Sparse{Tv}) f = Factorization(size(A)..., ccall((:SuiteSparseQR_C_factorize, :libspqr), Ptr{C_Factorization{Tv}}, (Cint, Cdouble, Ptr{Sparse{Tv}}, Ptr{Void}), ordering, tol, A.p, common())) - finalizer(f, free!) + finalizer(free!,f) f end @@ -119,7 +119,7 @@ function solve{Tv<:VTypes}(system::Integer, QR::Factorization{Tv}, B::Dense{Tv}) d = Dense(ccall((:SuiteSparseQR_C_solve, :libspqr), Ptr{C_Dense{Tv}}, (Cint, Ptr{C_Factorization{Tv}}, Ptr{C_Dense{Tv}}, Ptr{Void}), system, QR.p, B.p, common())) - finalizer(d, free!) + finalizer(free!,d) d end @@ -134,7 +134,7 @@ function qmult{Tv<:VTypes}(method::Integer, QR::Factorization{Tv}, X::Dense{Tv}) d = Dense(ccall((:SuiteSparseQR_C_qmult, :libspqr), Ptr{C_Dense{Tv}}, (Cint, Ptr{C_Factorization{Tv}}, Ptr{C_Dense{Tv}}, Ptr{Void}), method, QR.p, X.p, common())) - finalizer(d, free!) + finalizer(free!,d) d end diff --git a/base/sparse/umfpack.jl b/base/sparse/umfpack.jl index 2a1e17c3628e8..bdf9874addb95 100644 --- a/base/sparse/umfpack.jl +++ b/base/sparse/umfpack.jl @@ -110,7 +110,7 @@ function lufact{Tv<:UMFVTypes,Ti<:UMFITypes}(S::SparseMatrixCSC{Tv,Ti}) zerobased ? copy(S.colptr) : decrement(S.colptr), zerobased ? copy(S.rowval) : decrement(S.rowval), copy(S.nzval)) - finalizer(res, umfpack_free_symbolic) + finalizer(umfpack_free_symbolic,res) umfpack_numeric!(res) end diff --git a/base/stream.jl b/base/stream.jl index e74051e58156a..1cff105a3c3b5 100644 --- a/base/stream.jl +++ b/base/stream.jl @@ -133,7 +133,7 @@ function Pipe() try ret = Pipe(handle) associate_julia_struct(ret.handle,ret) - finalizer(ret,uvfinalize) + finalizer(uvfinalize,ret) return init_pipe!(ret;readable=true) catch Libc.free(handle) @@ -171,7 +171,7 @@ function PipeServer() try ret = PipeServer(handle) associate_julia_struct(ret.handle,ret) - finalizer(ret,uvfinalize) + finalizer(uvfinalize,ret) return init_pipe!(ret;readable=true) catch Libc.free(handle) @@ -215,7 +215,7 @@ function TTY(fd::RawFD; readable::Bool = false) handle = Libc.malloc(_sizeof_uv_tty) ret = TTY(handle) associate_julia_struct(handle,ret) - finalizer(ret,uvfinalize) + finalizer(uvfinalize,ret) # This needs to go after associate_julia_struct so that there # is no garbage in the ->data field uv_error("TTY",ccall(:uv_tty_init,Int32,(Ptr{Void},Ptr{Void},Int32,Int32),eventloop(),handle,fd.fd,readable)) @@ -278,7 +278,7 @@ function init_stdio(handle) ret.status = StatusOpen ret.line_buffered = false associate_julia_struct(ret.handle,ret) - finalizer(ret,uvfinalize) + finalizer(uvfinalize,ret) return ret end end @@ -651,7 +651,8 @@ end function malloc_julia_pipe(x) x.handle = Libc.malloc(_sizeof_uv_named_pipe) associate_julia_struct(x.handle,x) - finalizer(x,uvfinalize) + finalizer(uvfinalize,x) + x end _link_pipe(read_end::Ptr{Void},write_end::Ptr{Void}) = uv_error("pipe_link",ccall(:uv_pipe_link, Int32, (Ptr{Void}, Ptr{Void}), read_end, write_end)) diff --git a/test/core.jl b/test/core.jl index c68e0e2431265..f07684b8b2735 100644 --- a/test/core.jl +++ b/test/core.jl @@ -660,7 +660,9 @@ end # finalizers let A = [1] local x = 0 - finalizer(A, a->(x+=1)) + finalizer(A) do _ + x += 1 + end finalize(A) @test x == 1 A = 0