gir_ffi 0.6.6 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. data/History.txt +14 -0
  2. data/TODO.rdoc +23 -5
  3. data/lib/ffi-glib/array.rb +14 -15
  4. data/lib/ffi-glib/container_class_methods.rb +0 -1
  5. data/lib/ffi-glib/hash_table.rb +3 -4
  6. data/lib/ffi-glib/ptr_array.rb +12 -4
  7. data/lib/ffi-glib/sized_array.rb +27 -7
  8. data/lib/ffi-gobject.rb +14 -15
  9. data/lib/ffi-gobject/closure.rb +1 -1
  10. data/lib/ffi-gobject/object.rb +40 -15
  11. data/lib/ffi-gobject/ruby_closure.rb +0 -1
  12. data/lib/ffi-gobject/value.rb +45 -21
  13. data/lib/ffi-gobject_introspection/i_arg_info.rb +4 -0
  14. data/lib/ffi-gobject_introspection/i_base_info.rb +42 -2
  15. data/lib/ffi-gobject_introspection/i_callable_info.rb +8 -0
  16. data/lib/ffi-gobject_introspection/i_enum_info.rb +1 -4
  17. data/lib/ffi-gobject_introspection/i_interface_info.rb +1 -0
  18. data/lib/ffi-gobject_introspection/i_object_info.rb +2 -0
  19. data/lib/ffi-gobject_introspection/i_repository.rb +2 -3
  20. data/lib/ffi-gobject_introspection/i_struct_info.rb +3 -8
  21. data/lib/ffi-gobject_introspection/lib.rb +3 -0
  22. data/lib/gir_ffi-base.rb +3 -1
  23. data/lib/gir_ffi-base/gir_ffi/struct.rb +27 -0
  24. data/lib/gir_ffi-base/glib/boolean.rb +13 -1
  25. data/lib/gir_ffi-base/gobject.rb +7 -0
  26. data/lib/gir_ffi-base/gobject/lib.rb +0 -2
  27. data/lib/gir_ffi.rb +1 -3
  28. data/lib/gir_ffi/arg_helper.rb +4 -85
  29. data/lib/gir_ffi/builder.rb +5 -5
  30. data/lib/gir_ffi/builder_helper.rb +7 -0
  31. data/lib/gir_ffi/builders/argument_builder.rb +132 -0
  32. data/lib/gir_ffi/{base_argument_builder.rb → builders/base_argument_builder.rb} +32 -41
  33. data/lib/gir_ffi/builders/base_type_builder.rb +47 -0
  34. data/lib/gir_ffi/builders/callback_builder.rb +38 -0
  35. data/lib/gir_ffi/builders/constant_builder.rb +18 -0
  36. data/lib/gir_ffi/builders/enum_builder.rb +62 -0
  37. data/lib/gir_ffi/builders/error_argument_builder.rb +18 -0
  38. data/lib/gir_ffi/builders/field_builder.rb +94 -0
  39. data/lib/gir_ffi/builders/function_builder.rb +123 -0
  40. data/lib/gir_ffi/builders/interface_builder.rb +29 -0
  41. data/lib/gir_ffi/builders/mapping_method_builder.rb +88 -0
  42. data/lib/gir_ffi/builders/module_builder.rb +124 -0
  43. data/lib/gir_ffi/{null_argument_builder.rb → builders/null_argument_builder.rb} +0 -0
  44. data/lib/gir_ffi/builders/null_builder.rb +11 -0
  45. data/lib/gir_ffi/builders/object_builder.rb +123 -0
  46. data/lib/gir_ffi/{builder/property.rb → builders/property_builder.rb} +0 -0
  47. data/lib/gir_ffi/builders/registered_type_builder.rb +50 -0
  48. data/lib/gir_ffi/builders/return_value_builder.rb +68 -0
  49. data/lib/gir_ffi/builders/signal_builder.rb +91 -0
  50. data/lib/gir_ffi/builders/struct_builder.rb +35 -0
  51. data/lib/gir_ffi/builders/type_builder.rb +40 -0
  52. data/lib/gir_ffi/builders/unintrospectable_builder.rb +35 -0
  53. data/lib/gir_ffi/builders/union_builder.rb +34 -0
  54. data/lib/gir_ffi/builders/user_defined_builder.rb +103 -0
  55. data/lib/gir_ffi/builders/with_layout.rb +55 -0
  56. data/lib/gir_ffi/builders/with_methods.rb +44 -0
  57. data/lib/gir_ffi/callback_base.rb +31 -0
  58. data/lib/gir_ffi/class_base.rb +16 -10
  59. data/lib/gir_ffi/enum_base.rb +8 -4
  60. data/lib/gir_ffi/ffi_ext/pointer.rb +19 -2
  61. data/lib/gir_ffi/in_out_pointer.rb +38 -39
  62. data/lib/gir_ffi/in_pointer.rb +33 -18
  63. data/lib/gir_ffi/info_ext.rb +0 -4
  64. data/lib/gir_ffi/info_ext/i_arg_info.rb +0 -18
  65. data/lib/gir_ffi/info_ext/i_callable_info.rb +2 -1
  66. data/lib/gir_ffi/info_ext/i_registered_type_info.rb +6 -8
  67. data/lib/gir_ffi/info_ext/i_signal_info.rb +6 -21
  68. data/lib/gir_ffi/info_ext/i_type_info.rb +54 -29
  69. data/lib/gir_ffi/info_ext/safe_constant_name.rb +8 -1
  70. data/lib/gir_ffi/interface_base.rb +1 -1
  71. data/lib/gir_ffi/module_base.rb +5 -1
  72. data/lib/gir_ffi/object_base.rb +5 -1
  73. data/lib/gir_ffi/setter_argument_info.rb +4 -0
  74. data/lib/gir_ffi/signal_base.rb +21 -0
  75. data/lib/gir_ffi/struct_base.rb +24 -0
  76. data/lib/gir_ffi/type_base.rb +11 -0
  77. data/lib/gir_ffi/type_map.rb +4 -2
  78. data/lib/gir_ffi/union_base.rb +24 -0
  79. data/lib/gir_ffi/version.rb +1 -1
  80. data/tasks/test.rake +73 -7
  81. data/test/base_test_helper.rb +3 -19
  82. data/test/ffi-glib/array_test.rb +6 -0
  83. data/test/ffi-glib/ptr_array_test.rb +13 -0
  84. data/test/ffi-glib/ruby_closure_test.rb +7 -7
  85. data/test/ffi-glib/sized_array_test.rb +2 -2
  86. data/test/ffi-gobject/gobject_test.rb +3 -12
  87. data/test/ffi-gobject/object_test.rb +33 -2
  88. data/test/ffi-gobject/value_test.rb +114 -1
  89. data/test/ffi-gobject_introspection/i_enum_info_test.rb +2 -2
  90. data/test/ffi-gobject_introspection/i_object_info_test.rb +3 -3
  91. data/test/ffi-gobject_introspection/i_repository_test.rb +26 -21
  92. data/test/ffi-gobject_test.rb +14 -14
  93. data/test/gir_ffi-base/glib/boolean_test.rb +6 -0
  94. data/test/gir_ffi/arg_helper_test.rb +2 -122
  95. data/test/gir_ffi/builder_test.rb +67 -204
  96. data/test/gir_ffi/{argument_builder_test.rb → builders/argument_builder_test.rb} +230 -108
  97. data/test/gir_ffi/builders/base_argument_builder_test.rb +5 -0
  98. data/test/gir_ffi/builders/callback_builder_test.rb +50 -0
  99. data/test/gir_ffi/builders/constant_builder_test.rb +4 -0
  100. data/test/gir_ffi/{builder/type/enum_test.rb → builders/enum_builder_test.rb} +2 -3
  101. data/test/gir_ffi/builders/field_builder_test.rb +94 -0
  102. data/test/gir_ffi/{function_builder_test.rb → builders/function_builder_test.rb} +43 -24
  103. data/test/gir_ffi/{builder/type/interface_test.rb → builders/interface_builder_test.rb} +2 -2
  104. data/test/gir_ffi/{builder/module_test.rb → builders/module_builder_test.rb} +12 -13
  105. data/test/gir_ffi/{builder/type/object_test.rb → builders/object_builder_test.rb} +9 -9
  106. data/test/gir_ffi/{return_value_builder_test.rb → builders/return_value_builder_test.rb} +94 -58
  107. data/test/gir_ffi/builders/signal_builder_test.rb +62 -0
  108. data/test/gir_ffi/{builder/type/struct_test.rb → builders/struct_builder_test.rb} +36 -19
  109. data/test/gir_ffi/{builder/type/unintrospectable_test.rb → builders/unintrospectable_builder_test.rb} +3 -3
  110. data/test/gir_ffi/builders/union_builder_test.rb +29 -0
  111. data/test/gir_ffi/{builder/type/user_defined_test.rb → builders/user_defined_builder_test.rb} +2 -2
  112. data/test/gir_ffi/callback_base_test.rb +11 -0
  113. data/test/gir_ffi/class_base_test.rb +22 -22
  114. data/test/gir_ffi/ffi_ext/pointer_test.rb +18 -0
  115. data/test/gir_ffi/in_out_pointer_test.rb +0 -7
  116. data/test/gir_ffi/in_pointer_test.rb +27 -3
  117. data/test/gir_ffi/info_ext/i_signal_info_test.rb +16 -44
  118. data/test/gir_ffi/info_ext/i_type_info_test.rb +315 -74
  119. data/test/gir_ffi/info_ext/safe_constant_name_test.rb +6 -0
  120. data/test/gir_ffi/interface_base_test.rb +3 -5
  121. data/test/gir_ffi/object_base_test.rb +10 -6
  122. data/test/gir_ffi/type_map_test.rb +2 -2
  123. data/test/gir_ffi/unintrospectable_type_info_test.rb +2 -2
  124. data/test/gir_ffi_test_helper.rb +12 -4
  125. data/test/integration/generated_gimarshallingtests_test.rb +436 -76
  126. data/test/integration/generated_gio_test.rb +5 -11
  127. data/test/integration/generated_gobject_test.rb +8 -0
  128. data/test/integration/generated_regress_test.rb +755 -309
  129. data/test/integration/generated_secret_test.rb +2 -1
  130. metadata +73 -72
  131. data/lib/ffi-gobject/ruby_style.rb +0 -23
  132. data/lib/gir_ffi/argument_builder.rb +0 -154
  133. data/lib/gir_ffi/builder/field.rb +0 -60
  134. data/lib/gir_ffi/builder/module.rb +0 -127
  135. data/lib/gir_ffi/builder/type.rb +0 -39
  136. data/lib/gir_ffi/builder/type/base.rb +0 -48
  137. data/lib/gir_ffi/builder/type/callback.rb +0 -30
  138. data/lib/gir_ffi/builder/type/constant.rb +0 -22
  139. data/lib/gir_ffi/builder/type/enum.rb +0 -66
  140. data/lib/gir_ffi/builder/type/interface.rb +0 -33
  141. data/lib/gir_ffi/builder/type/object.rb +0 -134
  142. data/lib/gir_ffi/builder/type/registered_type.rb +0 -62
  143. data/lib/gir_ffi/builder/type/struct.rb +0 -34
  144. data/lib/gir_ffi/builder/type/unintrospectable.rb +0 -39
  145. data/lib/gir_ffi/builder/type/union.rb +0 -34
  146. data/lib/gir_ffi/builder/type/user_defined.rb +0 -107
  147. data/lib/gir_ffi/builder/type/with_layout.rb +0 -62
  148. data/lib/gir_ffi/builder/type/with_methods.rb +0 -64
  149. data/lib/gir_ffi/callback.rb +0 -72
  150. data/lib/gir_ffi/callback_helper.rb +0 -11
  151. data/lib/gir_ffi/error_argument_builder.rb +0 -17
  152. data/lib/gir_ffi/function_builder.rb +0 -112
  153. data/lib/gir_ffi/info_ext/i_enum_info.rb +0 -11
  154. data/lib/gir_ffi/info_ext/i_object_info.rb +0 -11
  155. data/lib/gir_ffi/info_ext/i_struct_info.rb +0 -11
  156. data/lib/gir_ffi/info_ext/i_union_info.rb +0 -12
  157. data/lib/gir_ffi/return_value_builder.rb +0 -81
  158. data/test/ffi-gobject/ruby_style_test.rb +0 -38
  159. data/test/gir_ffi/base_argument_builder_test.rb +0 -13
  160. data/test/gir_ffi/builder/type/callback_test.rb +0 -6
  161. data/test/gir_ffi/builder/type/constant_test.rb +0 -4
  162. data/test/gir_ffi/builder/type/union_test.rb +0 -12
  163. data/test/gir_ffi/callback_helper_test.rb +0 -10
  164. data/test/gir_ffi/callback_test.rb +0 -49
  165. data/test/gir_ffi/info_ext/i_arg_info_test.rb +0 -39
  166. data/test/gir_ffi/info_ext/i_object_info_test.rb +0 -14
