diff options
-rw-r--r-- | lib/efl/evas.rb | 35 | ||||
-rw-r--r-- | spec/evas_spec.rb | 12 |
2 files changed, 20 insertions, 27 deletions
diff --git a/lib/efl/evas.rb b/lib/efl/evas.rb index 3ecdf29..cba94ce 100644 --- a/lib/efl/evas.rb +++ b/lib/efl/evas.rb @@ -50,22 +50,21 @@ module Efl @ptr = ( case o when NilClass - FFI::AutoPointer.new Efl::Evas.evas_new, method(:free) - when self.class - o.to_ptr - when FFI::AutoPointer - o + FFI::AutoPointer.new Efl::Evas.evas_new, REvas.method(:release) when FFI::Pointer - FFI::AutoPointer.new o, method(:free) + o else raise ArgumentError.new "wrong argument #{o.class.name}" end ) yield self if block_given? end - def free p=nil - return Efl::Evas.evas_free p unless p.nil? - Efl::Evas.evas_free @ptr + def self.release p + Efl::Evas.evas_free p unless p.nil? + end + def free + @ptr.autorelease=false if @ptr.is_a? FFI::AutoPointer + REvas.release @ptr @ptr=nil end def object_add t @@ -108,23 +107,21 @@ module Efl @ptr = ( case o when NilClass - FFI::AutoPointer.new Efl::Evas.evas_new, method(:free) - when self.class - o.to_ptr - when FFI::AutoPointer - o + FFI::AutoPointer.new Efl::Evas.evas_new, REvasObject.method(:release) when FFI::Pointer - FFI::AutoPointer.new o, method(:free) + o else raise ArgumentError.new "wrong argument #{o.class.name}" end ) yield self if block_given? end - def free p=nil - return Efl::Evas.evas_object_del p unless p.nil? - Efl::Evas.evas_object_del @ptr - @ptr.free + def self.release p + Efl::Evas.evas_object_del p unless p.nil? + end + def free + @ptr.autopointer=false if @ptr.is_a? FFI::AutoPointer + REvasObject.release @ptr @ptr=nil end def geometry_get diff --git a/spec/evas_spec.rb b/spec/evas_spec.rb index 529784a..a4adabb 100644 --- a/spec/evas_spec.rb +++ b/spec/evas_spec.rb @@ -80,19 +80,15 @@ describe Efl::Evas do it "should be able to create and destroy evas" do e1 = Evas::REvas.new e1.address.should_not == 0 - e2 = Evas::REvas.new e1 + e2 = Evas::REvas.new e1.to_ptr e1.address.should == e2.address - e3 = Evas::REvas.new e1.to_ptr - e1.address.should == e3.address - e2.address.should == e3.address (e1==e2).should be_false - (e2==e3).should be_false - (e1==e3).should be_false (e1===e2).should be_true - (e2===e3).should be_true - (e1===e3).should be_true + e1.free e1.free e1.to_ptr.should be_nil + e2.free + e2.free e4 = Evas::REvas.new Evas.evas_new e4.address.should_not == 0 e5 = e4.dup |