gir_ffi 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/History.txt +5 -0
  2. data/lib/ffi-glib/array.rb +2 -3
  3. data/lib/ffi-glib/container_class_methods.rb +3 -4
  4. data/lib/ffi-glib/hash_table.rb +7 -3
  5. data/lib/ffi-glib/list_methods.rb +1 -1
  6. data/lib/ffi-glib/sized_array.rb +66 -0
  7. data/lib/ffi-glib/strv.rb +1 -1
  8. data/lib/ffi-glib.rb +5 -4
  9. data/lib/ffi-gobject/object.rb +2 -3
  10. data/lib/ffi-gobject/ruby_closure.rb +3 -2
  11. data/lib/ffi-gobject/value.rb +26 -14
  12. data/lib/ffi-gobject.rb +8 -5
  13. data/lib/ffi-gobject_introspection/g_error.rb +1 -0
  14. data/lib/ffi-gobject_introspection/i_base_info.rb +3 -2
  15. data/lib/ffi-gobject_introspection/i_union_info.rb +21 -8
  16. data/lib/ffi-gobject_introspection/lib.rb +1 -0
  17. data/lib/gir_ffi/argument_builder.rb +8 -20
  18. data/lib/gir_ffi/base_argument_builder.rb +13 -30
  19. data/lib/gir_ffi/builder/module.rb +3 -9
  20. data/lib/gir_ffi/builder/type/base.rb +2 -0
  21. data/lib/gir_ffi/builder/type/callback.rb +2 -2
  22. data/lib/gir_ffi/builder/type/enum.rb +1 -0
  23. data/lib/gir_ffi/builder/type/object.rb +13 -3
  24. data/lib/gir_ffi/builder/type/registered_type.rb +1 -1
  25. data/lib/gir_ffi/builder/type/struct.rb +18 -3
  26. data/lib/gir_ffi/builder/type/unintrospectable.rb +5 -45
  27. data/lib/gir_ffi/builder/type/user_defined.rb +3 -15
  28. data/lib/gir_ffi/builder/type.rb +5 -5
  29. data/lib/gir_ffi/builder.rb +5 -80
  30. data/lib/gir_ffi/callback.rb +65 -2
  31. data/lib/gir_ffi/callback_helper.rb +0 -56
  32. data/lib/gir_ffi/class_base.rb +2 -2
  33. data/lib/gir_ffi/in_out_pointer.rb +7 -28
  34. data/lib/gir_ffi/in_pointer.rb +12 -19
  35. data/lib/gir_ffi/info_ext/i_arg_info.rb +5 -0
  36. data/lib/gir_ffi/info_ext/i_callable_info.rb +16 -0
  37. data/lib/gir_ffi/info_ext/i_function_info.rb +15 -0
  38. data/lib/gir_ffi/info_ext/i_signal_info.rb +17 -10
  39. data/lib/gir_ffi/info_ext/i_type_info.rb +63 -39
  40. data/lib/gir_ffi/info_ext.rb +5 -3
  41. data/lib/gir_ffi/null_argument_builder.rb +1 -1
  42. data/lib/gir_ffi/return_value_builder.rb +24 -16
  43. data/lib/gir_ffi/unintrospectable_type_info.rb +41 -0
  44. data/lib/gir_ffi/user_defined_property_info.rb +15 -0
  45. data/lib/gir_ffi/user_defined_type_info.rb +25 -0
  46. data/lib/gir_ffi/version.rb +1 -1
  47. data/lib/gir_ffi-base.rb +3 -0
  48. data/lib/gir_ffi.rb +2 -1
  49. data/test/ffi-glib/sized_array_test.rb +87 -0
  50. data/test/ffi-gobject_introspection/i_base_info_test.rb +4 -5
  51. data/test/gir_ffi/argument_builder_test.rb +26 -55
  52. data/test/gir_ffi/builder/type/unintrospectable_test.rb +3 -19
  53. data/test/gir_ffi/builder/type/user_defined_test.rb +16 -21
  54. data/test/gir_ffi/builder_test.rb +31 -53
  55. data/test/gir_ffi/callback_helper_test.rb +0 -47
  56. data/test/gir_ffi/callback_test.rb +49 -0
  57. data/test/gir_ffi/function_builder_test.rb +8 -8
  58. data/test/gir_ffi/in_out_pointer_test.rb +2 -53
  59. data/test/gir_ffi/in_pointer_test.rb +0 -13
  60. data/test/gir_ffi/info_ext/i_callable_info_test.rb +32 -0
  61. data/test/gir_ffi/info_ext/i_function_info_test.rb +61 -0
  62. data/test/gir_ffi/info_ext/i_signal_info_test.rb +7 -0
  63. data/test/gir_ffi/info_ext/i_type_info_test.rb +158 -77
  64. data/test/gir_ffi/return_value_builder_test.rb +2 -2
  65. data/test/gir_ffi/unintrospectable_type_info_test.rb +95 -0
  66. data/test/gir_ffi/user_defined_property_info_test.rb +19 -0
  67. data/test/gir_ffi/user_defined_type_info_test.rb +34 -0
  68. data/test/integration/generated_gimarshallingtests_test.rb +10 -10
  69. data/test/integration/generated_regress_test.rb +10 -10
  70. metadata +24 -15
  71. data/lib/gir_ffi/builder/type/struct_based.rb +0 -31
  72. data/lib/gir_ffi/user_defined/i_base_info.rb +0 -7
  73. data/lib/gir_ffi/user_defined/i_object_info.rb +0 -13
  74. data/lib/gir_ffi/user_defined/i_property_info.rb +0 -9
  75. data/lib/gir_ffi/user_defined/i_registered_type_info.rb +0 -10
  76. data/test/gir_ffi/user_defined/i_object_info_test.rb +0 -18
  77. data/test/gir_ffi/user_defined/i_property_info_test.rb +0 -14
  78. data/test/gir_ffi/user_defined/i_registered_type_info_test.rb +0 -10
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.6.0 / 2013-06-07
2
+
3
+ * Support Rubinius
4
+ * Lots of refactoring
5
+
1
6
  == 0.5.2 / 2013-04-23
