summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2011-05-02 16:40:52 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2011-05-02 16:40:52 +0200
commitf7d729b57551913941d93aee88c8f34ecfd10dd0 (patch)
tree46ed0fd6c77f7fd35e11ee2b670ebecfeb734df1
parente430180e652a77f05c6ca041d64d05297f14ee59 (diff)
downloadffi-efl-f7d729b57551913941d93aee88c8f34ecfd10dd0.zip
ffi-efl-f7d729b57551913941d93aee88c8f34ecfd10dd0.tar.gz
REetFile use AutoPointer
-rw-r--r--lib/efl/eet.rb26
-rw-r--r--spec/eet_spec.rb2
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