Skip to content

Commit

Permalink
Add function-first finalizers
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Nov 25, 2017
1 parent 3cd0bc6 commit d777eb0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ Currently, the `@compat` macro supports the following syntaxes:

* Constructors for `Matrix{T}`, `Array{T}`, and `SparseMatrixCSC{T}` from `UniformScaling` ([#24372], [#24657])

* `finalizer` accepts the finalizer to run as the first argument and the object to be finalized
as the second ([#24605])

## Renaming


Expand Down Expand Up @@ -361,4 +364,5 @@ includes this fix. Find the minimum version from there.
[#24282]: https://github.com/JuliaLang/julia/issues/24282
[#24372]: https://github.com/JuliaLang/julia/issues/24372
[#24459]: https://github.com/JuliaLang/julia/issues/24459
[#24605]: https://github.com/JuliaLang/julia/issues/24605
[#24657]: https://github.com/JuliaLang/julia/issues/24657
8 changes: 8 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,14 @@ if VERSION < v"0.7.0-DEV.2543"
(::Type{Array{T}}){T}(s::UniformScaling, m::Integer, n::Integer) = Matrix{T}(s, m, n)
end

if VERSION < v"0.7.0-DEV.2562"
import Base: finalizer
finalizer(f::Function, o) = finalizer(o, f)
finalizer(f::Ptr{Void}, o) = finalizer(o, f)
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)
end

include("deprecated.jl")

end # module Compat
11 changes: 11 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,17 @@ let a = [1 0 0; 0 1 0; 0 0 1]
@test SparseMatrixCSC{Complex128,Int8}(I, 3, 2)::SparseMatrixCSC{Complex128,Int8} == a[:,1:2]
end

# 0.7
let A = [1]
local x = 0
finalizer(a->(x+=1), A)
finalize(A)
@test x == 1
A = 0
gc(); gc()
@test x == 1
end

if VERSION < v"0.6.0"
include("deprecated.jl")
end
Expand Down

0 comments on commit d777eb0

Please sign in to comment.