gir_ffi 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3de30b661f43f74216127542e5c68adc520c2fae
4
- data.tar.gz: d517d1dd678fa2e4c5fb13547c6a225286afce44
3
+ metadata.gz: 5e373464c8f376bf817deb6d9f1d82317b9d0b6a
4
+ data.tar.gz: 9205d3435def6eecba27339a6bd7d0f1a114c745
5
5
  SHA512:
6
- metadata.gz: 66971838b0f54a2d34b24ac782564a09cfd675236520a4212ec41af35acea4fa3ab212daab633b29b8af83d3af0a12b736656d4a50f032cd432d4dca831a4bba
7
- data.tar.gz: 3a419c93f07af1e2781fb2afc2d6e4a057bbbd0802acd99d0a9ce3afea146520050615e826d38778a6e07b5edc494e792568b61f06d970caadcff4599e2d8f09
6
+ metadata.gz: 42daa42701febe109c324c616af3aee367be2382e6994ca7fc9b915d63ef2984daacaed84eb6e1d5dd84d125e2acc964beeacb49e465552f9b45ad57f66a676c
7
+ data.tar.gz: 5f88e3c9d6e23449d0b461aab4bb320322f338e40f2938f5dd2bd9408da976b941d7661ad762c2ebd218f20521adb6c34dc27deab1316724d4bb6e3de0601bc2
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.8.1 / 2015-10-04
4
+
5
+ * Handle struct array fields with related length fields
6
+ * Update test library build process
7
+
3
8
  ## 0.8.0 / 2015-09-18
4
9
 
5
10
  * Drop official support for CRuby 1.9.3
data/README.md CHANGED
@@ -93,8 +93,7 @@ If you want to send pull requests or patches, please try to follow these
93
93
  instructions. If you get stuck, make a pull request anyway and I'll try to help
94
94
  out.
95
95
 
96
- * Make sure `rake test` runs without reporting any failures. If your code
97
- breaks existing stuff, it won't get merged in.
96
+ * Make sure `rake test` runs without reporting any failures.
98
97
  * Add tests for your feature. Otherwise, I can't see if it works or if I
99
98
  break it later.
100
99
  * Make sure latest master merges cleanly with your branch. Things might
data/Rakefile CHANGED
@@ -1,13 +1,5 @@
1
1
  require 'rake/clean'
2
- require 'bundler/gem_helper'
3
-
4
- class MyGemHelper < Bundler::GemHelper
5
- def version_tag
6
- "version-#{version}"
7
- end
8
- end
9
-
10
- MyGemHelper.install_tasks
2
+ require 'bundler/gem_tasks'
11
3
 
12
4
  load 'tasks/test.rake'
13
5
 
data/TODO.md CHANGED
@@ -3,12 +3,15 @@
3
3
  ## Miscellaneous
4
4
 
5
5
  * MAKE CONSTRUCTOR_WRAP CHECK TYPES? This would allow GObject::Object.new to
6
- work and create the correct subtype.
6
+ work and create the correct subtype for classes that don't define their own
7
+ default constructor.
7
8
  * Add tests for the other test files in gobject-introspection. Currently, only
8
9
  regress.c and gimarshallingtests.c are used, but there are 6 other files
9
10
  available.
10
11
  * Move GObjectIntrospection to GIRepository, and allow generating its own
11
12
  members.
13
+ * Do not remove ClassBase.new. We now remove it and then add it back for the
14
+ default constructor, which is kind of silly.
12
15
 
13
16
  ## Memory managment
14
17
 
@@ -57,14 +57,15 @@ module GirFFI
57
57
  end
58
58
 
59
59
  def set_up_argument_relations
60
- @base_argument_builders.each do |arg|
61
- if (idx = arg.arginfo.closure) >= 0
60
+ @base_argument_builders.each do |bldr|
61
+ if (idx = bldr.closure) >= 0
62
62
  @base_argument_builders[idx].closure = true
63
63
  end
64
64
  end
65
65
  all_builders.each do |bldr|
66
66
  if (idx = bldr.array_length_idx) >= 0
67
67
  other = @base_argument_builders[idx]
68
+ next unless other
68
69
 
69
70
  bldr.length_arg = other
70
71
  other.array_arg = bldr
@@ -60,6 +60,10 @@ module GirFFI
60
60
  type_info.array_length
61
61
  end
62
62
 
63
+ def closure
64
+ arginfo.closure
65
+ end
66
+
63
67
  def ownership_transfer
64
68
  arginfo.ownership_transfer
65
69
  end