@@ -23,6 +23,10 @@ module GObjectIntrospection
23
23
  Lib.g_arg_info_may_be_null @gobj
24
24
  end
25
25
 
26
+ def skip?
27
+ Lib.g_arg_info_is_skip @gobj
28
+ end
29
+
26
30
  def ownership_transfer
27
31
  Lib.g_arg_info_get_ownership_transfer @gobj
28
32
  end
@@ -25,13 +25,20 @@ module GObjectIntrospection
25
25
  # of the methods returning their number and the individual elements.
26
26
  #
27
27
  # For example, given the methods +n_foos+ and +foo+(+i+), this method
28
- # will create an additional method +foos+ returning all args.
28
+ # will create an additional method +foos+ returning all foos.
29
29
  #
30
30
  # Provide the second parameter if the plural is not trivially
31
31
  # constructed by adding +s+ to the singular.
32
+ #
33
+ # Examples:
34
+ #
35
+ # build_array_method :fields
36
+ # build_array_mehtod :properties, :property
37
+ # build_array_method :get_methods
38
+ #
32
39
  def self.build_array_method method, single = nil
33
40
  method = method.to_s
34
- single ||= method[0..-2]
41
+ single ||= method.to_s[0..-2]
35
42
  count = method.sub(/^(get_)?/, "\\1n_")
