diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2011-05-02 23:02:45 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2011-05-02 23:02:45 +0200 |
commit | 15fe513c7237ce4d0ad7b34d34c922a47a4a9811 (patch) | |
tree | 74888a182ff8a5b832defeb143d40d428769cddc /lib/efl | |
parent | f502b8aabf430d2f630bc7c8ceeeac578bc3acb5 (diff) | |
download | ffi-efl-15fe513c7237ce4d0ad7b34d34c922a47a4a9811.zip ffi-efl-15fe513c7237ce4d0ad7b34d34c922a47a4a9811.tar.gz |
eina_hash : remove Hash#from_eina_hash, cleanup REinaHash#initialize and FFI::Autopointer usage, update specs
Diffstat (limited to 'lib/efl')
-rw-r--r-- | lib/efl/eina_hash.rb | 33 |
1 files changed, 10 insertions, 23 deletions
diff --git a/lib/efl/eina_hash.rb b/lib/efl/eina_hash.rb index 9aa8808..59d99e2 100644 --- a/lib/efl/eina_hash.rb +++ b/lib/efl/eina_hash.rb @@ -3,17 +3,6 @@ # require 'efl/ffi/eina_hash' # -class Hash - def self.from_eina_hash o - if o.is_a? Efl::EinaHash::REinaHash - o.to_h - elsif o.is_a? FFI::Pointer - Efl::EinaHash::REinaHash.new(o).to_h - else - raise ArgumentError.new " wrong argument #{o.class.name}" - end - end -end module Efl module EinaHash # @@ -26,27 +15,25 @@ module Efl @ptr = ( case o when NilClass - FFI::AutoPointer.new cstr.call, method(:free) - when self.class - o.to_ptr - when FFI::AutoPointer - o + FFI::AutoPointer.new cstr.call, REinaHash.method(:release) when FFI::Pointer - FFI::AutoPointer.new ( o==FFI::Pointer::NULL ? cstr.call : o ), method(:free) + FFI::AutoPointer.new ( o==FFI::Pointer::NULL ? cstr.call : o ), REinaHash.method(:release) when Hash ptr = cstr.call o.each do |k,v| Efl::EinaHash.eina_hash_add ptr, k, v end - FFI::AutoPointer.new ptr, method(:free) + FFI::AutoPointer.new ptr, REinaHash.method(:release) else raise ArgumentError.new "wrong argument #{o.class.name}" end ) end - def free p=nil - return Efl::EinaHash.eina_hash_free p unless p.nil? - Efl::EinaHash.eina_hash_free @ptr - @ptr.free - @ptr = nil + def self.release p + Efl::EinaHash.eina_hash_free p + end + def del + @ptr.autorelease=false + EinaHash.release @ptr + @ptr=nil end def each data=FFI::Pointer::NULL, &block return if not block_given? |