@@ -2,6 +2,7 @@ require 'gir_ffi/builders/argument_builder'
2
2
  require 'gir_ffi/builders/argument_builder_collection'
3
3
  require 'gir_ffi/builders/error_argument_builder'
4
4
  require 'gir_ffi/builders/method_template'
5
+ require 'gir_ffi/builders/null_argument_builder'
5
6
  require 'gir_ffi/error_argument_info'
6
7
  require 'gir_ffi/return_value_info'
7
8
  require 'gir_ffi/variable_name_generator'
@@ -44,6 +45,8 @@ module GirFFI
44
45
  @error_argument ||=
45
46
  if @info.throws?
46
47
  ErrorArgumentBuilder.new vargen, ErrorArgumentInfo.new
48
+ else
49
+ NullArgumentBuilder.new
47
50
  end
48
51
  end
49
52
 
@@ -1,5 +1,4 @@
1
1
  require 'gir_ffi/builders/argument_builder'
2
- require 'gir_ffi/builders/return_value_builder'
3
2
  require 'gir_ffi/variable_name_generator'
4
3
  require 'gir_ffi/field_argument_info'
5
4
 
@@ -7,11 +6,123 @@ module GirFFI
7
6
  module Builders
8
7
  # Creates field getter and setter code for a given IFieldInfo.
9
8
  class FieldBuilder
9
+ # Convertor for fields for field getters. Used when building getter
10
+ # methods.
11
+ class GetterArgumentBuilder < BaseArgumentBuilder
12
+ def initialize(var_gen, field_argument_info, field_info, options = {})
13
+ super(var_gen, field_argument_info)
14
+ @field_info = field_info
15
+ @length_arg = options.fetch(:length_argument) { NullArgumentBuilder.new }
16
+ end
17
+
18
+ def pre_conversion
19
+ [
20
+ "#{field_ptr} = @struct.to_ptr + #{field_offset}",
21
+ "#{typed_ptr} = GirFFI::InOutPointer.new(#{field_type_tag}, #{field_ptr})",
22
+ "#{bare_value} = #{typed_ptr}.to_value"
23
+ ]
24
+ end
25
+
26
+ def capture_variable_name
27
+ nil
28
+ end
29
+
30
+ def post_converted_name
31
+ @post_converted_name ||= if has_post_conversion?
32
+ new_variable
33
+ else
34
+ bare_value
35
+ end
36
+ end
37
+
38
+ def return_value_name
39
+ post_converted_name
40
+ end
41
+
42
+ def post_conversion
43
+ if has_post_conversion?
44
+ ["#{post_converted_name} = #{post_convertor.conversion}"]
45
+ else
46
+ []
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def field_offset
53
+ @field_info.offset
54
+ end
55
+
56
+ def field_ptr
57
+ @field_ptr ||= @var_gen.new_var
58
+ end
59
+
60
+ def typed_ptr
61
+ @typed_ptr ||= @var_gen.new_var
62
+ end
63
+
64
+ def bare_value
65
+ @bare_value ||= @var_gen.new_var
66
+ end
67
+
68
+ def field_type_tag
69
+ @field_type_tag ||= @field_info.field_type.tag_or_class.inspect
70
+ end
71
+
72
+ def field_type
73
+ @field_type ||= @field_info.field_type
74
+ end
75
+
76
+ def has_post_conversion?
77
+ type_info.needs_c_to_ruby_conversion_for_functions?
78
+ end
79
+
80
+ def post_convertor
81
+ @post_convertor ||= CToRubyConvertor.new(type_info,
82
+ bare_value,
83
+ length_arg.post_converted_name)
84
+ end
85
+ end
86
+
87
+ # Class to represent argument info for the argument of a getter method.
88
+ # Implements the necessary parts of IArgumentInfo's interface.
89
+ class GetterArgumentInfo
90
+ attr_reader :name, :argument_type
91
+
92
+ def initialize(name, type)
93
+ @name = name
94
+ @argument_type = type
95
+ end
96
+
97
+ def closure
98
+ -1
99
+ end
100
+
101
+ def direction
102
+ :out
103
+ end
104
+
105
+ def ownership_transfer
106
+ :everything
107
+ end
108
+
109
+ def caller_allocates?
110
+ false
111
+ end
112
+
113
+ def skip?
114
+ false
115
+ end
116
+ end
117
+
10
118
  # Builder for field getters
11
119
  class GetterBuilder
