gir_ffi 0.0.14 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/History.txt +6 -0
  2. data/README.rdoc +36 -12
  3. data/examples/01_empty_window.rb +1 -3
  4. data/examples/02_hello_world.rb +1 -3
  5. data/examples/03_upgraded_hello_world.rb +1 -3
  6. data/examples/04_webkit.rb +2 -2
  7. data/examples/05_notification.rb +1 -2
  8. data/examples/print_class.rb +6 -4
  9. data/lib/ffi-glib.rb +107 -0
  10. data/lib/ffi-glib/array.rb +14 -0
  11. data/lib/ffi-glib/byte_array.rb +10 -0
  12. data/lib/ffi-glib/hash_table.rb +55 -0
  13. data/lib/ffi-glib/list.rb +9 -0
  14. data/lib/ffi-glib/list_methods.rb +31 -0
  15. data/lib/ffi-glib/s_list.rb +9 -0
  16. data/lib/ffi-gobject.rb +94 -0
  17. data/lib/ffi-gobject/closure.rb +12 -0
  18. data/lib/ffi-gobject/helper.rb +119 -0
  19. data/lib/ffi-gobject/initially_unowned.rb +10 -0
  20. data/lib/ffi-gobject/ruby_closure.rb +47 -0
  21. data/lib/ffi-gobject/value.rb +65 -0
  22. data/lib/ffi-gobject_introspection.rb +3 -0
  23. data/lib/{gir_ffi → ffi-gobject_introspection}/g_error.rb +1 -1
  24. data/lib/ffi-gobject_introspection/gobject_lib.rb +7 -0
  25. data/lib/{gir_ffi → ffi-gobject_introspection}/i_arg_info.rb +2 -2
  26. data/lib/{gir_ffi → ffi-gobject_introspection}/i_base_info.rb +1 -1
  27. data/lib/{gir_ffi → ffi-gobject_introspection}/i_callable_info.rb +4 -4
  28. data/lib/{gir_ffi → ffi-gobject_introspection}/i_callback_info.rb +1 -1
  29. data/lib/{gir_ffi → ffi-gobject_introspection}/i_constant_info.rb +2 -3
  30. data/lib/{gir_ffi → ffi-gobject_introspection}/i_enum_info.rb +1 -1
  31. data/lib/{gir_ffi → ffi-gobject_introspection}/i_field_info.rb +1 -1
  32. data/lib/{gir_ffi → ffi-gobject_introspection}/i_flags_info.rb +1 -1
  33. data/lib/{gir_ffi → ffi-gobject_introspection}/i_function_info.rb +1 -1
  34. data/lib/{gir_ffi → ffi-gobject_introspection}/i_interface_info.rb +1 -1
  35. data/lib/{gir_ffi → ffi-gobject_introspection}/i_object_info.rb +1 -1
  36. data/lib/{gir_ffi → ffi-gobject_introspection}/i_property_info.rb +1 -1
  37. data/lib/{gir_ffi → ffi-gobject_introspection}/i_registered_type_info.rb +1 -1
  38. data/lib/{gir_ffi → ffi-gobject_introspection}/i_repository.rb +37 -23
  39. data/lib/{gir_ffi → ffi-gobject_introspection}/i_signal_info.rb +1 -1
  40. data/lib/{gir_ffi → ffi-gobject_introspection}/i_struct_info.rb +1 -1
  41. data/lib/{gir_ffi → ffi-gobject_introspection}/i_type_info.rb +2 -2
  42. data/lib/{gir_ffi → ffi-gobject_introspection}/i_union_info.rb +1 -1
  43. data/lib/{gir_ffi → ffi-gobject_introspection}/i_value_info.rb +1 -1
  44. data/lib/{gir_ffi → ffi-gobject_introspection}/i_vfunc_info.rb +1 -1
  45. data/lib/{gir_ffi → ffi-gobject_introspection}/lib.rb +1 -1
  46. data/lib/ffi-gtk/base.rb +17 -0
  47. data/lib/ffi-gtk2.rb +5 -0
  48. data/lib/ffi-gtk3.rb +5 -0
  49. data/lib/gir_ffi.rb +11 -4
  50. data/lib/gir_ffi/arg_helper.rb +5 -4
  51. data/lib/gir_ffi/builder.rb +3 -25
  52. data/lib/gir_ffi/builder/argument.rb +0 -2
  53. data/lib/gir_ffi/builder/argument/hash_table_base.rb +1 -1
  54. data/lib/gir_ffi/builder/argument/list_base.rb +1 -1
  55. data/lib/gir_ffi/builder/module.rb +1 -6
  56. data/lib/gir_ffi/builder/type/unintrospectable.rb +1 -1
  57. data/lib/gir_ffi/callback_helper.rb +14 -7
  58. data/lib/gir_ffi/in_out_pointer.rb +1 -1
  59. data/lib/gir_ffi/in_pointer.rb +1 -1
  60. data/lib/gir_ffi/module_base.rb +4 -0
  61. data/lib/gir_ffi/type_map.rb +29 -0
  62. data/lib/gir_ffi/version.rb +1 -1
  63. data/tasks/test.rake +20 -1
  64. data/test/arg_helper_test.rb +10 -13
  65. data/test/builder_test.rb +2 -2
  66. data/test/class_base_test.rb +1 -1
  67. data/test/{glib_overrides_test.rb → ffi-glib/glib_overrides_test.rb} +3 -5
  68. data/test/{g_object_overrides_test.rb → ffi-gobject/g_object_overrides_test.rb} +7 -37
  69. data/test/ffi-gobject/gobject_test.rb +22 -0
  70. data/test/ffi-gobject/value_test.rb +34 -0
  71. data/test/{unit → ffi-gobject_introspection}/i_base_info_test.rb +2 -2
  72. data/test/{unit → ffi-gobject_introspection}/i_constant_info_test.rb +1 -1
  73. data/test/ffi-gobject_introspection/i_object_info_test.rb +20 -0
  74. data/test/{unit → ffi-gobject_introspection}/i_repository_test.rb +11 -11
  75. data/test/function_definition_builder_test.rb +1 -1
  76. data/test/gir_ffi_test_helper.rb +114 -0
  77. data/test/girffi_test.rb +2 -2
  78. data/test/gtk_overrides_test.rb +15 -12
  79. data/test/integration/generated_gimarshallingtests_test.rb +10 -5
  80. data/test/integration/generated_gio_test.rb +1 -1
  81. data/test/integration/generated_gobject_test.rb +1 -1
  82. data/test/integration/generated_gtk_test.rb +3 -3
  83. data/test/integration/generated_regress_test.rb +11 -3
  84. data/test/interface_type_builder_test.rb +1 -1
  85. data/test/module_builder_test.rb +1 -1
  86. data/test/test_helper.rb +2 -111
  87. data/test/type_builder_test.rb +2 -2
  88. data/test/unintrospectable_type_builder_test.rb +1 -1
  89. data/test/unit/builder_test.rb +1 -1
  90. data/test/unit/callback_helper_test.rb +13 -10
  91. data/test/unit/constant_builder_test.rb +1 -1
  92. data/test/unit/in_out_pointer_test.rb +1 -1
  93. data/test/unit/in_pointer_test.rb +1 -1
  94. data/test/unit/object_type_builder_test.rb +1 -1
  95. metadata +62 -43
  96. data/lib/gir_ffi/g_object.rb +0 -38
  97. data/lib/gir_ffi/overrides/glib.rb +0 -225
  98. data/lib/gir_ffi/overrides/gobject.rb +0 -330
  99. data/lib/gir_ffi/overrides/gtk.rb +0 -29
  100. data/test/g_object_test.rb +0 -21
  101. data/test/i_object_info_test.rb +0 -20
