gir_ffi 0.4.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/History.txt +8 -0
  2. data/README.md +1 -1
  3. data/TODO.rdoc +12 -4
  4. data/lib/ffi-glib.rb +0 -5
  5. data/lib/ffi-glib/list.rb +1 -1
  6. data/lib/ffi-glib/s_list.rb +1 -1
  7. data/lib/ffi-gobject.rb +2 -3
  8. data/lib/ffi-gobject/closure.rb +4 -3
  9. data/lib/ffi-gobject_introspection/i_base_info.rb +11 -14
  10. data/lib/ffi-gobject_introspection/i_constant_info.rb +1 -1
  11. data/lib/ffi-gobject_introspection/i_function_info.rb +0 -6
  12. data/lib/ffi-gobject_introspection/lib.rb +8 -2
  13. data/lib/gir_ffi.rb +5 -0
  14. data/lib/gir_ffi/arg_helper.rb +1 -1
  15. data/lib/gir_ffi/argument_builder.rb +161 -0
  16. data/lib/gir_ffi/base_argument_builder.rb +146 -0
  17. data/lib/gir_ffi/builder/field.rb +7 -5
  18. data/lib/gir_ffi/builder/module.rb +3 -14
  19. data/lib/gir_ffi/builder/property.rb +0 -2
  20. data/lib/gir_ffi/builder/type/callback.rb +0 -8
  21. data/lib/gir_ffi/builder/type/constant.rb +0 -4
  22. data/lib/gir_ffi/builder/type/enum.rb +0 -4
  23. data/lib/gir_ffi/builder/type/interface.rb +0 -4
  24. data/lib/gir_ffi/builder/type/object.rb +0 -1
  25. data/lib/gir_ffi/builder/type/struct_based.rb +0 -6
  26. data/lib/gir_ffi/builder/type/union.rb +0 -4
  27. data/lib/gir_ffi/builder/type/with_layout.rb +0 -1
  28. data/lib/gir_ffi/builder/type/with_methods.rb +1 -7
  29. data/lib/gir_ffi/callback.rb +9 -0
  30. data/lib/gir_ffi/callback_helper.rb +8 -1
  31. data/lib/gir_ffi/class_base.rb +6 -26
  32. data/lib/gir_ffi/error_argument_builder.rb +17 -0
  33. data/lib/gir_ffi/{builder/function.rb → function_builder.rb} +14 -11
  34. data/lib/gir_ffi/in_out_pointer.rb +29 -36
  35. data/lib/gir_ffi/in_pointer.rb +1 -1
  36. data/lib/gir_ffi/info_ext.rb +6 -0
  37. data/lib/gir_ffi/info_ext/i_field_info.rb +0 -2
  38. data/lib/gir_ffi/info_ext/i_type_info.rb +29 -10
  39. data/lib/gir_ffi/info_ext/safe_constant_name.rb +21 -0
  40. data/lib/gir_ffi/info_ext/safe_function_name.rb +13 -0
  41. data/lib/gir_ffi/interface_base.rb +1 -11
  42. data/lib/gir_ffi/module_base.rb +0 -10
  43. data/lib/gir_ffi/null_argument_builder.rb +9 -0
  44. data/lib/gir_ffi/return_value_builder.rb +75 -0
  45. data/lib/gir_ffi/setter_argument_info.rb +16 -0
  46. data/lib/gir_ffi/type_map.rb +10 -1
  47. data/lib/gir_ffi/version.rb +1 -1
  48. data/tasks/test.rake +61 -0
  49. data/test/base_test_helper.rb +0 -2
  50. data/test/ffi-gobject/value_test.rb +15 -0
  51. data/test/ffi-gobject_introspection/i_base_info_test.rb +31 -6
  52. data/test/ffi-gobject_introspection/i_function_info_test.rb +0 -17
  53. data/test/ffi-gobject_introspection/lib_test.rb +0 -55
  54. data/test/ffi-gobject_test.rb +2 -1
  55. data/test/gir_ffi/argument_builder_test.rb +414 -0
  56. data/test/gir_ffi/base_argument_builder_test.rb +13 -0
  57. data/test/gir_ffi/builder/module_test.rb +4 -40
  58. data/test/gir_ffi/builder/type/callback_test.rb +0 -27
  59. data/test/gir_ffi/builder/type/constant_test.rb +0 -12
  60. data/test/gir_ffi/builder/type/enum_test.rb +0 -20
  61. data/test/gir_ffi/builder/type/interface_test.rb +0 -11
  62. data/test/gir_ffi/builder/type/object_test.rb +2 -2
  63. data/test/gir_ffi/builder/type/struct_test.rb +0 -39
  64. data/test/gir_ffi/builder/type/unintrospectable_test.rb +1 -1
  65. data/test/gir_ffi/builder/type/union_test.rb +0 -11
  66. data/test/gir_ffi/builder_test.rb +3 -11
  67. data/test/gir_ffi/callback_helper_test.rb +7 -0
  68. data/test/gir_ffi/{builder/function_test.rb → function_builder_test.rb} +16 -28
  69. data/test/gir_ffi/in_out_pointer_test.rb +0 -20
  70. data/test/gir_ffi/info_ext/i_type_info_test.rb +112 -26
  71. data/test/gir_ffi/info_ext/safe_constant_name_test.rb +16 -0
  72. data/test/gir_ffi/info_ext/safe_function_name_test.rb +22 -0
  73. data/test/gir_ffi/return_value_builder_test.rb +355 -0
  74. data/test/integration/generated_gimarshallingtests_test.rb +608 -296
  75. data/test/integration/generated_regress_test.rb +879 -494
  76. metadata +35 -24
  77. data/lib/gir_ffi/builder/argument.rb +0 -569
  78. data/lib/gir_ffi/builder/argument/base.rb +0 -151
  79. data/lib/gir_ffi/builder/argument/in_base.rb +0 -14
  80. data/lib/gir_ffi/builder/argument/in_out_base.rb +0 -18
  81. data/lib/gir_ffi/builder/argument/out_base.rb +0 -15
  82. data/test/gir_ffi/builder/argument/base_test.rb +0 -55
  83. data/test/integration/pretty_print_test.rb +0 -33
