Permalink
Browse files

Make RegularArgument handle :inout arguments for :array

  • Loading branch information...
1 parent 97672b9 commit 81e8be3263760ae0fa90bc47b497f3f8c18852be @mvz committed Nov 11, 2012
Showing with 18 additions and 14 deletions.
  1. +1 −14 lib/gir_ffi/builder/argument.rb
  2. +1 −0 lib/gir_ffi/type_map.rb
  3. +16 −0 test/gir_ffi/builder/regular_argument_test.rb
@@ -145,7 +145,7 @@ def needs_outgoing_parameter_conversion?
[ :array, :enum, :flags, :ghash, :glist, :gslist, :object, :struct,
:strv ].include?(specialized_type_tag)
else
- [ :enum, :flags, :ghash, :glist, :gslist, :object, :struct,
+ [ :array, :enum, :flags, :ghash, :glist, :gslist, :object, :struct,
:strv ].include?(specialized_type_tag)
end
end
@@ -221,10 +221,6 @@ def self.build var_gen, arginfo, libmodule
end
when :c
CArrayOutArgument
- when :array
- it = PointerLikeOutArgument.new var_gen, arginfo.name, type, direction
- it.extend WithTypedContainerPostMethod
- return it
else
RegularArgument
end
@@ -256,15 +252,6 @@ def postpost
end
end
- # Base class for arguments with direction :out for which the base type is
- # a pointer: For these, a pointer to a pointer needs to be passed to the
- # C function.
- class PointerLikeOutArgument < Argument::OutBase
- def pre
- [ "#{callarg} = GirFFI::InOutPointer.for :pointer" ]
- end
- end
-
module WithTypedContainerPostMethod
def post
[ "#{retname} = #{argument_class_name}.wrap #{elm_t}, #{callarg}.to_value" ]
@@ -9,6 +9,7 @@ module TypeMap
:ghash => :pointer,
:glist => :pointer,
:gslist => :pointer,
+ :array => :pointer,
:strv => :pointer,
:object => :pointer,
:struct => :pointer,
@@ -88,6 +88,22 @@
end
end
+ describe "for :array" do
+ before do
+ stub(type_info).tag { :array }
+ stub(type_info).flattened_tag { :array }
+ stub(type_info).element_type { :foo }
+ end
+
+ it "has the correct value for #pre" do
+ builder.pre.must_equal [ "_v1 = GirFFI::InOutPointer.for :array" ]
+ end
+
+ it "has the correct value for #post" do
+ builder.post.must_equal [ "_v2 = GLib::Array.wrap(:foo, _v1.to_value)" ]
+ end
+ end
+
describe "for :glist" do
before do
stub(type_info).tag { :glist }

0 comments on commit 81e8be3

Please sign in to comment.