gir_ffi 0.6.3 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. data/History.txt +11 -0
  2. data/README.md +24 -6
  3. data/lib/ffi-glib/ptr_array.rb +17 -1
  4. data/lib/ffi-glib/variant.rb +15 -0
  5. data/lib/ffi-glib.rb +1 -0
  6. data/lib/ffi-gobject/object.rb +1 -1
  7. data/lib/ffi-gobject/ruby_closure.rb +1 -1
  8. data/lib/ffi-gobject/value.rb +13 -3
  9. data/lib/ffi-gobject.rb +1 -2
  10. data/lib/ffi-gobject_introspection/i_enum_info.rb +14 -0
  11. data/lib/ffi-gobject_introspection/lib.rb +2 -0
  12. data/lib/gir_ffi/arg_helper.rb +2 -0
  13. data/lib/gir_ffi/argument_builder.rb +22 -21
  14. data/lib/gir_ffi/base_argument_builder.rb +2 -1
  15. data/lib/gir_ffi/builder/module.rb +2 -3
  16. data/lib/gir_ffi/builder/type/enum.rb +18 -1
  17. data/lib/gir_ffi/builder/type/object.rb +20 -18
  18. data/lib/gir_ffi/class_base.rb +0 -1
  19. data/lib/gir_ffi/enum_base.rb +25 -0
  20. data/lib/gir_ffi/ffi_ext.rb +1 -0
  21. data/lib/gir_ffi/function_builder.rb +50 -33
  22. data/lib/gir_ffi/in_out_pointer.rb +0 -5
  23. data/lib/gir_ffi/in_pointer.rb +7 -5
  24. data/lib/gir_ffi/info_ext/i_callable_info.rb +4 -0
  25. data/lib/gir_ffi/info_ext/i_enum_info.rb +13 -0
  26. data/lib/gir_ffi/info_ext/i_field_info.rb +1 -1
  27. data/lib/gir_ffi/info_ext/i_object_info.rb +11 -0
  28. data/lib/gir_ffi/info_ext/i_registered_type_info.rb +11 -0
  29. data/lib/gir_ffi/info_ext/i_struct_info.rb +11 -0
  30. data/lib/gir_ffi/info_ext/i_type_info.rb +10 -19
  31. data/lib/gir_ffi/info_ext/i_union_info.rb +12 -0
  32. data/lib/gir_ffi/info_ext/safe_constant_name.rb +0 -2
  33. data/lib/gir_ffi/info_ext.rb +4 -0
  34. data/lib/gir_ffi/interface_base.rb +0 -1
  35. data/lib/gir_ffi/return_value_builder.rb +3 -2
  36. data/lib/gir_ffi/type_map.rb +3 -0
  37. data/lib/gir_ffi/version.rb +1 -1
  38. data/lib/gir_ffi/zero_terminated.rb +36 -3
  39. data/lib/gir_ffi-base/gir_ffi/library.rb +17 -0
  40. data/lib/gir_ffi-base/gobject/lib.rb +2 -2
  41. data/lib/gir_ffi.rb +1 -0
  42. data/tasks/test.rake +1 -0
  43. data/test/base_test_helper.rb +22 -2
  44. data/test/ffi-glib/ruby_closure_test.rb +1 -1
  45. data/test/ffi-glib/variant_test.rb +10 -0
  46. data/test/ffi-gobject/value_test.rb +24 -8
  47. data/test/ffi-gobject_introspection/i_enum_info_test.rb +17 -0
  48. data/test/gir_ffi/argument_builder_test.rb +66 -24
  49. data/test/gir_ffi/builder_test.rb +1 -1
  50. data/test/gir_ffi/function_builder_test.rb +1 -3
  51. data/test/gir_ffi/in_out_pointer_test.rb +5 -3
  52. data/test/gir_ffi/in_pointer_test.rb +32 -2
  53. data/test/gir_ffi/info_ext/i_arg_info_test.rb +2 -2
  54. data/test/gir_ffi/info_ext/i_callable_info_test.rb +2 -2
  55. data/test/gir_ffi/info_ext/i_field_info_test.rb +14 -20
  56. data/test/gir_ffi/info_ext/i_function_info_test.rb +2 -2
  57. data/test/gir_ffi/info_ext/i_signal_info_test.rb +2 -2
  58. data/test/gir_ffi/info_ext/i_type_info_test.rb +8 -8
  59. data/test/gir_ffi/info_ext/safe_constant_name_test.rb +2 -2
  60. data/test/gir_ffi/info_ext/safe_function_name_test.rb +2 -2
  61. data/test/gir_ffi/return_value_builder_test.rb +18 -1
  62. data/test/gir_ffi/zero_terminated_test.rb +10 -0
  63. data/test/gir_ffi_test_helper.rb +0 -19
  64. data/test/integration/generated_gimarshallingtests_test.rb +291 -99
  65. data/test/integration/generated_regress_test.rb +138 -14
  66. data/test/lib/autogen.sh +6 -2
  67. metadata +14 -2