36
43
  self.class_eval <<-CODE
37
44
  def #{method}
@@ -42,6 +49,38 @@ module GObjectIntrospection
42
49
  CODE
43
50
  end
44
51
 
52
+ # This is a helper method to construct a method for finding an element, out
53
+ # of the methods returning their number and the individual elements.
54
+ #
55
+ # For example, given the methods +n_foos+ and +foo+(+i+), this method will
56
+ # create an additional method +find_foo+ returning the foo with the
57
+ # matching name.
58
+ #
59
+ # Optionally provide counter and fetcher methods if they cannot be
60
+ # trivially derived from the finder method.
61
+ #
62
+ # Examples:
63
+ #
64
+ # build_finder_method :find_field
65
+ # build_finder_method :find_property, :n_properties
66
+ # build_finder_method :find_method, :get_n_methods, :get_method
67
+ #
68
+ def self.build_finder_method method, counter = nil, fetcher = nil
69
+ method = method.to_s
70
+ single = method.sub(/^find_/, "")
71
+ counter ||= "n_#{single}s"
72
+ fetcher ||= "#{single}"
73
+ self.class_eval <<-CODE
74
+ def #{method}(name)
75
+ (0..(#{counter} - 1)).each do |i|
76
+ it = #{fetcher}(i)
77
+ return it if it.name == name
78
+ end
79
+ nil
80
+ end
81
+ CODE
82
+ end
83
+
45
84
  def name
46
85
  Lib.g_base_info_get_name @gobj
47
86
  end
@@ -60,6 +99,7 @@ module GObjectIntrospection
60
99
 
61
100
  def container
62
101
  ptr = Lib.g_base_info_get_container @gobj
102
+ Lib.g_base_info_ref ptr
63
103
  IRepository.wrap_ibaseinfo_pointer ptr
64
104
  end
65
105
 
@@ -9,20 +9,28 @@ module GObjectIntrospection
9
9
  def return_type
10
10
  ITypeInfo.wrap(Lib.g_callable_info_get_return_type @gobj)
11
11
  end
12
+
12
13
  def caller_owns
13
14
  Lib.g_callable_info_get_caller_owns @gobj
14
15
  end
16
+
15
17
  def may_return_null?
16
18
  Lib.g_callable_info_may_return_null @gobj
17
19
  end
20
+
18
21
  def n_args
19
22
  Lib.g_callable_info_get_n_args @gobj
20
23
  end
24
+
21
25
  def arg(index)
22
26
  IArgInfo.wrap(Lib.g_callable_info_get_arg @gobj, index)
23
27
  end
24
28
  ##
25
29
  build_array_method :args
30
+
31
+ def skip_return?
32
+ Lib.g_callable_info_skip_return @gobj
33
+ end
26
34
  end
27
35
  end
28
36
 
@@ -20,10 +20,7 @@ module GObjectIntrospection
20
20
 
21
21
  ##
22
22
  build_array_method :get_methods
23
-
24
- def find_method name
25
- get_methods.find {|m| m.name == name}
26
- end
23
+ build_finder_method :find_method, :get_n_methods, :get_method
27
24
 
28
25
  def storage_type
29
26
  Lib.g_enum_info_get_storage_type @gobj
@@ -41,6 +41,7 @@ module GObjectIntrospection
41
41
  end
42
42
  ##
43
43
  build_array_method :signals
44
+ build_finder_method :find_signal
44
45
 
45
46
  def n_vfuncs
46
47
  Lib.g_interface_info_get_n_vfuncs @gobj
@@ -48,6 +48,7 @@ module GObjectIntrospection
48
48
  end
49
49
  ##
50
50
  build_array_method :properties, :property
51
+ build_finder_method :find_property, :n_properties
51
52
 
52
53
  def get_n_methods
53
54
  Lib.g_object_info_get_n_methods @gobj
@@ -72,6 +73,7 @@ module GObjectIntrospection
72
73
  end
73
74
  ##
74
75
  build_array_method :signals
76
+ build_finder_method :find_signal
75
77
 
76
78
  def n_vfuncs
77
79
  Lib.g_object_info_get_n_vfuncs @gobj
@@ -23,7 +23,7 @@ require 'ffi-gobject_introspection/i_enum_info'
23
23
  require 'ffi-gobject_introspection/i_flags_info'
24
24
 
25
25
  module GObjectIntrospection
26
- GObject::Lib::g_type_init
26
+ GObject.type_init
27
27
 
28
28
  # The Gobject Introspection Repository. This class is the point of
29
29
  # access to the introspection typelibs.
@@ -54,8 +54,6 @@ module GObjectIntrospection
54
54
  :unresolved => IBaseInfo
55
55
  }
56
56
 
57
- POINTER_SIZE = FFI.type_size(:pointer)
58
-
59
57
  def initialize
60
58
  @gobj = Lib::g_irepository_get_default
61
59
  end
@@ -105,6 +103,7 @@ module GObjectIntrospection
105
103
  end
106
104
 
107
105
  def find_by_gtype gtype
106
+ raise ArgumentError, "Type #{gtype} is not a valid type" if gtype == 0
108
107
  ptr = Lib.g_irepository_find_by_gtype @gobj, gtype
109
108
  return wrap ptr
110
109
  end
@@ -11,6 +11,7 @@ module GObjectIntrospection
11
11
 
12
12
  ##
13
13
  build_array_method :fields
14
+ build_finder_method :find_field
14
15
 
15
16
  def get_n_methods
16
17
  Lib.g_struct_info_get_n_methods @gobj
@@ -21,14 +22,8 @@ module GObjectIntrospection
21
22
 
22
23
  ##
23
24
  build_array_method :get_methods
24
-
25
- def find_method(name)
26
- method_map[name]
27
- end
28
-
29
- def method_map
30
- @method_map ||= Hash[get_methods.map {|mthd| [mthd.name, mthd] }]
31
- end
25
+ # There is a function g_object_info_find_method but it causes a core dump.
26
+ build_finder_method :find_method, :get_n_methods, :get_method
32
27
 
33
28
  def size
34
29
  Lib.g_struct_info_get_size @gobj
@@ -49,6 +49,7 @@ module GObjectIntrospection
49
49
  :unresolved
50
50
  ]