@@ -1,4 +1,4 @@
1
- module GirFFI
1
+ module GObjectIntrospection
2
2
  # Wraps a GISignalInfo struct.
3
3
  # Represents a signal.
4
4
  # Not implemented yet.
@@ -1,4 +1,4 @@
1
- module GirFFI
1
+ module GObjectIntrospection
2
2
  # Wraps a GIStructInfo struct.
3
3
  # Represents a struct.
4
4
  class IStructInfo < IRegisteredTypeInfo
@@ -1,4 +1,4 @@
1
- module GirFFI
1
+ module GObjectIntrospection
2
2
  # Wraps a GITypeInfo struct.
3
3
  # Represents type information, direction, transfer etc.
4
4
  class ITypeInfo < IBaseInfo
@@ -33,7 +33,7 @@ module GirFFI
33
33
  end
34
34
 
35
35
  def name
36
- raise "Should not call this for gir 0.6.5 ..."
36
+ raise "Should not call this for ITypeInfo"
37
37
  end
38
38
  end
39
39
  end
@@ -1,4 +1,4 @@
1
- module GirFFI
1
+ module GObjectIntrospection
2
2
  # Wraps a GIUnionInfo struct.
3
3
  # Represents a union.
4
4
  # Not implemented yet.
@@ -1,4 +1,4 @@
1
- module GirFFI
1
+ module GObjectIntrospection
2
2
  # Wraps a GIValueInfo struct.