2
7
 
3
8
  * Handle signal details in GObject.signal_connect and .signal_emit
@@ -44,9 +44,8 @@ module GLib
44
44
  end
45
45
 
46
46
  def self.wrap elmttype, ptr
47
- super(ptr).tap do |it|
48
- break if it.nil?
49
- it.element_type = elmttype
47
+ super(ptr).tap do |array|
48
+ array.element_type = elmttype if array
50
49
  end
51
50
  end
52
51
 
@@ -1,8 +1,8 @@
1
1
  module GLib
2
2
  module ContainerClassMethods
3
3
  def wrap typespec, ptr
4
- if (it = super(ptr))
5
- it.reset_typespec typespec
4
+ super(ptr).tap do |container|
5
+ container.reset_typespec typespec if container
6
6
  end
7
7
  end
8
8
 
@@ -13,6 +13,7 @@ module GLib
13
13
  when FFI::Pointer
14
14
  wrap typespec, it
15
15
  when self
16
+ # TODO: Reset or check?
16
17
  it.reset_typespec typespec
17
18
  else
18
19
  from_enumerable typespec, it
@@ -20,5 +21,3 @@ module GLib
20
21
  end
21
22
  end
22
23
  end
23
-
24
-
@@ -56,7 +56,9 @@ module GLib
56
56
  def self.hash_function_for keytype
57
57
  case keytype
58
58
  when :utf8
59
- FFI::Function.new(:uint, [:pointer], find_support_funtion("g_str_hash"))
59
+ FFI::Function.new(:uint,
60
+ [:pointer],
61
+ find_support_function("g_str_hash"))
60
62
  else
61
63
  nil
62
64
  end
@@ -65,13 +67,15 @@ module GLib
65
67
  def self.equality_function_for keytype
