Skip to content

Commit b732fc8

Browse files
committed
change finalizer argument order to allow for do finalizer functions
1 parent 9e6ec34 commit b732fc8

File tree

19 files changed

+46
-40
lines changed

19 files changed

+46
-40
lines changed

base/REPL.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ function setup_interface(repl::LineEditREPL; hascolor = repl.hascolor, extra_rep
682682
if !repl.no_history_file
683683
try
684684
f = open(find_hist_file(), true, true, true, false, false)
685-
finalizer(replc, replc->close(f))
685+
finalizer(_->close(f), replc)
686686
hist_from_file(hp, f)
687687
catch e
688688
print_response(repl, e, catch_backtrace(), true, Base.have_color)

base/base.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ const (:) = Colon()
140140
==(w::WeakRef, v) = isequal(w.value, v)
141141
==(w, v::WeakRef) = isequal(w, v.value)
142142

143-
function finalizer(o::ANY, f::Union(Function,Ptr))
144-
if isimmutable(o)
145-
error("objects of type ", typeof(o), " cannot be finalized")
146-
end
143+
finalizer(o::Function, f::Function) = error("invalid finalizer(f::Function, o::Function)")
144+
finalizer(o::Ptr, f::Ptr) = error("invalid finalizer(f::Ptr, o::Ptr)")
145+
finalizer(f::Union(Function,Ptr), o::ANY) = begin
146+
isimmutable(o) && error("objects of type ", typeof(o), " cannot be finalized")
147147
ccall(:jl_gc_add_finalizer, Void, (Any,Any), o, f)
148148
end
149149

base/base64.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Base64Pipe <: IO
2121

2222
function Base64Pipe(io::IO)
2323
b = new(io,0,0,0)
24-
finalizer(b, close)
24+
finalizer(close, b)
2525
return b
2626
end
2727
end

base/deprecated.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,9 @@ end
205205
@deprecate itrunc{T<:Integer}(::Type{T}, n::Integer) (n % T)
206206

207207
@deprecate oftype{T}(::Type{T},c) convert(T,c)
208+
209+
function finalizer(o::Any, f::Union(Function,Ptr))
210+
depwarn("finalizer(o::Any, f::Union(Function,Ptr)) is deprecated, " *
211+
"use finalizer(f::Union(Function,Ptr), o::Any) instead", :finalizer)
212+
finalizer(f, o)
213+
end

base/dict.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ function add_weak_key(t::Dict, k, v)
717717
# TODO: it might be better to avoid the finalizer, allow
718718
# wiped WeakRefs to remain in the table, and delete them as
719719
# they are discovered by getindex and setindex!.
720-
finalizer(k, t.deleter)
720+
finalizer(t.deleter, k)
721721
return t
722722
end
723723

@@ -731,7 +731,7 @@ end
731731

732732
function add_weak_value(t::Dict, k, v)
733733
t[k] = WeakRef(v)
734-
finalizer(v, x->weak_value_delete!(t, k, x))
734+
finalizer(x->weak_value_delete!(t, k, x), v)
735735
return t
736736
end
737737

base/fftw.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ type Plan{T<:fftwNumber}
222222
ialign::Int32 # alignment mod 16 of input
223223
function Plan(plan::Ptr{Void}, sz::Dims, istride::Dims, ialign::Int32)
224224
p = new(plan,sz,istride,ialign)
225-
finalizer(p, p -> destroy_plan(T, p.plan))
225+
finalizer(p -> destroy_plan(T, p.plan), p)
226226
return p
227227
end
228228
end

base/gmp.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type BigInt <: Integer
2525
function BigInt()
2626
b = new(zero(Cint), zero(Cint), C_NULL)
2727
ccall((:__gmpz_init,:libgmp), Void, (Ptr{BigInt},), &b)
28-
finalizer(b, _gmp_clear_func)
28+
finalizer(_gmp_clear_func, b)
2929
return b
3030
end
3131
end

base/iostream.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function IOStream(name::String, finalize::Bool)
1616
buf = zeros(Uint8,sizeof_ios_t)
1717
x = IOStream(name, buf)
1818
if finalize
19-
finalizer(x, close)
19+
finalizer(close, x)
2020
end
2121
return x
2222
end

base/linalg/umfpack.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function lufact{Tv<:UMFVTypes,Ti<:UMFITypes}(S::SparseMatrixCSC{Tv,Ti})
114114
zerobased ? copy(S.colptr) : decrement(S.colptr),
115115
zerobased ? copy(S.rowval) : decrement(S.rowval),
116116
copy(S.nzval))
117-
finalizer(res, umfpack_free_symbolic)
117+
finalizer(umfpack_free_symbolic, res)
118118
umfpack_numeric!(res)
119119
end
120120

@@ -126,7 +126,7 @@ function lufact!{Tv<:UMFVTypes,Ti<:UMFITypes}(S::SparseMatrixCSC{Tv,Ti})
126126
zerobased ? S.colptr : decrement!(S.colptr),
127127
zerobased ? S.rowval : decrement!(S.rowval),
128128
S.nzval)
129-
finalizer(res, umfpack_free_symbolic)
129+
finalizer(umfpack_free_symbolic, res)
130130
umfpack_numeric!(res)
131131
end
132132

base/mmap.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function mmap_array{T,N}(::Type{T}, dims::NTuple{N,Integer}, s::IO, offset::File
110110
pmap, delta = mmap(len, prot, flags, fd(s), offset)
111111
end
112112
A = pointer_to_array(convert(Ptr{T}, uint(pmap)+delta), dims)
113-
finalizer(A,x->munmap(pmap,len+delta))
113+
finalizer(x->munmap(pmap,len+delta), A)
114114
return A
115115
end
116116

@@ -150,7 +150,7 @@ function mmap_array{T,N}(::Type{T}, dims::NTuple{N,Integer}, s::IO, offset::File
150150
error("could not create mapping view: $(FormatMessage())")
151151
end
152152
A = pointer_to_array(convert(Ptr{T}, viewhandle+offset-offset_page), dims)
153-
finalizer(A, x->munmap(viewhandle, mmaphandle))
153+
finalizer(x->munmap(viewhandle, mmaphandle), A)
154154
return A
155155
end
156156

0 commit comments

Comments
 (0)