3
3
  # Represents one of the enum values of an IEnumInfo.
4
4
  class IValueInfo < IBaseInfo
@@ -1,4 +1,4 @@
1
- module GirFFI
1
+ module GObjectIntrospection
2
2
  # Wraps a GIVFuncInfo struct.
3
3
  # Represents a virtual function.
4
4
  class IVFuncInfo < IBaseInfo
@@ -1,6 +1,6 @@
1
1
  require 'ffi'
2
2
 
3
- module GirFFI
3
+ module GObjectIntrospection
4
4
  module Lib
5
5
  extend FFI::Library
6
6
  ffi_lib "girepository-1.0"
@@ -0,0 +1,17 @@
1
+ module Gtk
2
+ _setup_method "init"
3
+
4
+ def self.init_with_auto_argv
5
+ my_args = init_without_auto_argv [$0, *ARGV]
6
+ my_args.shift
7
+ ARGV.replace my_args
8
+ end
9
+ class << self
10
+ alias init_without_auto_argv init
11
+ alias init init_with_auto_argv
12
+ end
13
+ end
14
+
15
+ Gtk.class_eval do
16
+ end
17
+
@@ -0,0 +1,5 @@
1
+ require 'gir_ffi'
2
+
3
+ GirFFI.setup :Gtk, '2.0'
4
+
5
+ require 'ffi-gtk/base'
@@ -0,0 +1,5 @@
1
+ require 'gir_ffi'
2
+
3
+ GirFFI.setup :Gtk, '3.0'
4
+
5
+ require 'ffi-gtk/base'
@@ -1,12 +1,19 @@
1
- require 'gir_ffi/g_object'
2
- require 'gir_ffi/i_repository'
1
+ require 'ffi'
2
+
3
+ require 'gir_ffi/class_base'
4
+ require 'gir_ffi/type_map'
5
+
6
+ require 'ffi-gobject_introspection'
7
+
8
+ require 'gir_ffi/arg_helper'
3
9
  require 'gir_ffi/builder'
4
10
 
5
11
  module GirFFI
6
- GObject.type_init
7
-
8
12
  def self.setup module_name, version=nil
9
13
  module_name = module_name.to_s
10
14
  GirFFI::Builder.build_module module_name, version
11
15
  end
12
16
  end
17
+
18
+ require 'ffi-glib'
19
+ require 'ffi-gobject'
@@ -53,14 +53,14 @@ module GirFFI
53
53
  if type == :utf8
54
54
  ptr_to_utf8_array ptr, size
55
55
  else
56
- ffi_type = GirFFI::Builder::TAG_TYPE_MAP[type] || type
56
+ ffi_type = TypeMap.map_basic_type type
57
57
  ptr.send "get_array_of_#{ffi_type}", 0, size
58
58
  end
59
59
  end
60
60
 
61
61
  def self.setup_ptr_to_type_array_handler_for *types
62
62
  types.flatten.each do |type|
63
- ffi_type = GirFFI::Builder::TAG_TYPE_MAP[type] || type
63
+ ffi_type = TypeMap.map_basic_type type
64
64
  defn =
65
65
  "def self.ptr_to_#{type}_array ptr, size