@@ -40,9 +40,6 @@ module GirFFI
40
40
  case @value_type
41
41
  when :gboolean
42
42
  (value ? 1 : 0)
43
- # TODO: Remove all references to :utf8 from this class
44
- when :utf8
45
- InPointer.from :utf8, value
46
43
  else
47
44
  value || nil_value
48
45
  end
@@ -60,7 +57,5 @@ module GirFFI
60
57
  value
61
58
  end
62
59
  end
63
-
64
60
  end
65
61
  end
66
-
@@ -10,8 +10,10 @@ module GirFFI
10
10
  from_utf8_array ary
11
11
  when Symbol
12
12
  from_basic_type_array type, ary
13
- when FFI::Enum
14
- from_enum_array type, ary
13
+ when Module
14
+ from_enum_array type::Enum, ary
15
+ when Array
16
+ from_interface_pointer_array ary
15
17
  else
16
18
  raise NotImplementedError, type
17
19
  end
@@ -22,14 +24,14 @@ module GirFFI
22
24
  case type
23
25
  when :utf8, :filename
24
26
  from_utf8 val
25
- when :gint32, :gint8
27
+ when :gint32, :guint32, :gint8
26
28
  self.new val
27
- when FFI::Enum
29
+ when Module
28
30
  self.new type[val]
29
31
  when :void
30
32
  ArgHelper.object_to_inptr val
31
33
  else
32
- raise NotImplementedError
34
+ raise NotImplementedError, type
33
35
  end
34
36
  end
35
37
 
@@ -9,6 +9,10 @@ module GirFFI
9
9
  def return_ffi_type
10
10
  return_type.to_ffitype
11
11
  end
12
+
13
+ def to_ffitype
14
+ Builder.build_class self
15
+ end
12
16
  end
13
17
  end
14
18
  end
@@ -0,0 +1,13 @@
1
+ module GirFFI
2
+ module InfoExt
3
+ module IEnumInfo
4
+ def to_ffitype
5
+ # TODO: It would make more sense if it were called Enum
6
+ to_type::Enum
7
+ end
8
+ end
9
+ end
10
+ end
11
+
12
+ GObjectIntrospection::IEnumInfo.send :include, GirFFI::InfoExt::IEnumInfo
13
+
@@ -4,7 +4,7 @@ module GirFFI
4
4
  module IFieldInfo
5
5
  def layout_specification
6
6
  [ name.to_sym,
7
- field_type.layout_specification_type,
7
+ field_type.to_ffitype,
8
8
  offset ]
9
9
  end
10
10
  end
@@ -0,0 +1,11 @@
1
+ module GirFFI
2
+ module InfoExt
3
+ module IObjectInfo
4
+ def to_ffitype
5
+ to_type::Struct
6
+ end
7
+ end
8
+ end
9
+ end
10
+
11
+ GObjectIntrospection::IObjectInfo.send :include, GirFFI::InfoExt::IObjectInfo
@@ -1,11 +1,22 @@
1
1
  require 'gir_ffi/builder_helper'
2
+ require 'gir_ffi/info_ext/safe_constant_name'
2
3
 
3
4
  module GirFFI
4
5
  module InfoExt
5
6
  module IRegisteredTypeInfo
7
+ include SafeConstantName
8
+
6
9
  def full_type_name
7
10
  "::#{safe_namespace}::#{name}"
8
11
  end
12
+
13
+ def to_ffitype
14
+ to_type
15
+ end
16
+
17
+ def to_type
18
+ Builder.build_class self
19
+ end
9
20
  end
10
21
  end
11
22
  end
@@ -0,0 +1,11 @@
1
+ module GirFFI
2
+ module InfoExt
3
+ module IStructInfo
4
+ def to_ffitype
5
+ to_type::Struct
6
+ end
7
+ end
8
+ end
9
+ end
10
+
11
+ GObjectIntrospection::IStructInfo.send :include, GirFFI::InfoExt::IStructInfo
@@ -20,23 +20,6 @@ module GirFFI
20
20
  GObject::Value.for_g_type g_type