@@ -1,151 +0,0 @@
1
- require 'gir_ffi/info_ext/i_registered_type_info'
2
-
3
- module GirFFI
4
- module Builder
5
- module Argument
6
- # Abstract parent class of the argument building classes. These
7
- # classes are used by Builder::Function to create the code that
8
- # processes each argument before and after the actual function call.
9
- class Base
10
- KEYWORDS = [
11
- "alias", "and", "begin", "break", "case", "class", "def", "do",
12
- "else", "elsif", "end", "ensure", "false", "for", "if", "in",
13
- "module", "next", "nil", "not", "or", "redo", "rescue", "retry",
14
- "return", "self", "super", "then", "true", "undef", "unless",
15
- "until", "when", "while", "yield"
16
- ]
17
-
18
- attr_reader :name, :retname
19
-
20
- attr_accessor :length_arg, :array_arg
21
-
22
- def initialize var_gen, name, typeinfo, direction
23
- @typeinfo = typeinfo
24
- @inarg = nil
25
- @retname = nil
26
- @name = safe(name)
27
- @var_gen = var_gen
28
- @length_arg = nil
29
- @array_arg = nil
30
- end
31
-
32
- def type_info
33
- @typeinfo
34
- end
35
-
36
- def type_tag
37
- type_info.tag
38
- end
39
-
40
- def specialized_type_tag
41
- type_info.flattened_tag
42
- end
43
-
44
- def type_specification
45
- type_info.type_specification
46
- end
47
-
48
- TAG_TO_WRAPPER_CLASS_MAP = {
49
- :glist => 'GLib::List',
50
- :gslist => 'GLib::SList',
51
- :ghash => 'GLib::HashTable',
52
- :array => 'GLib::Array',
53
- :utf8 => 'GirFFI::InPointer',
54
- :void => 'GirFFI::InPointer'
55
- }
56
-
57
- def argument_class_name
58
- case (tag = type_tag)
59
- when :interface
60
- type_info.interface_type_name
61
- when :array
62
- case type_info.array_type
63
- when :byte_array
64
- 'GLib::ByteArray'
65
- when :array
66
- 'GLib::Array'
67
- when :ptr_array
68
- 'GLib::PtrArray'
69
- else # :c
70
- if type_info.zero_terminated?
71
- if type_info.element_type == :utf8
72
- 'GLib::Strv'
73
- else
74
- 'GirFFI::InPointer'
75
- end
76
- else
77
- 'GirFFI::InPointer'
78
- end
79
- end
80
- else
81
- TAG_TO_WRAPPER_CLASS_MAP[tag]
82
- end
83
- end
84
-
85
- def subtype_tag_or_class_name index=0
86
- type = type_info.param_type(index)
87
- tag = type.tag
88
- base = if tag == :interface
89
- type.interface_type_name
90
- else
91
- tag.inspect
92
- end
93
- if type.pointer?
94
- "[:pointer, #{base}]"
95
- else
96
- base
97
- end
98
- end
99
-
100
- def elm_t
101
- type_info.element_type.inspect
102
- end
103
-
104
- def array_size
105
- if @length_arg
106
- @length_arg.retname
107
- else
108
- type_info.array_fixed_size
109
- end
110
- end
111
-
112
- def safe name
113
- if KEYWORDS.include? name
114
- "#{name}_"
115
- else
116
- name
117
- end
118
- end
119
-
120
- def inarg
121
- @array_arg.nil? ? @inarg : nil
122
- end
123
-
124
- def retval
125
- @array_arg.nil? ? @retname : nil
126
- end
127
-
128
- def callarg
129
- @callarg ||= @var_gen.new_var
130
- end
131
-
132
- def pre
133
- []
134
- end
135
-
136
- def post
137
- []
138
- end
139
-
140
- def postpost
141
- []
142
- end
143
-
144
- def cleanup
145
- []
146
- end
147
- end
148
- end
149
- end
150
- end
151
-
@@ -1,14 +0,0 @@
1
- module GirFFI
2
- module Builder
3
- module Argument
4
- # Abstract base class implementing argument processing for arguments
5
- # with direction :in.
6
- class InBase < Base
7
- def initialize var_gen, name, typeinfo, direction
8
- super var_gen, name, typeinfo, direction
9
- @inarg = @name
10
- end
11
- end
12
- end
13
- end
14
- end
@@ -1,18 +0,0 @@
1
- module GirFFI
2
- module Builder
3
- module Argument
4
- # Abstract base class implementing argument processing for arguments
5
- # with direction :inout.
6
- class InOutBase < Base
7
- def initialize var_gen, name, typeinfo, direction
8
- super var_gen, name, typeinfo, direction
9
- @inarg = @name
10
- end
11
-
12
- def retname
13
- @retname ||= @var_gen.new_var
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,15 +0,0 @@
1
- module GirFFI
2
- module Builder
3
- module Argument
4
- # Abstract base class implementing argument processing for arguments
5
- # with direction :out.
6
- class OutBase < Base
7
- def retname
8
- @retname ||= @var_gen.new_var
9
- end
10
- end
11
- end
12
- end
13
- end
14
-
15
-
@@ -1,55 +0,0 @@
1
- require 'gir_ffi_test_helper'
2
-
3
- describe GirFFI::Builder::Argument::Base do
4
- describe "#subtype_tag_or_class_name" do
5
- describe "for a simple type" do
6
- it "returns the string ':void'" do
7
- mock(subtype = Object.new).tag { :void }
8
- mock(subtype).pointer? { false }
9
-
10
- mock(info = Object.new).param_type(0) { subtype }
11
-
12
- builder = GirFFI::Builder::Argument::Base.new nil, 'foo', info, :direction
13
- assert_equal ":void", builder.subtype_tag_or_class_name
14
- end
15
- end
16
-
17
- describe "for an array of simple type :foo" do
18
- it "returns the string ':foo'" do
19
- mock(subtype = Object.new).tag { :foo }
20
- mock(subtype).pointer? { false }
21
-
22
- mock(info = Object.new).param_type(0) { subtype }
23
-
24
- builder = GirFFI::Builder::Argument::Base.new nil, 'bar', info, :direction
25
- assert_equal ":foo", builder.subtype_tag_or_class_name
26
- end
27
- end
28
-
29
- describe "for an array of an interface class" do
30
- it "returns the interface's full class name" do
31
- mock(subtype = Object.new).tag { :interface }
32
- mock(subtype).interface_type_name { "-full-type-name-" }
33
- mock(subtype).pointer? { false }
34
-
35
- mock(info = Object.new).param_type(0) { subtype }
36
-
37
- builder = GirFFI::Builder::Argument::Base.new nil, 'bar', info, :direction
38
- assert_equal "-full-type-name-", builder.subtype_tag_or_class_name
39
- end
40
- end
41
-
42
- describe "for an array of pointer to simple type :foo" do
43
- it "returns the string '[:pointer, :foo]'" do
44
- mock(subtype = Object.new).tag { :foo }
45
- mock(subtype).pointer? { true }
46
-
47
- mock(info = Object.new).param_type(0) { subtype }
48
-
49
- builder = GirFFI::Builder::Argument::Base.new nil, 'bar', info, :direction
50
- assert_equal "[:pointer, :foo]", builder.subtype_tag_or_class_name
51
- end
52
- end
53
- end
54
- end
55
-
@@ -1,33 +0,0 @@
1
- require 'gir_ffi_test_helper'
2
-
3
- require 'tempfile'
4
-
5
- GirFFI.setup :Regress
6
-
7
- describe "Pretty-printing" do
8
- def assert_syntax_ok str
9
- tmp = Tempfile.new "gir_ffi"
10
- # TODO: Make #pretty_print add this preamble.
11
- tmp.write "# coding: utf-8\n"
12
- tmp.write str
13
- tmp.flush
14
- is_ok = `ruby -c #{tmp.path} 2>&1`
15
- is_ok.must_match(/^Syntax OK/)
16
- end
17
-
18
- describe "for the Regress module" do
19
- it "runs without throwing an exception" do
20
- Regress._builder.pretty_print
21
- end
22
-
23
- it "results in valid Ruby" do
24
- assert_syntax_ok Regress._builder.pretty_print
25
- end
26
- end
27
-
28
- describe "for the GLib module" do
29
- it "results in valid Ruby" do
30
- assert_syntax_ok GLib._builder.pretty_print
31
- end
32
- end
33
- end