From a58d00af40659f7fff02d24e31c5e32b9abbfdcf Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Fri, 1 Dec 2017 12:49:15 -0800 Subject: [PATCH] Revert "Add function-first finalizers (#416)" This reverts commit 5ab47d1e9a3745fd73145cd59756b89589a7533c due to method ambiguities. add at-compat for finalizer instead at-compat finalizer --- README.md | 4 ++-- src/Compat.jl | 13 +++++-------- test/runtests.jl | 3 ++- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 60418ed75..a873cce33 100644 --- a/README.md +++ b/README.md @@ -192,8 +192,8 @@ Currently, the `@compat` macro supports the following syntaxes: * `Uninitialized` and `uninitialized` with corresponding `Array` constructors ([#24652]). -* `finalizer` accepts the finalizer to run as the first argument and the object to be finalized - as the second ([#24605]) +* `@compat finalizer(func, obj)` with the finalizer to run as the first argument and the object to be finalized + as the second ([#24605]). ## Renaming diff --git a/src/Compat.jl b/src/Compat.jl index 220409f13..c580a057a 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -100,6 +100,11 @@ function _compat(ex::Expr) end end end + if VERSION < v"0.7.0-DEV.2562" + if ex.head == :call && ex.args[1] == :finalizer + ex.args[2], ex.args[3] = ex.args[3], ex.args[2] + end + end return Expr(ex.head, map(_compat, ex.args)...) end @@ -825,14 +830,6 @@ end export Uninitialized, uninitialized 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 diff --git a/test/runtests.jl b/test/runtests.jl index b842ec337..b98ded9df 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -916,10 +916,11 @@ module Test24361 using Compat.Test @test String(Compat.Base64.base64decode("SGVsbG8h")) == "Hello!" end + # 0.7 let A = [1] local x = 0 - finalizer(a->(x+=1), A) + @compat finalizer(a->(x+=1), A) finalize(A) @test x == 1 A = 0