From f7d729b57551913941d93aee88c8f34ecfd10dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 2 May 2011 16:40:52 +0200 Subject: REetFile use AutoPointer --- lib/efl/eet.rb | 26 ++++++++++++++++---------- spec/eet_spec.rb | 2 +- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/efl/eet.rb b/lib/efl/eet.rb index f66ede7..7a1ca5b 100644 --- a/lib/efl/eet.rb +++ b/lib/efl/eet.rb @@ -17,16 +17,22 @@ module Efl end private :initialize # - def self.open path, mode=:eet_file_mode_read, &blk - if blk - f = Efl::Eet.eet_open path, mode - raise Exception.new "Unable to open file #{path}" if f.nil? - yield REetFile.new f - Efl::Eet.eet_close f - else - f = Efl::Eet.eet_open path, mode - return REetFile.new f unless f.nil? - end + def self.open path, mode=:eet_file_mode_read + p = Efl::Eet.eet_open path, mode + raise Exception.new "Unable to open file #{path}" if p.nil? + o = REetFile.new FFI::AutoPointer.new p, REetFile.method(:release) + return o if not block_given? + yield o + o.close + nil + end + def self.release p + Efl::Eet.eet_close f + end + def close + @ptr.autorelease=false + Efl::Eet.eet_close @ptr + @ptr = nil end # def write key, data, compress=false diff --git a/spec/eet_spec.rb b/spec/eet_spec.rb index 4d7059c..a0c195c 100644 --- a/spec/eet_spec.rb +++ b/spec/eet_spec.rb @@ -80,7 +80,7 @@ describe Efl::Eet do f = REetFile.open FP, :eet_file_mode_read_write f.write 'configg', 'test key' f.read('configg').should == 'test key' - f.close +# f.close #leave it to FFI::AutoPointer end # it "should write in block" do -- cgit v1.1-2-g2b99