66
68
  case keytype
67
69
  when :utf8
68
- FFI::Function.new(:int, [:pointer, :pointer], find_support_funtion("g_str_equal"))
70
+ FFI::Function.new(:int,
71
+ [:pointer, :pointer],
72
+ find_support_function("g_str_equal"))
69
73
  else
70
74
  nil
71
75
  end
72
76
  end
73
77
 
74
- def self.find_support_funtion name
78
+ def self.find_support_function name
75
79
  lib = ::GLib::Lib.ffi_libraries.first
76
80
  lib.find_function(name)
77
81
  end
@@ -46,7 +46,7 @@ module GLib
46
46
  end
47
47
 
48
48
  def next_element
49
- return if @current.nil?
49
+ return if !@current
50
50
  element = @current.head
51
51
  @current = @current.tail
52
52
  element
@@ -0,0 +1,66 @@
1
+ module GLib
2
+ # Class representing an array with a determined size
3
+ class SizedArray
4
+ include Enumerable
5
+ attr_reader :element_type, :size
6
+
7
+ def initialize element_type, size, pointer
8
+ @element_type = element_type
9
+ @size = size
10
+ @pointer = pointer
11
+ end
12
+
13
+ def to_ptr
14
+ @pointer
15
+ end
16
+
17
+ def each &block
18
+ # TODO: Move implementation from GirFFI::ArgHelper to here.
19
+ # While doing so, the implentation could also become a real iterator
20
+ arr = GirFFI::ArgHelper.ptr_to_typed_array(@element_type, @pointer, @size)
21
+ if block_given?
22
+ arr.each(&block)
23
+ else
24
+ arr.each
25
+ end
26
+ end
27
+
28
+ def self.wrap element_type, size, pointer
29
+ new element_type, size, pointer unless pointer.null?
30
+ end
31
+
32
+ class << self
33
+ def from element_type, size, item
34
+ return unless item
35
+
36
+ case item
37
+ when FFI::Pointer
38
+ wrap element_type, size, item
39
+ when self
40
+ from_sized_array size, item
41
+ else
42
+ from_enumerable element_type, size, item
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def from_sized_array size, sized_array
49
+ check_size(size, sized_array.size)
50
+ sized_array
51
+ end
52
+
53
+ def from_enumerable element_type, size, arr
54
+ check_size(size, arr.size)
55
+ ptr = GirFFI::InPointer.from_array element_type, arr
56
+ self.wrap element_type, arr.size, ptr
57
+ end
58
+
59
+ def check_size(expected_size, size)
60
+ if expected_size > 0 && size != expected_size
61
+ raise ArgumentError, "Expected size #{expected_size}, got #{size}"
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
data/lib/ffi-glib/strv.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module GLib
2
- # Extra methods for GLib::Strv.
2
+ # Extra methods for GLib::Strv. The bulk is defined in `gir_ffi-base/glib/strv.rb`
3
3
  class Strv
4
4
  def self.from it
5
5
  case it
data/lib/ffi-glib.rb CHANGED
@@ -3,12 +3,13 @@
3
3
 
4
4
  GirFFI.setup :GLib
5
5
 
6
- require 'ffi-glib/s_list'
7
- require 'ffi-glib/list'
8
- require 'ffi-glib/hash_table'
9
- require 'ffi-glib/byte_array'
10
6
  require 'ffi-glib/array'
7
+ require 'ffi-glib/byte_array'
8
+ require 'ffi-glib/hash_table'
9
+ require 'ffi-glib/list'
11
10
  require 'ffi-glib/ptr_array'
11
+ require 'ffi-glib/s_list'
12
+ require 'ffi-glib/sized_array'
12
13
  require 'ffi-glib/strv'
13
14
 
14
15
  module GLib
@@ -46,10 +46,9 @@ module GObject
46
46
  def adjust_value_to_type val, type
47
47
  case type.tag
48
48
  when :ghash