66
66
  ptr.get_array_of_#{ffi_type}(0, size)
@@ -74,7 +74,7 @@ module GirFFI
74
74
  def self.ptr_to_utf8_array ptr, size
75
75
  ptrs = ptr.read_array_of_pointer(size)
76
76
 
77
- ptrs.map { |ptr| ptr_to_utf8 ptr }
77
+ ptrs.map { |pt| ptr_to_utf8 pt }
78
78
  end
79
79
 
80
80
  def self.ptr_to_interface_array klass, ptr, size
@@ -160,7 +160,8 @@ module GirFFI
160
160
 
161
161
  def self.check_error errpp
162
162
  errp = errpp.read_pointer
163
- raise GError.new(errp)[:message] unless errp.null?
163
+ # FIXME: Do not depend on GError from GObjectIntrospection namespace.
164
+ raise GObjectIntrospection::GError.new(errp)[:message] unless errp.null?
164
165
  end
165
166
 
166
167
  def self.check_fixed_array_size size, arr, name
@@ -10,34 +10,12 @@ module GirFFI
10
10
  module Builder
11
11
  extend BuilderHelper
12
12
 
13
- sz = FFI.type_size(:size_t) * 8
14
- gtype_type = "uint#{sz}".to_sym
15
-
16
- TAG_TYPE_MAP = {
17
- :GType => :size_t,
18
- :gtype => gtype_type,
19
- :gboolean => :bool,
20
- :gunichar => :uint32,
21
- :gint8 => :int8,
22
- :guint8 => :uint8,
23
- :gint16 => :int16,
24
- :guint16 => :uint16,
25
- :gint => :int,
26
- :gint32 => :int32,
27
- :guint32 => :uint32,
28
- :gint64 => :int64,
29
- :guint64 => :uint64,
30
- :gfloat => :float,
31
- :gdouble => :double,
32
- :void => :void
33
- }
34
-
35
13
  def self.build_class info
36
14
  Builder::Type.build(info)
37
15
  end
38
16
 
39
17
  def self.build_by_gtype gtype
40
- info = IRepository.default.find_by_gtype gtype
18
+ info = GObjectIntrospection::IRepository.default.find_by_gtype gtype
41
19
  if info.nil?
42
20
  Builder::Type::Unintrospectable.new(gtype).build_class
43
21
  else
@@ -100,7 +78,7 @@ module GirFFI
100
78
  :pointer
101
79
  end
102
80
  else
103
- return TAG_TYPE_MAP[tag] || tag
81
+ return TypeMap.map_basic_type tag
104
82
  end
105
83
  end
106
84
 
@@ -111,7 +89,7 @@ module GirFFI
111
89
  if tag == :interface
112
90
  return build_class info.interface
113
91
  else
114
- return TAG_TYPE_MAP[tag] || tag
92
+ return TypeMap.map_basic_type tag
115
93
  end
116
94
  end
117
95
 
@@ -450,8 +450,6 @@ module GirFFI::Builder
450
450
 
451
451
  # Implements argument processing for return values.
452
452
  class ReturnValue < Argument::Base
453
- attr_reader :cvar
454
-
455
453
  def cvar
456
454
  @cvar ||= @function_builder.new_var
457
455
  end
@@ -10,7 +10,7 @@ module GirFFI
10
10
  end
11
11
 
12
12
  def val_t
13
- val_t = subtype_tag(1).inspect
13
+ subtype_tag(1).inspect
14
14
  end
15
15
  end
16
16
  end
@@ -7,7 +7,7 @@ module GirFFI
7
7
  private
8
8
 
9
9
  def elm_t
10
- elm_t = subtype_tag.inspect
10
+ subtype_tag.inspect
11
11
  end
12
12
  end
13
13
  end
@@ -74,11 +74,6 @@ module GirFFI
74
74
  def setup_module
75
75
  @module.extend ModuleBase
76
76
  @module.const_set :GIR_FFI_BUILDER, self
77
- begin
78
- require "gir_ffi/overrides/#{@namespace.downcase}"
79
- @module.class_eval "include GirFFI::Overrides::#{@namespace}"
80
- rescue LoadError
81
- end
82
77
  end
