Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change finalizer argument order to allow for do-block syntax #12578

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 3 additions & 1 deletion base/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion base/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions base/base64.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -173,7 +173,7 @@ type Base64DecodePipe <: IO

function Base64DecodePipe(io::IO)
b = new(io,[],[])
finalizer(b, close)
finalizer(close,b)
return b
end
end
Expand Down
9 changes: 9 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion base/docs/helpdb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
```
Expand Down
2 changes: 1 addition & 1 deletion base/fft/FFTW.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion base/iostream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions base/mmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion base/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions base/multi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions base/poll.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type FileMonitor
Libc.free(handle)
throw(UVError("PollingFileWatcher", err))
end
finalizer(this, uvfinalize)
finalizer(uvfinalize,this)
this
end
end
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion base/process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions base/regex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions base/socket.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Loading