49
- GLib::HashTable.from [type.param_type(0).tag, type.param_type(1).tag],
50
- val
49
+ GLib::HashTable.from type.element_type, val
51
50
  when :glist
52
- GLib::List.from type.param_type(0).tag, val
51
+ GLib::List.from type.element_type, val
53
52
  else
54
53
  val
55
54
  end
@@ -37,8 +37,9 @@ module GObject
37
37
  return closure
38
38
  end
39
39
 
40
+ # TODO: Use invocation_hint and marshal_data
40
41
  def self.marshaller(closure, return_value, n_param_values,
41
- param_values, invocation_hint, marshal_data)
42
+ param_values, _invocation_hint, _marshal_data)
42
43
  rclosure = wrap(closure.to_ptr)
43
44
 
44
45
  args = n_param_values.times.map {|idx|
@@ -47,7 +48,7 @@ module GObject
47
48
 
48
49
  result = rclosure.invoke_block(*args)
49
50
 
50
- return_value.set_ruby_value(result) unless return_value.nil?
51
+ return_value.set_ruby_value(result) if return_value
51
52
  end
52
53
  end
53
54
  end
@@ -3,6 +3,7 @@ module GObject
3
3
 
4
4
  # Overrides for GValue, GObject's generic value container structure.
5
5
  class Value
6
+ # TODO: Give more generic name
6
7
  def set_ruby_value val
7
8
  if current_gtype == 0
8
9
  init_for_ruby_value val
@@ -25,8 +26,7 @@ module GObject
25
26
  }
26
27
 
27
28
  def set_value val
28
- method = TYPE_TO_SET_METHOD_MAP[current_fundamental_type]
29
- call_or_raise method, val
29
+ send set_method, val
30
30
  self
31
31
  end
32
32
 
@@ -70,12 +70,13 @@ module GObject
70
70
  TYPE_POINTER => :get_pointer
71
71
  }
72
72
 
73
+ # TODO: Rename to get_value
73
74
  def ruby_value
74
- method = TYPE_TO_GET_METHOD_MAP[current_fundamental_type]
75
- call_or_raise method
75
+ send get_method
76
76
  end
77
77
 
78
78
  class << self
79
+ # TODO: Give more generic name
79
80
  def wrap_ruby_value val
80
81
  self.new.set_ruby_value val
81
82
  end
@@ -97,15 +98,22 @@ module GObject
97
98
  end
98
99
  end
99
100
 
101
+ # TODO: Combine with wrap_ruby_value
102
+ def self.wrap_instance instance
103
+ self.new.tap {|it|
104
+ it.init GObject.type_from_instance instance
105
+ it.set_instance instance
106
+ }
107
+ end
108
+
100
109
  private
101
110
 
102
111
  def set_instance_enhanced val
103
- check_type_compatibility val
112
+ check_type_compatibility val if val
104
113
  set_instance val
105
114
  end
106
115
 
107
116
  def check_type_compatibility val
108
- return if val.nil?
109
117
  if !GObject::Value.type_compatible(GObject.type_from_instance(val), current_gtype)
110
118
  raise ArgumentError, "#{val.class} is incompatible with #{current_gtype_name}"
111
119
  end
@@ -113,22 +121,26 @@ module GObject
113
121
 
114
122
  def get_boxed_enhanced
115
123
  boxed = get_boxed
116
- case current_gtype
124
+ gtype = current_gtype
125
+
126
+ case gtype
117
127
  when TYPE_STRV
118
128
  GLib::Strv.wrap boxed
119
129
  when TYPE_HASH_TABLE
120
130
  GLib::HashTable.wrap [:gpointer, :gpointer], boxed
121
131
  else
122
- GirFFI::ArgHelper.wrap_object_pointer_by_gtype boxed, current_gtype
132
+ GirFFI::ArgHelper.wrap_object_pointer_by_gtype boxed, gtype
123
133
  end
124
134
  end
125
135
 