21
21
  end
22
22
 
23
- def layout_specification_type
24
- ffitype = self.to_ffitype
25
- case ffitype
26
- when Class
27
- ffitype.const_get :Struct
28
- when :array
29
- subtype = param_type(0).layout_specification_type
30
- # XXX Don't use pointer directly to appease JRuby.
31
- if subtype == :pointer
32
- subtype = :"uint#{FFI.type_size(:pointer)*8}"
33
- end
34
- [subtype, array_fixed_size]
35
- else
36
- ffitype
37
- end
38
- end
39
-
40
23
  def element_type
41
24
  case tag
42
25
  when :glist, :gslist, :array
@@ -117,8 +100,16 @@ module GirFFI
117
100
  return :pointer if pointer?
118
101
 
119
102
  type_tag = tag
120
- if type_tag == :interface
121
- Builder.build_class interface
103
+ case type_tag
104
+ when :interface
105
+ interface.to_ffitype
106
+ when :array
107
+ subtype = param_type(0).to_ffitype
108
+ # NOTE: Don't use pointer directly to appease JRuby.
109
+ if subtype == :pointer
110
+ subtype = :"uint#{FFI.type_size(:pointer)*8}"
111
+ end
112
+ [subtype, array_fixed_size]
122
113
  else
123
114
  TypeMap.map_basic_type type_tag
124
115
  end
@@ -0,0 +1,12 @@
1
+ module GirFFI
2
+ module InfoExt
3
+ module IUnionInfo
4
+ def to_ffitype
5
+ # TODO: It would make more sense if it were called Union
6
+ to_type::Struct
7
+ end
8
+ end
9
+ end
10
+ end
11
+
12
+ GObjectIntrospection::IUnionInfo.send :include, GirFFI::InfoExt::IUnionInfo
@@ -16,7 +16,5 @@ module GirFFI
16
16
  end
17
17
  end
18
18
 
19
- GObjectIntrospection::IRegisteredTypeInfo.send :include, GirFFI::InfoExt::SafeConstantName
20
19
  GObjectIntrospection::ICallbackInfo.send :include, GirFFI::InfoExt::SafeConstantName
21
20
  GObjectIntrospection::IConstantInfo.send :include, GirFFI::InfoExt::SafeConstantName
22
-
@@ -1,10 +1,14 @@
1
1
  require 'gir_ffi/info_ext/i_arg_info'
2
2
  require 'gir_ffi/info_ext/i_callable_info'
3
+ require 'gir_ffi/info_ext/i_enum_info'
3
4
  require 'gir_ffi/info_ext/i_field_info'
4
5
  require 'gir_ffi/info_ext/i_function_info'
6
+ require 'gir_ffi/info_ext/i_object_info'
5
7
  require 'gir_ffi/info_ext/i_property_info'
6
8
  require 'gir_ffi/info_ext/i_registered_type_info'
7
9
  require 'gir_ffi/info_ext/i_signal_info'
10
+ require 'gir_ffi/info_ext/i_struct_info'
8
11
  require 'gir_ffi/info_ext/i_type_info'
12
+ require 'gir_ffi/info_ext/i_union_info'
9
13
  require 'gir_ffi/info_ext/safe_constant_name'
10
14
  require 'gir_ffi/info_ext/safe_function_name'
@@ -13,4 +13,3 @@ module GirFFI
13
13
  end
14
14
  end
15
15
  end
16
-
@@ -63,9 +63,10 @@ module GirFFI
63
63
  needs_wrapping? || [ :utf8, :c ].include?(specialized_type_tag)
64
64
  end
65
65
 
66
+ # TODO: Merge with ArgumentBuilder#needs_outgoing_parameter_conversion?
66
67
  def needs_wrapping?