83
78
 
84
79
  def already_set_up
@@ -112,7 +107,7 @@ module GirFFI
112
107
 
113
108
  def gir
114
109
  unless defined? @gir
115
- @gir = IRepository.default
110
+ @gir = GObjectIntrospection::IRepository.default
116
111
  @gir.require @namespace, @version
117
112
  end
118
113
  @gir
@@ -54,7 +54,7 @@ module GirFFI
54
54
  end
55
55
 
56
56
  def gir
57
- @gir ||= GirFFI::IRepository.default
57
+ @gir ||= GObjectIntrospection::IRepository.default
58
58
  end
59
59
  end
60
60
  end
@@ -3,7 +3,7 @@ module GirFFI
3
3
  def self.wrap_in_callback_args_mapper namespace, name, prc
4
4
  return prc if FFI::Function === prc
5
5
  return nil if prc.nil?
6
- info = IRepository.default.find_by_name namespace, name
6
+ info = GObjectIntrospection::IRepository.default.find_by_name namespace, name
7
7
  return Proc.new do |*args|
8
8
  prc.call(*map_callback_args(args, info))
9
9
  end
@@ -11,25 +11,32 @@ module GirFFI
11
11
 
12
12
  def self.map_callback_args args, info
13
13
  args.zip(info.args).map { |arg, inf|
14
- map_single_callback_arg arg, inf }
14
+ map_single_callback_arg arg, inf.argument_type }
15
15
  end
16
16
 
17
17
  # TODO: Use GirFFI::ReturnValue classes for mapping.
18
- def self.map_single_callback_arg arg, info
19
- case info.argument_type.tag
18
+ def self.map_single_callback_arg arg, type
19
+ case type.tag
20
20
  when :interface
21
- map_interface_callback_arg arg, info
21
+ map_interface_callback_arg arg, type
22
22
  when :utf8
23
23
  ArgHelper.ptr_to_utf8 arg
24
24
  when :void
25
25
  map_void_callback_arg arg
26
+ when :array
27
+ subtype = type.param_type(0)
28
+ if subtype.tag == :interface and arg.is_a?(FFI::Pointer)
29
+ map_interface_callback_arg arg, subtype
30
+ else
31
+ raise NotImplementedError
32
+ end
26
33
  else
27
34
  arg
28
35
  end
29
36
  end
30
37
 
31
- def self.map_interface_callback_arg arg, info
32
- iface = info.argument_type.interface
38
+ def self.map_interface_callback_arg arg, type
39
+ iface = type.interface
33
40
  case iface.info_type
34
41
  when :object
35
42
  ArgHelper.object_pointer_to_object arg
@@ -56,7 +56,7 @@ module GirFFI
56
56
  when :utf8
57
57
  :pointer
58
58
  else
59
- GirFFI::Builder::TAG_TYPE_MAP[type] || type
59
+ TypeMap.map_basic_type type
60
60
  end
61
61
  end
62
62
 
@@ -8,7 +8,7 @@ module GirFFI
8
8
  return from_utf8_array ary if type == :utf8
9
9
  return from_interface_pointer_array ary if type == :interface_pointer
10
10
 
11
- ffi_type = GirFFI::Builder::TAG_TYPE_MAP[type] || type
11
+ ffi_type = TypeMap.map_basic_type type
12
12
  block = ArgHelper.allocate_array_of_type ffi_type, ary.length
13
13
  block.send "put_array_of_#{ffi_type}", 0, ary
14
14
 
@@ -12,6 +12,10 @@ module GirFFI
12
12
  klass
13
13
  end
14
14
 
15
+ def load_class classname
16
+ _builder.build_namespaced_class classname.to_s
17
+ end
18
+
15
19
  def _builder
16
20
  self.const_get :GIR_FFI_BUILDER
17
21
  end