126
- def call_or_raise method, *args
127
- if method
128
- send method, *args
129
- else
130
- raise "Don't know how to handle #{current_gtype_name}"
131
- end
136
+ def get_method
137
+ TYPE_TO_GET_METHOD_MAP[current_fundamental_type] or
138
+ raise "Can't find method to get #{current_gtype_name}"
139
+ end
140
+
141
+ def set_method
142
+ TYPE_TO_SET_METHOD_MAP[current_fundamental_type] or
143
+ raise "Can't find method to set #{current_gtype_name}"
132
144
  end
133
145
  end
134
146
  end
data/lib/ffi-gobject.rb CHANGED
@@ -61,15 +61,13 @@ module GObject
61
61
 
62
62
  def self.signal_emit object, detailed_signal, *args
63
63
  signal, detail = detailed_signal.split('::')
64
- sig_info = object.class.find_signal signal
65
-
66
- id = signal_lookup_from_instance signal, object
64
+ signal_id = signal_lookup_from_instance signal, object
67
65
  detail_quark = GLib.quark_from_string(detail)
68
-
66
+ sig_info = object.class.find_signal signal
69
67
  arr = sig_info.signal_arguments_to_gvalue_array object, *args
70
68
  rval = sig_info.gvalue_for_signal_return_value
71
69
 
72
- Lib.g_signal_emitv arr.values, id, detail_quark, rval
70
+ Lib.g_signal_emitv arr.values, signal_id, detail_quark, rval
73
71
 
74
72
  return rval
75
73
  end
@@ -79,10 +77,13 @@ module GObject
79
77
  sig_info = object.class.find_signal signal
80
78
  callback = sig_info.signal_callback(&block)
81
79
  GirFFI::CallbackHelper.store_callback callback
80
+
82
81
  data_ptr = GirFFI::ArgHelper.object_to_inptr data
82
+
83
83
  Lib.g_signal_connect_data object, detailed_signal, callback, data_ptr, nil, 0
84
84
  end
85
85
 
86
+ # Smells of :reek:LongParameterList: due to the C interface.
86
87
  def self.param_spec_int(name, nick, blurb, minimum, maximum,
87
88
  default_value, flags)