12
- def initialize(field_builder, return_value_builder)
13
- @field_builder = field_builder
14
- @return_value_builder = return_value_builder
120
+ def initialize(info)
121
+ @info = info
122
+ end
123
+
124
+ def method_definition
125
+ template.method_definition
15
126
  end
16
127
 
17
128
  def singleton_method?
@@ -19,7 +130,7 @@ module GirFFI
19
130
  end
20
131
 
21
132
  def method_name
22
- @field_builder.field_name
133
+ @info.name
23
134
  end
24
135
 
25
136
  def method_arguments
@@ -27,36 +138,72 @@ module GirFFI
27
138
  end
28
139
 
29
140
  def preparation
30
- [
31
- "#{field_ptr} = @struct.to_ptr + #{field_offset}",
32
- "#{typed_ptr} = GirFFI::InOutPointer.new(#{field_type_tag}, #{field_ptr})"
33
- ]
141
+ []
34
142
  end
35
143
 
36
144
  def invocation
37
- "#{typed_ptr}.to_value"
145
+ nil
38
146
  end
39
147
 
40
148
  def result
41
- [@return_value_builder.return_value_name]
149
+ [getter_argument_builder.return_value_name]
42
150
  end
43
151
 
44
152
  private
45
153
 
46
- def field_ptr
47
- @field_ptr ||= @return_value_builder.new_variable
154
+ def var_gen
155
+ @var_gen ||= VariableNameGenerator.new
48
156
  end
49
157
 
50
- def typed_ptr
51
- @typed_ptr ||= @return_value_builder.new_variable
158
+ def template
159
+ @template ||= MethodTemplate.new(self, argument_builders)
160
+ end
161
+
162
+ def argument_builders
163
+ @argument_builders ||=
164
+ ArgumentBuilderCollection.new(
165
+ NullReturnValueBuilder.new,
166
+ [getter_argument_builder, length_argument_builder])
167
+ end
168
+
169
+ def getter_argument_builder
170
+ @getter_argument_builder ||=
171
+ GetterArgumentBuilder.new(var_gen, field_argument_info, @info,
172
+ length_argument: length_argument_builder)
173
+ end
174
+
175
+ def length_argument_builder
176
+ @length_argument_builder ||=
177
+ if array_length_field
178
+ GetterArgumentBuilder.new(var_gen, length_argument_info, array_length_field)
179
+ else
180
+ NullArgumentBuilder.new
181
+ end
182
+ end
183
+
184
+ def array_length_field
185
+ @info.related_array_length_field
186
+ end
187
+
188
+ def length_argument_info
189
+ @length_argument_info ||=
190
+ GetterArgumentInfo.new 'length', array_length_field.field_type
52
191
  end
53
192
 
54
193
  def field_offset
55
- @field_builder.field_offset
194
+ @info.offset
56
195
  end
57
196
 
58
197
  def field_type_tag
59
- @field_builder.field_type_tag
198
+ @field_type_tag ||= @info.field_type.tag_or_class.inspect
199
+ end
200
+
201
+ def field_type
202
+ @field_type ||= @info.field_type
203
+ end
204
+
205
+ def field_argument_info
206
+ @field_argument_info ||= GetterArgumentInfo.new 'value', field_type
60
207
  end
61
208
  end
62
209
 
@@ -84,9 +231,8 @@ module GirFFI
84
231
  end
85
232
 
86
233
  def getter_def
87
- argument_builders = ArgumentBuilderCollection.new(return_value_builder, [])
88
- getter_builder = GetterBuilder.new(self, return_value_builder)
89
- MethodTemplate.new(getter_builder, argument_builders).method_definition
234
+ getter_builder = GetterBuilder.new(info)
235
+ getter_builder.method_definition
90
236
  end
91
237
 
92
238
  # TODO: Use MethodTemplate
@@ -106,20 +252,12 @@ module GirFFI
106
252
  CODE
107
253
  end
108
254
 
109
- def field_name
110
- @field_name ||= info.name
111
- end
112
-
113
- def field_offset
114
- @field_offset ||= info.offset
115
- end
255
+ private
116
256
 
117
257
  def field_type_tag
118
258
  @field_type_tag ||= info.field_type.tag_or_class.inspect
119
259
  end
120
260
 
121
- private
122
-
123
261
  def container_class
124
262
  @container_class ||= container_module.const_get(container_info.safe_name)
125
263
  end
@@ -140,11 +278,6 @@ module GirFFI
140
278
  @field_argument_info ||= FieldArgumentInfo.new 'value', field_type
141
279
  end
142
280
 