67
- [ :struct, :union, :interface, :object, :strv, :zero_terminated,
68
- :byte_array, :ptr_array, :glist, :gslist, :ghash, :array
68
+ [ :array, :byte_array, :error, :ghash, :glist, :gslist, :interface,
69
+ :object, :ptr_array, :struct, :strv, :union, :zero_terminated
69
70
  ].include?(specialized_type_tag)
70
71
  end
71
72
 
@@ -13,6 +13,9 @@ module GirFFI
13
13
  :c => :pointer,
14
14
  :object => :pointer,
15
15
  :struct => :pointer,
16
+ :error => :pointer,
17
+ :ptr_array => :pointer,
18
+ :utf8 => :pointer,
16
19
  :GType => gtype_type,
17
20
  :gboolean => :bool,
18
21
  :gunichar => :uint32,
@@ -1,3 +1,3 @@
1
1
  module GirFFI
2
- VERSION = "0.6.3"
2
+ VERSION = "0.6.4"
3
3
  end
@@ -26,7 +26,10 @@ module GirFFI
26
26
  return if @ptr.null?
27
27
  offset = 0
28
28
  while val = read_value(offset)
29
- offset += FFI.type_size(:int32)
29
+ offset += FFI.type_size(ffi_type)
30
+ if complex_element_type?
31
+ val = element_class.wrap val
32
+ end
30
33
  yield val
31
34
  end
32
35
  end
@@ -34,8 +37,38 @@ module GirFFI
34
37
  private
35
38
 
36
39
  def read_value offset
37
- val = @ptr.get_int32(offset)
38
- return val unless val == 0
40
+ val = @ptr.send("get_#{ffi_type}", offset)
41
+ return val unless is_null_value(val)
42
+ end
43
+
44
+ def ffi_type
45
+ @ffi_type ||= TypeMap.map_basic_type_or_string basic_element_type
46
+ end
47
+
48
+ def complex_element_type?
49
+ Array === element_type
50
+ end
51
+
52
+ def basic_element_type
53
+ if complex_element_type?
54
+ element_type.first
55
+ else
56
+ element_type
57
+ end
58
+ end
59
+
60
+ def is_null_value value
61
+ if basic_element_type == :pointer
62
+ value.null?
63
+ else
64
+ value == 0
65
+ end
66
+ end
67
+
68
+ def element_class
69
+ if complex_element_type?
70
+ element_type.last
71
+ end
39
72
  end
40
73
  end
41
74
  end
@@ -0,0 +1,17 @@
1
+ require 'ffi'
2
+
3
+ module GirFFI
4
+ module Library
5
+ include FFI::Library
6
+
7
+ def find_type type
8
+ if type.is_a? Module
9
+ if type.const_defined?(:Enum)
10
+ return super type::Enum
11
+ end
12
+ end
13
+
14
+ super
15
+ end
16
+ end
17
+ end
@@ -1,8 +1,8 @@
1
- require 'ffi'
1
+ require 'gir_ffi-base/gir_ffi/library'
2
2
 
3
3
  module GObject
4
4
  module Lib
5
- extend FFI::Library
5
+ extend GirFFI::Library
6
6
  ffi_lib "gobject-2.0"
7
7
  attach_function :g_type_init, [], :void
8
8
  end
data/lib/gir_ffi.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'ffi'
2
2
 
3
+ require 'gir_ffi/ffi_ext'
3
4
  require 'gir_ffi/class_base'
4
5
  require 'gir_ffi/type_map'
5
6
 
data/tasks/test.rake CHANGED
@@ -102,6 +102,7 @@ namespace :test do
102
102
  :overrides,
103
103
  :integration]
104
104
 
105
+ desc "Create stubs for Regress and GIMarshallingTests tests"
105
106
  task :stub => :lib do
106
107
  file = File.new 'test/lib/Regress-1.0.gir'
107
108
  listener = Listener.new
@@ -10,6 +10,28 @@ end
10
10
  require 'minitest/autorun'
11
11
  require 'rr'
12
12
 
13
+ require 'gir_ffi-base'
14
+ require 'ffi-gobject_introspection'
15
+
16
+ GObjectIntrospection::IRepository.prepend_search_path File.join(File.dirname(__FILE__), 'lib')
17
+ module GObjectIntrospection
18
+ class IRepository
19
+ def shared_library_with_regress namespace
20
+ case namespace
21
+ when "Regress"
22
+ return File.join(File.dirname(__FILE__), 'lib', 'libregress.so')
23
+ when "GIMarshallingTests"
24
+ return File.join(File.dirname(__FILE__), 'lib', 'libgimarshallingtests.so')
25
+ else
26
+ return shared_library_without_regress namespace
27
+ end
28
+ end
29
+
30
+ alias shared_library_without_regress shared_library
31
+ alias shared_library shared_library_with_regress
32
+ end
33
+ end
34
+
13
35
  Thread.abort_on_exception = true
14
36
 
15
37
  class Minitest::Test
@@ -71,5 +93,3 @@ class Minitest::Spec
71
93
  alias :context :describe