88
89
  ptr = Lib.g_param_spec_int(name, nick, blurb, minimum, maximum,
@@ -97,6 +98,8 @@ module GObject
97
98
  load_class :ParamFlags
98
99
 
99
100
  module Lib
101
+ # NOTE: This Lib module is set up in `gir_ffi-base/gobject/lib.rb`.
102
+
100
103
  attach_function :g_object_ref, [:pointer], :void
101
104
  attach_function :g_object_ref_sink, [:pointer], :void
102
105
  attach_function :g_object_unref, [:pointer], :void
@@ -1,6 +1,7 @@
1
1
  module GObjectIntrospection
2
2
  # Wraps GLib's GError struct.
3
3
  class GError
4
+ # GLib's GError struct.
4
5
  class Struct < FFI::Struct
5
6
  layout :domain, :uint32,
6
7
  :code, :int,
@@ -3,10 +3,11 @@ module GObjectIntrospection
3
3
  # Decendant types will be implemented as needed.
4
4
  class IBaseInfo
5
5
  def initialize ptr, lib=Lib
6
- raise ArgumentError, "ptr must not be nil" if ptr.nil?
7
6
  raise ArgumentError, "ptr must not be null" if ptr.null?
8
7
 
9
- ObjectSpace.define_finalizer self, self.class.make_finalizer(lib, ptr)
8
+ unless defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
9
+ ObjectSpace.define_finalizer self, self.class.make_finalizer(lib, ptr)
10
+ end
10
11
 
11
12
  @gobj = ptr
12
13
  @lib = lib
@@ -1,22 +1,35 @@
1
1
  module GObjectIntrospection
2
2
  # Wraps a GIUnionInfo struct.
3
3
  # Represents a union.
4
- # Not implemented yet.
5
4
  class IUnionInfo < IRegisteredTypeInfo
6
- def n_fields; Lib.g_union_info_get_n_fields @gobj; end
7
- def field(index); IFieldInfo.wrap(Lib.g_union_info_get_field @gobj, index); end
5
+ def n_fields
6
+ Lib.g_union_info_get_n_fields @gobj
7
+ end
8
+ def field(index)
9
+ IFieldInfo.wrap(Lib.g_union_info_get_field @gobj, index)
10
+ end
8
11
 
9
12
  ##
10
13
  build_array_method :fields
11
14
 
12
- def get_n_methods; Lib.g_union_info_get_n_methods @gobj; end
13
- def get_method(index); IFunctionInfo.wrap(Lib.g_union_info_get_method @gobj, index); end
15
+ def get_n_methods
16
+ Lib.g_union_info_get_n_methods @gobj
17
+ end
18
+ def get_method(index)
19
+ IFunctionInfo.wrap(Lib.g_union_info_get_method @gobj, index)
20
+ end
14
21
 
15
22
  ##
16
23
  build_array_method :get_methods
17
24
 
18
- def find_method(name); IFunctionInfo.wrap(Lib.g_union_info_find_method @gobj, name); end
19
- def size; Lib.g_union_info_get_size @gobj; end
20
- def alignment; Lib.g_union_info_get_alignment @gobj; end
25
+ def find_method(name)
26
+ IFunctionInfo.wrap(Lib.g_union_info_find_method @gobj, name)
27
+ end
28
+ def size
29
+ Lib.g_union_info_get_size @gobj
30
+ end
31
+ def alignment
32
+ Lib.g_union_info_get_alignment @gobj
33
+ end
21
34
  end
22
35
  end
@@ -233,6 +233,7 @@ module GObjectIntrospection
233
233
  attach_function :g_interface_info_get_constant, [:pointer, :int], :pointer
234
234
  attach_function :g_interface_info_get_iface_struct, [:pointer], :pointer
235
235
 
236
+ # Union type representing an argument value
236
237
  class GIArgument < FFI::Union
237
238
  signed_size_t = "int#{FFI.type_size(:size_t) * 8}".to_sym
238
239
 
@@ -48,11 +48,13 @@ module GirFFI
48
48
  case specialized_type_tag
49
49
  when :enum, :flags
50
50
  "#{argument_class_name}[#{output_conversion_arguments}]"
51
+ when :utf8
52
+ "ArgHelper.ptr_to_utf8 #{callarg}.to_value"
51
53
  else
52
54
  "#{argument_class_name}.wrap(#{output_conversion_arguments})"
53
55
  end
54
56
  elsif is_fixed_length_array?
55
- "#{callarg}.to_sized_array_value #{array_size}"
57
+ "GLib::SizedArray.wrap(#{subtype_tag_or_class_name}, #{array_size}, #{callarg}.to_value)"
56
58
  else
57
59
  "#{callarg}.to_value"
58
60
  end
@@ -91,9 +93,9 @@ module GirFFI
91
93
  def set_function_call_argument
92
94
  value = if @direction == :out
93
95
  if is_caller_allocated_object?
94
- "#{argument_class_name}.allocate"
96
+ "#{argument_class_name}._allocate"
95
97
  else
96
- "GirFFI::InOutPointer.for #{type_specification}"
98
+ "GirFFI::InOutPointer.for #{specialized_type_tag.inspect}"
97
99
  end
98
100
  else
99
101
  if needs_ingoing_parameter_conversion?
@@ -112,7 +114,7 @@ module GirFFI
112
114
 
113
115
  def needs_outgoing_parameter_conversion?
114
116
  [ :array, :enum, :flags, :ghash, :glist, :gslist, :object, :struct,
115
- :strv ].include?(specialized_type_tag)
117
+ :strv, :utf8 ].include?(specialized_type_tag)
116
118
  end
117
119
 
118
120
  def needs_ingoing_parameter_conversion?
