LoginSignup
0
0

More than 5 years have passed since last update.

Julia v1.0.0でfinalizerの引数順序が変更された

Posted at

Juliaのmutable structのディストラクタとしてfinalizerを使用しますが、v1.0.0からfinalizerの引数順序が変更されました。

v1.0.0での書き方

finalizerの第一引数がfunction、第二引数がfinalize対象のオブジェクトに変更されました。
ちょうど変更前と逆の順序になります。
以下の例ではdo syntaxを使って引数の順序を変えています。


mutable struct Synth
    synth_ptr::Ptr{Cvoid}
    setting_ptr::Ptr{Cvoid}
    function Synth()
        synth = new(C_NULL, C_NULL)
        finalizer(synth) do synth
          # ディストラクタの処理
        end
        synth
    end
end

v1.0.0以前での書き方

mutable struct Synth
    synth_ptr::Ptr{Cvoid}
    setting_ptr::Ptr{Cvoid}
    function Synth()
        synth = new(C_NULL, C_NULL)
        finalizer(synth,
            function(synth::Synth)
              # ディストラクタの処理
            end)
        synth
    end
end

投入コミット

どうでもいい話

v1.0.0の話をする時、v0.7.0じゃないの?と無限に揚げ足を取れるわけですが、どっちで言うのがいいんですかね…。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0