@@ -0,0 +1,29 @@
1
+ module GirFFI
2
+ module TypeMap
3
+ sz = FFI.type_size(:size_t) * 8
4
+ gtype_type = "uint#{sz}".to_sym
5
+
6
+ TAG_TYPE_MAP = {
7
+ :GType => :size_t,
8
+ :gtype => gtype_type,
9
+ :gboolean => :bool,
10
+ :gunichar => :uint32,
11
+ :gint8 => :int8,
12
+ :guint8 => :uint8,
13
+ :gint16 => :int16,
14
+ :guint16 => :uint16,
15
+ :gint => :int,
16
+ :gint32 => :int32,
17
+ :guint32 => :uint32,
18
+ :gint64 => :int64,
19
+ :guint64 => :uint64,
20
+ :gfloat => :float,
21
+ :gdouble => :double,
22
+ :void => :void
23
+ }
24
+
25
+ def self.map_basic_type type
26
+ TAG_TYPE_MAP[type] || type
27
+ end
28
+ end
29
+ end
@@ -1,4 +1,4 @@
1
1
  module GirFFI
2
- VERSION = "0.0.14"
2
+ VERSION = "0.1.0"
3
3
  end
4
4
 
@@ -20,6 +20,24 @@ namespace :test do
20
20
  t.ruby_opts += ["-w"]
21
21
  end
22
22
 
23
+ Rake::TestTask.new(:gobjectintrospection) do |t|
24
+ t.libs = ['lib']
25
+ t.test_files = FileList['test/ffi-gobject_introspection/*_test.rb']
26
+ t.ruby_opts += ["-w"]
27
+ end
28
+
29
+ Rake::TestTask.new(:glib) do |t|
30
+ t.libs = ['lib']
31
+ t.test_files = FileList['test/ffi-glib/*_test.rb']
32
+ t.ruby_opts += ["-w"]
33
+ end
34
+
35
+ Rake::TestTask.new(:gobject) do |t|
36
+ t.libs = ['lib']
37
+ t.test_files = FileList['test/ffi-gobject/*_test.rb']
38
+ t.ruby_opts += ["-w"]
39
+ end
40
+
23
41
  desc 'Build Regress test library and typelib'
24
42
  task :lib => "test/lib/Makefile" do
25
43
  sh %{cd test/lib && make}
@@ -44,4 +62,5 @@ file "test/lib/configure" do
44
62
  end
45
63
 
46
64
  desc 'Run unit an integration tests'
47
- task :test => ['test:unit', 'test:run', 'test:integration']
65
+ task :test => ['test:gobjectintrospection',
66
+ 'test:unit', 'test:run', 'test:glib', 'test:gobject', 'test:integration']
@@ -1,4 +1,4 @@
1
- require File.expand_path('test_helper.rb', File.dirname(__FILE__))
1
+ require File.expand_path('gir_ffi_test_helper.rb', File.dirname(__FILE__))
2
2
 
3
3
  class ArgHelperTest < MiniTest::Spec
4
4
  context "The outptr_to_utf8_array method" do
@@ -63,20 +63,17 @@ class ArgHelperTest < MiniTest::Spec
63
63
  end
64
64
  end
65
65
 
66
- context "The object_pointer_to_object method" do
67
- setup do
68
- GirFFI.setup :Regress
69
- @o = Regress::TestSubObj.new
70
- @o2 = GirFFI::ArgHelper.object_pointer_to_object @o.to_ptr
71
- end
66
+ describe "::object_pointer_to_object" do
67
+ it "finds the wrapping class by gtype and wraps the pointer in it" do
68
+ klsptr = GirFFI::InOutPointer.from :gtype, 0xdeadbeef
69
+ objptr = GirFFI::InOutPointer.from :pointer, klsptr
72
70
 
73
- should "return an object of the correct class" do
74
- assert_instance_of Regress::TestSubObj, @o2
75
- end
71
+ object_class = Class.new
72
+ mock(GirFFI::Builder).build_by_gtype(0xdeadbeef) { object_class }
73
+ mock(object_class).wrap(objptr) { "good-result" }
76
74
 
77
- should "return an object pointing to the original struct" do
78
- assert_equal @o.to_ptr, @o2.to_ptr
75
+ r = GirFFI::ArgHelper.object_pointer_to_object objptr
76
+ assert_equal "good-result", r
79
77
  end
80
78
  end
81
-
82
79
  end