@@ -127,23 +129,13 @@ module GirFFI
127
129
  base = "#{argument_class_name}[#{parameter_conversion_arguments}]"
128
130
  "GirFFI::InOutPointer.from #{specialized_type_tag.inspect}, #{base}"
129
131
  when :object, :struct, :void, :glist, :gslist, :ghash, :array,
130
- :zero_terminated, :strv, :callback
132
+ :zero_terminated, :strv, :callback, :utf8, :c
131
133
  base = "#{argument_class_name}.from(#{parameter_conversion_arguments})"
132
134
  if has_output_value?
133
- if specialized_type_tag == :strv
134
- "GirFFI::InOutPointer.from #{type_specification}, #{base}"
135
- else
136
- "GirFFI::InOutPointer.from :pointer, #{base}"
137
- end
135
+ "GirFFI::InOutPointer.from :pointer, #{base}"
138
136
  else
139
137
  base
140
138
  end
141
- when :c, :utf8
142
- if has_output_value?
143
- "GirFFI::InOutPointer.from #{parameter_conversion_arguments}"
144
- else
145
- "GirFFI::InPointer.from(#{parameter_conversion_arguments})"
146
- end
147
139
  else
148
140
  base = "#{parameter_conversion_arguments}"
149
141
  "GirFFI::InOutPointer.from #{specialized_type_tag.inspect}, #{base}"
@@ -157,9 +149,5 @@ module GirFFI
157
149
  def parameter_conversion_arguments
158
150
  conversion_arguments @name
159
151
  end
160
-
161
- def self_t
162
- type_tag.inspect
163
- end
164
152
  end
165
153
  end
@@ -33,45 +33,30 @@ module GirFFI
33
33
  @typeinfo
34
34
  end
35
35
 
36
- def type_tag
37
- type_info.tag
38
- end
39
-
40
36
  def specialized_type_tag
41
37
  type_info.flattened_tag
42
38
  end
43
39
 
44
- def type_specification
45
- type_info.type_specification
46
- end
47
-
48
40
  TAG_TO_WRAPPER_CLASS_MAP = {
41
+ :array => 'GLib::Array',
42
+ :byte_array => 'GLib::ByteArray',
43
+ :c => 'GLib::SizedArray',
44
+ :callback => 'GirFFI::Callback',
45
+ :ghash => 'GLib::HashTable',
49
46
  :glist => 'GLib::List',
50
47
  :gslist => 'GLib::SList',
51
- :ghash => 'GLib::HashTable',
52
- :array => 'GLib::Array',
48
+ :ptr_array => 'GLib::PtrArray',
49
+ :strv => 'GLib::Strv',
53
50
  :utf8 => 'GirFFI::InPointer',
54
- :void => 'GirFFI::InPointer'
51
+ :void => 'GirFFI::InPointer',
52
+ :zero_terminated => 'GirFFI::ZeroTerminated'
55
53
  }
56
54
 
55
+ # TODO: Use class rather than class name
57
56
  def argument_class_name
58
57
  case (tag = type_info.flattened_tag)
59
58
  when :struct, :union, :object, :interface, :enum, :flags
60
59
  type_info.interface_type_name
61
- when :callback
62
- 'GirFFI::Callback'
63
- when :byte_array
64
- 'GLib::ByteArray'
65
- when :array
66
- 'GLib::Array'
67
- when :ptr_array
68
- 'GLib::PtrArray'
69
- when :strv
70
- 'GLib::Strv'
71
- when :c
72
- 'GirFFI::InPointer'
73
- when :zero_terminated
74
- 'GirFFI::ZeroTerminated'
75
60
  else
76
61
  TAG_TO_WRAPPER_CLASS_MAP[tag]
77
62
  end
@@ -130,11 +115,11 @@ module GirFFI
130
115
  def conversion_arguments name
131
116
  case specialized_type_tag
132
117
  when :utf8, :void