143
- def return_value_builder
144
- @rv_builder ||= ReturnValueBuilder.new(VariableNameGenerator.new,
145
- field_argument_info)
146
- end
147
-
148
281
  def setter_builder
149
282
  @setter_builder ||= ArgumentBuilder.new(VariableNameGenerator.new,
150
283
  field_argument_info)
@@ -74,7 +74,7 @@ module GirFFI
74
74
  end
75
75
 
76
76
  def plain_invocation
77
- [@builder.invocation]
77
+ [@builder.invocation].compact
78
78
  end
79
79
  end
80
80
  end
@@ -0,0 +1,43 @@
1
+ module GirFFI
2
+ # Argument builder that does nothing. Implements the Null Object pattern.
3
+ class NullArgumentBuilder
4
+ def initialize(*)
5
+ end
6
+
7
+ def pre_conversion
8
+ []
9
+ end
10
+
11
+ def post_conversion
12
+ []
13
+ end
14
+
15
+ def array_length_idx
16
+ -1
17
+ end
18
+
19
+ def method_argument_name
20
+ nil
21
+ end
22
+
23
+ def return_value_name
24
+ nil
25
+ end
26
+
27
+ def call_argument_name
28
+ nil
29
+ end
30
+
31
+ def capture_variable_name
32
+ nil
33
+ end
34
+
35
+ def closure
36
+ -1
37
+ end
38
+
39
+ def post_converted_name
40
+ nil
41
+ end
42
+ end
43
+ end
@@ -5,6 +5,11 @@ module GirFFI
5
5
  def layout_specification
6
6
  [name.to_sym, field_type.to_ffi_type, offset]
7
7
  end
8
+
9
+ def related_array_length_field
10
+ index = field_type.array_length
11
+ container.fields[index] if index > -1
12
+ end
8
13
  end
9
14
  end
10
15
  end
@@ -1,4 +1,4 @@
1
1
  # Current GirFFI version
2
2
  module GirFFI
3
- VERSION = '0.8.0'
3
+ VERSION = '0.8.1'
4
4
  end
@@ -190,5 +190,5 @@ file "test/lib/Makefile" => "test/lib/configure" do
190
190
  end
191
191
 
192
192
  file "test/lib/configure" => ["test/lib/autogen.sh", "test/lib/configure.ac"] do
193
- sh %{cd test/lib && NOCONFIGURE=1 ./autogen.sh}
193
+ sh %{cd test/lib && ./autogen.sh}
194
194
  end
@@ -104,4 +104,26 @@ describe GirFFI::Builders::FieldBuilder do
104
104
  instance.setter_def.must_equal expected
105
105
  end
106
106
  end
107
+
108
+ describe 'for a field with a related array length field' do
109
+ let(:field_info) { get_field_introspection_data 'GObject', 'SignalQuery', 'param_types' }
110
+ let(:n_params_field_info) { get_field_introspection_data 'GObject', 'SignalQuery', 'n_params' }
111
+
112
+ it 'creates the right getter method' do
113
+ skip if field_info.field_type.array_length < 0
114
+ expected = <<-CODE.reset_indentation
115
+ def param_types
116
+ _v1 = @struct.to_ptr + #{n_params_field_info.offset}
117
+ _v2 = GirFFI::InOutPointer.new(:guint32, _v1)
118
+ _v3 = _v2.to_value
119
+ _v4 = @struct.to_ptr + #{field_info.offset}
120
+ _v5 = GirFFI::InOutPointer.new([:pointer, :c], _v4)
121
+ _v6 = _v5.to_value
122
+ _v7 = GirFFI::SizedArray.wrap(:GType, _v3, _v6)
123
+ _v7
124
+ end
125
+ CODE
126
+ instance.getter_def.must_equal expected
127
+ end
128
+ end
107
129
  end
@@ -55,4 +55,21 @@ describe GObject do
55
55
  instance.n_values.must_equal 0
56
56
  end
57
57
  end
58
+
59
+ describe GObject::SignalQuery do
60
+ it 'works' do
61
+ GObject::SignalQuery.new
62
+ pass
63
+ end
64
+
65
+ it 'uses the n_params field for the length of param_types' do
66
+ field_info = get_field_introspection_data 'GObject', 'SignalQuery', 'param_types'
67
+ skip if field_info.field_type.array_length < 0
68
+ gtype = GObject::Object.gtype
69
+ signals = GObject.signal_list_ids gtype
70
+ signal_query = GObject.signal_query signals.first
71
+ signal_query.n_params.must_equal 1
72
+ signal_query.param_types.size.must_equal 1
73
+ end
74
+ end
58
75
  end
