diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2011-05-13 07:09:56 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2011-05-13 07:09:56 +0200 |
commit | a33f6f851bd57b0dde4a8119981e10bea9af25e5 (patch) | |
tree | 0c28800556521f5f110bbcedfed1e6e4563ea233 | |
parent | d5bc890cabde613368dde50a3953df6c909a9d0c (diff) | |
download | ffi-efl-a33f6f851bd57b0dde4a8119981e10bea9af25e5.zip ffi-efl-a33f6f851bd57b0dde4a8119981e10bea9af25e5.tar.gz |
bugfix ecore_getopt store :string
-rw-r--r-- | lib/efl/ecore_getopt.rb | 12 | ||||
-rw-r--r-- | spec/ecore_getopt_spec.rb | 22 |
2 files changed, 21 insertions, 13 deletions
diff --git a/lib/efl/ecore_getopt.rb b/lib/efl/ecore_getopt.rb index dfe9275..75aa888 100644 --- a/lib/efl/ecore_getopt.rb +++ b/lib/efl/ecore_getopt.rb @@ -118,7 +118,7 @@ module Efl # @refs = [] # to prevent FFI::MemoryPointer.from_string from beeing GC'ed end def p_from_string r - return r if r==FFI::Pointer::NULL + return FFI::Pointer::NULL if r.nil? FFI::MemoryPointer.from_string r end private :p_from_string @@ -138,6 +138,10 @@ module Efl p = FFI::MemoryPointer.new :pointer p.write_pointer FFI::Pointer::NULL r = @values[skey] = [ ptype, p ] + when :string + p = FFI::MemoryPointer.new :pointer + p.write_pointer FFI::Pointer::NULL + r = @values[skey] = [ ptype, p ] else p = FFI::MemoryPointer.new ptype p.send 'write_'+ptype.to_s, val unless val.nil? @@ -157,6 +161,9 @@ module Efl when :choice p = ptr.read_pointer ( p==FFI::Pointer::NULL ? nil : p.read_string ) + when :string + p = ptr.read_pointer + (p==FFI::Pointer::NULL ? nil : p.read_string ) when :pointer p = ptr.read_pointer ( p==FFI::Pointer::NULL ? nil : p ) @@ -198,7 +205,7 @@ module Efl st = d[:action_param][:store] st[:type] = v[0] st[:arg_req] = v[1] - st[:def][v[2]] = (v[2]==:str ? p_from_string(v[3]) : v[3] ) unless v[3].nil? + st[:def][v[2]] = (v[2]==:strv ? p_from_string(v[3]) : v[3] ) unless v[3].nil? when :store_const d[:action_param][:store_const] = v when :choices @@ -212,6 +219,7 @@ module Efl @ecore_values_st = Native::EcoreGetoptValue.new FFI::MemoryPointer.new Native::EcoreGetoptValue, @values_order.length, false @values_order.each_with_index do |k,i| vtype, vpointer, *sub_type = @values[k] + vpointer.write_pointer @ecore_getopt_st.desc_ptr(i)[:action_param][:store][:def][:strv] if vtype==:string etype, vfield, pfield = @types[vtype] @ecore_values_st.value_ptr(i)[pfield] = vpointer end diff --git a/spec/ecore_getopt_spec.rb b/spec/ecore_getopt_spec.rb index 3eb38b6..0e2c93a 100644 --- a/spec/ecore_getopt_spec.rb +++ b/spec/ecore_getopt_spec.rb @@ -40,7 +40,7 @@ describe Efl::EcoreGetopt do @p.help 'H', 'help' @p.store 'i', 'int', 'store an integer', :int, 2 @p.store_meta 'd', 'double', 'store an double+meta', @meta1, :double, 3.1415926 - @p.store_def 's', 'short', 'store an short+default', :short, 9 + @p.store_def 's', 'string', 'store an string+default', :string, "default" @p.store_full 'l', 'long', 'store a long+full', @meta2, :ecore_getopt_desc_arg_requirement_yes, :long, 666 @p.store_const 'c', 'const', 'store a constant', -666, 123456 @p.store_true 't', 'true', 'store true' @@ -55,9 +55,9 @@ describe Efl::EcoreGetopt do end # describe "license copyright version help" do -# it "DEBUG" do -# puts @p.debug -# end + it "DEBUG" do + puts @p.debug + end it "should handle -L" do args = @p.parse ["My lovely prog name","-L"] @p['quit'].should == 1 @@ -103,9 +103,9 @@ describe Efl::EcoreGetopt do @p['d'].should == 6.66 end it "should handle -s" do - @p['s'].should == 9 - args = @p.parse ["progname","-s 125"] - @p['s'].should == 125 + @p['s'].should == 'default' + args = @p.parse ["progname","-sset"] + @p['s'].should == 'set' end it "should handle -l" do @p['l'].should == 666 @@ -163,10 +163,10 @@ describe Efl::EcoreGetopt do args = @p.parse ["progname","--double=6.66"] @p['d'].should == 6.66 end - it "should handle --short" do - @p['s'].should == 9 - args = @p.parse ["progname","--short=125"] - @p['s'].should == 125 + it "should handle --string" do + @p['s'].should == 'default' + args = @p.parse ["progname","--string=set"] + @p['s'].should == 'set' end it "should handle --long" do @p['l'].should == 666 |