133
- "#{self_t}, #{name}"
118
+ "#{specialized_type_tag.inspect}, #{name}"
119
+ when :c
120
+ "#{subtype_tag_or_class_name}, #{type_info.array_fixed_size}, #{name}"
134
121
  when :glist, :gslist, :ghash, :array, :zero_terminated
135
122
  "#{elm_t}, #{name}"
136
- when :c
137
- "#{type_specification}, #{name}"
138
123
  when :callback
139
124
  iface = type_info.interface
140
125
  "\"#{iface.namespace}\", \"#{iface.name}\", #{name}"
@@ -144,5 +129,3 @@ module GirFFI
144
129
  end
145
130
  end
146
131
  end
147
-
148
-
@@ -29,7 +29,8 @@ module GirFFI
29
29
  lib = modul.const_get(:Lib)
30
30
 
31
31
  Builder.attach_ffi_function lib, go
32
- modul.class_eval function_definition(go, lib)
32
+ definition = function_definition(go, lib)
33
+ modul.class_eval definition
33
34
 
34
35
  true
35
36
  end
@@ -46,13 +47,6 @@ module GirFFI
46
47
  def build_module
47
48
  unless defined? @module
48
49
  build_dependencies
49
- build_module_non_recursive
50
- end
51
- @module
52
- end
53
-
54
- def build_module_non_recursive
55
- unless defined? @module
56
50
  instantiate_module
57
51
  setup_lib_for_ffi
58
52
  setup_module unless already_set_up
@@ -66,7 +60,7 @@ module GirFFI
66
60
  deps = gir.dependencies @namespace
67
61
  deps.each {|dep|
68
62
  name, version = dep.split '-'
69
- Builder.build_module_non_recursive name, version
63
+ Builder.build_module name, version
70
64
  }
71
65
  end
72
66
 
@@ -1,3 +1,5 @@
1
+ require 'gir_ffi/builder_helper'
2
+
1
3
  module GirFFI
2
4
  module Builder
3
5
  module Type
@@ -18,11 +18,11 @@ module GirFFI
18
18
  end
19
19
 
20
20
  def argument_types
21
- Builder.ffi_function_argument_types info
21
+ @info.argument_ffi_types
22
22
  end
23
23
 
24
24
  def return_type
25
- Builder.ffi_function_return_type info
25
+ @info.return_ffi_type
26
26
  end
27
27
  end
28
28
  end
@@ -1,4 +1,5 @@
1
1
  require 'gir_ffi/builder/type/registered_type'
2
+
2
3
  module GirFFI
3
4
  module Builder
4
5
  module Type
@@ -1,4 +1,6 @@
1
- require 'gir_ffi/builder/type/struct_based'
1
+ require 'gir_ffi/builder/type/registered_type'
2
+ require 'gir_ffi/builder/type/with_layout'
3
+ require 'gir_ffi/builder/type/with_methods'
2
4
  require 'gir_ffi/builder/property'
3
5
  require 'gir_ffi/object_base'
4
6
 
@@ -7,7 +9,10 @@ module GirFFI
7
9
  module Type
8
10
 
9
11
  # Implements the creation of a class representing a GObject Object.
10
- class Object < StructBased
12
+ class Object < RegisteredType
13
+ include WithMethods
14
+ include WithLayout
15
+
11
16
  def find_signal signal_name
12
17
  signal_definers.each do |inf|
13
18
  inf.signals.each do |sig|
@@ -46,10 +51,15 @@ module GirFFI
46
51
  setup_interfaces
47
52
  end
48
53
 
54
+ # FIXME: Private method only in subclass
55
+ def layout_superclass
56
+ FFI::Struct
57
+ end
58
+
49
59
  def parent
50
60
  unless defined? @parent
51
61
  pr = info.parent
52
- if pr.nil? or (pr.name == @classname and pr.namespace == @namespace)
62
+ if pr.nil? or (pr.safe_name == @classname and pr.namespace == @namespace)
53
63
  @parent = nil
54
64
  else
55
65
  @parent = pr