72
94
  end
73
95
  end
74
-
75
- require 'gir_ffi-base'
@@ -40,7 +40,7 @@ describe GObject::RubyClosure do
40
40
  c = GObject::RubyClosure.new { 2 }
41
41
  gv = GObject::Value.new
42
42
  GObject::RubyClosure.marshaller(c, gv, 0, nil, nil, nil)
43
- assert_equal 2, gv.ruby_value
43
+ assert_equal 2, gv.get_value
44
44
  end
45
45
  end
46
46
 
@@ -0,0 +1,10 @@
1
+ require 'gir_ffi_test_helper'
2
+
3
+ describe GLib::Variant do
4
+ describe "#get_string" do
5
+ it "returns just the contained string" do
6
+ var = GLib::Variant.new_string("Foo")
7
+ var.get_string.must_equal "Foo"
8
+ end
9
+ end
10
+ end
@@ -42,25 +42,41 @@ describe GObject::Value do
42
42
  end
43
43
  end
44
44
 
45
- describe "#ruby_value" do
45
+ describe "#set_value" do
46
+ it "handles :int64" do
47
+ value = 0x1234_5678_9012_3456
48
+ gv = GObject::Value.for_g_type GObject::TYPE_INT64
49
+ gv.set_value value
50
+ gv.get_int64.must_equal value
51
+ end
52
+ end
53
+
54
+ describe "#get_value" do
46
55
  it "unwraps a boolean false" do
47
56
  gv = GObject::Value.wrap_ruby_value false
48
- result = gv.ruby_value
57
+ result = gv.get_value
49
58
  assert_equal false, result
50
59
  end
51
60
 
52
61
  it "unwraps a boolean true" do
53
62
  gv = GObject::Value.wrap_ruby_value true
54
- result = gv.ruby_value
63
+ result = gv.get_value
55
64
  assert_equal true, result
56
65
  end
57
66
 
67
+ it "unwraps an int64" do
68
+ value = 0x1234_5678_9012_3456
69
+ gv = GObject::Value.for_g_type GObject::TYPE_INT64
70
+ gv.set_int64 value
71
+ gv.get_value.must_equal value
72
+ end
73
+
58
74
  it "works with a ByteArray" do
59
75
  ba = GLib::ByteArray.new.append("some bytes")
60
- v = GObject::Value.new.init(GObject.type_from_name("GByteArray"))
76
+ v = GObject::Value.for_g_type GObject.type_from_name("GByteArray")
61
77
  v.set_boxed ba
62
78
 
63
- result = v.ruby_value
79
+ result = v.get_value
64
80
 
65
81
  result.to_string.must_equal "some bytes"
66
82
  result.must_be_kind_of GLib::ByteArray
@@ -71,14 +87,14 @@ describe GObject::Value do
71
87
  it "creates a gint GValue from a Ruby Integer" do
72
88
  gv = GObject::Value.from 21
73
89
  gv.current_gtype_name.must_equal "gint"
74
- gv.ruby_value.must_equal 21
90
+ gv.get_value.must_equal 21
75
91
  end
76
92
 
77
93
  it "returns its argument if given a GValue" do
78
94
  gv = GObject::Value.from 21
79
95
  gv2 = GObject::Value.from gv
80
96
  gv2.current_gtype_name.must_equal "gint"
81
- gv2.ruby_value.must_equal 21
97
+ gv2.get_value.must_equal 21
82
98
  end
83
99
  end
84
100
 
@@ -97,7 +113,7 @@ describe GObject::Value do
97
113
  ba = GLib::ByteArray.new.append("some bytes")
98
114
  v = GObject::Value.new.init(GObject.type_from_name("GByteArray"))
99
115
  v.set_value ba
100
- v.ruby_value.to_string.must_equal "some bytes"
116
+ v.get_value.to_string.must_equal "some bytes"
101
117
  end
102
118
  end
103
119
  end
@@ -0,0 +1,17 @@
1
+ require 'introspection_test_helper'
2
+
3
+ describe GObjectIntrospection::IEnumInfo do
4
+ describe "#find_method" do
5
+ setup do
6
+ gir = GObjectIntrospection::IRepository.default
7
+ gir.require 'Regress', nil
8
+ @info = gir.find_by_name 'Regress', 'TestEnum'
9
+ end
10
+
11
+ should "find a method by name" do
12
+ result = @info.find_method("param")
13
+ result.name.must_equal "param"
14
+ end
15
+ end
16
+ end
17
+