@@ -1,96 +1,4 @@
1
1
  #!/bin/sh
2
2
  # Run this to generate all the initial makefiles, etc.
3
3
 
4
- PROJECT=GirFFITest
5
-
6
- if test ! -f configure.ac ; then
7
- echo "You must run this script in the top-level $PROJECT directory"
8
- exit 1
9
- fi
10
-
11
- DIE=0
12
-
13
- have_libtool=false
14
- if libtoolize --version < /dev/null > /dev/null 2>&1 ; then
15
- libtool_version=`libtoolize --version |
16
- head -1 |
17
- sed -e 's/^\(.*\)([^)]*)\(.*\)$/\1\2/g' \
18
- -e 's/^[^0-9]*\([0-9.][0-9.]*\).*/\1/'`
19
- case $libtool_version in
20
- 2.2*)
21
- have_libtool=true
22
- ;;
23
- 2.4*)
24
- have_libtool=true
25
- ;;
26
- esac
27
- fi
28
- if $have_libtool ; then : ; else
29
- echo
30
- echo "You must have libtool >= 2.2 installed to compile $PROJECT."
31
- echo "Install the appropriate package for your distribution,"
32
- echo "or get the source tarball at http://ftp.gnu.org/gnu/libtool/"
33
- DIE=1
34
- fi
35
-
36
- if autoconf --version < /dev/null > /dev/null 2>&1 ; then : ; else
37
- echo
38
- echo "You must have autoconf installed to compile $PROJECT."
39
- echo "Install the appropriate package for your distribution,"
40
- echo "or get the source tarball at http://ftp.gnu.org/gnu/autoconf/"
41
- DIE=1
42
- fi
43
-
44
- if automake-1.14 --version < /dev/null > /dev/null 2>&1 ; then
45
- AUTOMAKE=automake-1.14
46
- ACLOCAL=aclocal-1.14
47
- else if automake-1.13 --version < /dev/null > /dev/null 2>&1 ; then
48
- AUTOMAKE=automake-1.13
49
- ACLOCAL=aclocal-1.13
50
- else if automake-1.11 --version < /dev/null > /dev/null 2>&1 ; then
51
- AUTOMAKE=automake-1.11
52
- ACLOCAL=aclocal-1.11
53
- else if automake-1.10 --version < /dev/null > /dev/null 2>&1 ; then
54
- AUTOMAKE=automake-1.10
55
- ACLOCAL=aclocal-1.10
56
- else
57
- echo
58
- echo "You must have automake 1.13.x, 1.11.x or 1.10.x installed to compile $PROJECT."
59
- echo "Install the appropriate package for your distribution,"
60
- echo "or get the source tarball at http://ftp.gnu.org/gnu/automake/"
61
- DIE=1
62
- fi
63
- fi
64
- fi
65
- fi
66
-
67
- if test "$DIE" -eq 1; then
68
- exit 1
69
- fi
70
-
71
-
72
- libtoolize --force || exit $?
73
-
74
- $ACLOCAL -I m4 || exit $?
75
-
76
- autoconf || exit $?
77
- autoheader || exit $?
78
-
79
- $AUTOMAKE --add-missing || exit $?
80
-
81
- # NOCONFIGURE is used by gnome-common; support both
82
- if ! test -z "$AUTOGEN_SUBDIR_MODE"; then
83
- NOCONFIGURE=1
84
- fi
85
-
86
- if test -z "$NOCONFIGURE"; then
87
- if test -z "$*"; then
88
- echo "I am going to run ./configure with no arguments - if you wish "
89
- echo "to pass any to it, please specify them on the $0 command line."
90
- fi
91
-
92
- ./configure --enable-maintainer-mode $AUTOGEN_CONFIGURE_ARGS "$@" || exit $?
93
-
94
- echo
95
- echo "Now type 'make' to compile $PROJECT."
96
- fi
4
+ autoreconf -ivf
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gir_ffi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matijs van Zuijlen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-18 00:00:00.000000000 Z
11
+ date: 2015-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -188,6 +188,7 @@ files:
188
188
  - lib/gir_ffi/builders/marshalling_method_builder.rb
189
189
  - lib/gir_ffi/builders/method_template.rb
190
190
  - lib/gir_ffi/builders/module_builder.rb
191
+ - lib/gir_ffi/builders/null_argument_builder.rb
191
192
  - lib/gir_ffi/builders/null_convertor.rb
192
193
  - lib/gir_ffi/builders/null_return_value_builder.rb
193
194
  - lib/gir_ffi/builders/object_builder.rb