51
51
 
52
+ attach_function :g_base_info_ref, [:pointer], :void
52
53
  attach_function :g_base_info_unref, [:pointer], :void
53
54
  attach_function :g_base_info_get_type, [:pointer], :IInfoType
54
55
  attach_function :g_base_info_get_name, [:pointer], :string
@@ -74,6 +75,7 @@ module GObjectIntrospection
74
75
  attach_function :g_callable_info_may_return_null, [:pointer], :bool
75
76
  attach_function :g_callable_info_get_n_args, [:pointer], :int
76
77
  attach_function :g_callable_info_get_arg, [:pointer, :int], :pointer
78
+ attach_function :g_callable_info_skip_return, [:pointer], :bool
77
79
 
78
80
  # IArgInfo
79
81
  enum :IDirection, [
@@ -93,6 +95,7 @@ module GObjectIntrospection
93
95
  attach_function :g_arg_info_is_return_value, [:pointer], :bool
94
96
  attach_function :g_arg_info_is_optional, [:pointer], :bool
95
97
  attach_function :g_arg_info_is_caller_allocates, [:pointer], :bool
98
+ attach_function :g_arg_info_is_skip, [:pointer], :bool
96
99
  attach_function :g_arg_info_may_be_null, [:pointer], :bool
97
100
  attach_function :g_arg_info_get_ownership_transfer, [:pointer], :ITransfer
98
101
  attach_function :g_arg_info_get_scope, [:pointer], :IScopeType
data/lib/gir_ffi-base.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # This section contains code that is needed by GObjectIntrospection, but
2
2
  # belongs in modules that can only be created fully once GObjectIntrospection
3
3
  # is fully loaded.
4
+ require 'gir_ffi-base/gir_ffi/library'
5
+ require 'gir_ffi-base/gir_ffi/struct'
4
6
  require 'gir_ffi-base/glib/boolean'
5
7
  require 'gir_ffi-base/glib/strv'
6
- require 'gir_ffi-base/gobject/lib'
8
+ require 'gir_ffi-base/gobject'
@@ -0,0 +1,27 @@
1
+ module GirFFI
2
+ class Struct < FFI::Struct
3
+ extend FFI::DataConverter
4
+
5
+ def self.native_type
6
+ FFI::Type::Struct.new(self)
7
+ end
8
+
9
+ def self.to_native value, context
10
+ value
11
+ end
12
+
13
+ def self.from_native value, context
14
+ value
15
+ end
16
+
17
+ # TODO: Find method to directly copy bytes, rather than reading and
18
+ # putting them.
19
+ def self.copy_value_to_pointer value, pointer, offset=0
20
+ pointer.put_bytes offset, value.to_ptr.read_bytes(size), 0, size
21
+ end
22
+
23
+ def self.get_value_from_pointer pointer
24
+ pointer.to_ptr
25
+ end
26
+ end
27
+ end
@@ -4,7 +4,7 @@ module GLib
4
4
  # Implementation of gboolean
5
5
  class Boolean
6
6
  extend FFI::DataConverter
7
- native_type :int #FFI::Type::INT
7
+ native_type FFI::Type::INT
8
8
 
9
9
  def self.from_native value, context
10
10
  value != 0 ? true : false
@@ -13,5 +13,17 @@ module GLib
13
13
  def self.to_native value, context
14
14
  value ? 1 : 0
15
15
  end
16
+
17
+ def self.size
18
+ FFI.type_size FFI::Type::INT
19
+ end
20
+
21
+ def self.copy_value_to_pointer value, pointer
22
+ pointer.put_int 0, to_native(value, nil)
23
+ end
24
+
25
+ def self.get_value_from_pointer pointer
26
+ from_native pointer.get_int(0), nil
27
+ end
16
28
  end
17
29
  end
@@ -0,0 +1,7 @@
1
+ require 'gir_ffi-base/gobject/lib'
2
+
3
+ module GObject
4
+ def self.type_init
5
+ Lib::g_type_init
6
+ end
7
+ end
@@ -1,5 +1,3 @@
1
- require 'gir_ffi-base/gir_ffi/library'
2
-
3
1
  module GObject
4
2
  module Lib
5
3
  extend GirFFI::Library
data/lib/gir_ffi.rb CHANGED
@@ -12,8 +12,6 @@ require 'gir_ffi/in_pointer'
12
12
  require 'gir_ffi/in_out_pointer'
13
13
  require 'gir_ffi/zero_terminated'
14
14
  require 'gir_ffi/arg_helper'
15
- require 'gir_ffi/callback'
16
- require 'gir_ffi/callback_helper'
17
15
  require 'gir_ffi/builder'
18
16
 
19
17
  module GirFFI
@@ -24,7 +22,7 @@ module GirFFI
24
22
 
25
23
  def self.define_type klass, &block
26
24
  info = UserDefinedTypeInfo.new(klass, &block)
27
- Builder::Type::UserDefined.new(info).build_class
25
+ Builders::UserDefinedBuilder.new(info).build_class
28
26
 
29
27
  klass.get_gtype
30
28
  end
@@ -1,79 +1,13 @@
1
1
  require 'gir_ffi/allocation_helper'
2
- require 'gir_ffi/callback_helper'
3
2
  require 'gir_ffi/builder'
4
3
 
5
4
  module GirFFI
6
5
  module ArgHelper
7
6
  OBJECT_STORE = {}
8
7
 
9
- POINTER_SIZE = FFI.type_size(:pointer)
10
-
11
- SIMPLE_G_TYPES = [
12
- :gint8, :gint16, :gint, :gint32, :gint64,
13
- :guint8, :guint16, :guint32, :guint64,
14
- :gfloat, :gdouble
15
- ]
16
-
17
- # FIXME: Hideous
18
- # TODO: Move this implementation to InPointer
19
- def self.object_to_inptr obj
20
- return nil if obj.nil?
21
- return obj.to_ptr if obj.respond_to? :to_ptr
22
- return obj if obj.is_a? FFI::Pointer
23
-
24
- FFI::Pointer.new(obj.object_id).tap {|ptr|
25
- OBJECT_STORE[ptr.address] = obj }
26
- end
27
-
28
- def self.ptr_to_typed_array type, ptr, size
29
- return [] if ptr.nil? or ptr.null?
30
-
31
- case type
32
- when Class
33
- ptr_to_interface_array type, ptr, size
34
- when Module
35
- ptr_to_enum_array type, ptr, size
36
- when Array
37
- ptr_to_interface_pointer_array type[1], ptr, size
38
- when :utf8
39
- ptr_to_utf8_array ptr, size
40
- else
41
- ffi_type = TypeMap.map_basic_type type
42
- ptr.send "get_array_of_#{ffi_type}", 0, size
43
- end
44
- end
45
-
46
- def self.ptr_to_utf8_array ptr, size
47
- ptrs = ptr.read_array_of_pointer(size)
48
- ptrs.map { |pt| ptr_to_utf8 pt }
49
- end
50
-
51
- def self.ptr_to_interface_array klass, ptr, size
52
- struct_size = klass::Struct.size
53
- size.times.map do |idx|
54
- klass.wrap(ptr + struct_size * idx)
55
- end
56
- end
57
-
58
- def self.ptr_to_interface_pointer_array klass, ptr, size
59
- ptrs = ptr.read_array_of_pointer(size)
60
- ptrs.map do |optr|
61
- klass.wrap(optr)
62
- end
63
- end
64
-
65
- def self.ptr_to_enum_array enum, ptr, size
66
- ptr.get_array_of_int32(0, size).map {|val| enum[val] }
67
- end
68
-
69
- if RUBY_VERSION < "1.9"
70
- def self.ptr_to_utf8 ptr
71
- ptr.null? ? nil : ptr.read_string
72
- end
73
- else
74
- def self.ptr_to_utf8 ptr
75
- ptr.null? ? nil : ptr.read_string.force_encoding("utf-8")
76
- end
8
+ # @deprecated Compatibility function. Remove in 0.7.0.
9
+ def self.ptr_to_utf8 ptr
10
+ ptr.to_utf8
77
11
  end
78
12
 
79
13
  def self.ptr_to_utf8_length ptr, len
@@ -91,25 +25,10 @@ module GirFFI
91
25
  end
92
26
  end
93
27
 
94
- def self.allocate_array_of_type type, length
95
- AllocationHelper.safe_malloc FFI.type_size(type) * length
96
- end
97
-
98
- def self.object_pointer_to_object optr
99
- gtype = GObject.type_from_instance_pointer optr
100
- wrap_object_pointer_by_gtype optr, gtype
101
- end
102
-
103
- def self.wrap_object_pointer_by_gtype optr, gtype
104
- return nil if optr.null?
105
- klass = Builder.build_by_gtype gtype
106
- klass.direct_wrap optr
107
- end
108
-
109
28
  def self.cast_from_pointer type, it
110
29
  case type
111
30
  when :utf8, :filename
112
- ptr_to_utf8 it
31
+ it.to_utf8
113
32
  when :gint32
114
33
  cast_pointer_to_int32 it
115
34
  else
@@ -1,5 +1,5 @@
1
- require 'gir_ffi/builder/type'
2
- require 'gir_ffi/builder/module'
1
+ require 'gir_ffi/builders/type_builder'
2
+ require 'gir_ffi/builders/module_builder'
3
3
  require 'gir_ffi/builder_helper'
4
4
  require 'gir_ffi/unintrospectable_type_info'
5
5
 
@@ -11,7 +11,7 @@ module GirFFI
11
11
  extend BuilderHelper
12
12
 
13
13
  def self.build_class info
14
- Builder::Type.build(info)
14
+ Builders::TypeBuilder.build(info)
15
15
  end
16
16
 
17
17
  def self.build_by_gtype gtype
@@ -22,10 +22,10 @@ module GirFFI
22
22
  end
23
23
 
24
24
  def self.build_module namespace, version=nil
25
- Builder::Module.new(namespace, version).generate
25
+ Builders::ModuleBuilder.new(namespace, version).generate
26
26
  end
27
27
 
28
- # TODO: Move elsewhere, perhaps to Builder::Function.
28
+ # TODO: Move elsewhere, perhaps to FunctionBuilder.
29
29
  def self.attach_ffi_function lib, info
30
30
  sym = info.symbol
31
31
  return if lib.method_defined? sym