gir_ffi 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4030d6c4cfb00268801490cc1bb1ea0fcecfd533
4
- data.tar.gz: 36be619abbb6889c67c7ab2726c6eaa3708f7946
3
+ metadata.gz: 8cf0a7c44fc03dbe6b94889b4f2d9fb4d0ffd3d4
4
+ data.tar.gz: 125f3d704a2d1dbf911503efd0ee15b7b520b96f
5
5
  SHA512:
6
- metadata.gz: ae9124773e81ce3c8ce21882fa164296f40c06d14c3032f57b121a4026967fb0e6e210d60dacaa171f21997f34a19855e407ed425c7fba0d1d2dbc47fa47e4e9
7
- data.tar.gz: 0b647b4e8bec822e25f96a249efc0ea0ce4b9177b17de87d18d3f17f384d5f70480f7986ff920697a6e06709b752d0407ed3d88f485b43a290081e2ffecee01e
6
+ metadata.gz: c8701346e6ed89cac5567fff4c564c536debc9a64f0cd91f1c61792e363265f84ab385c8a410fb52acb65ecbfab105fa085f39e4a10e20534388e7e5fe5e7fac
7
+ data.tar.gz: 922d806dd05c7e353fb5e382ab04ae982abc7fe96bb470a855d937ef273b524d1ecd3d6a9346480c23cb28f56bb7137697370bb2af179a1e91b7946c7654e87b
data/Changelog.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.1 / 2014-01-17
4
+
5
+ * Handle method setup for methods with unsafe names (i.e., g_iconv())
6
+ * Add override for GLib::IConv.open
7
+
8
+ # Changelog
9
+
3
10
  ## 0.7.0 / 2014-01-11
4
11
 
5
12
  * Type handling:
@@ -0,0 +1,14 @@
1
+ module GLib
2
+ load_class :IConv
3
+
4
+ # Overrides for IConv
5
+ class IConv
6
+ def self.open(to_codeset, from_codeset)
7
+ to_ptr = GirFFI::InPointer.from(:utf8, to_codeset)
8
+ from_ptr = GirFFI::InPointer.from(:utf8, from_codeset)
9
+ result_ptr = Lib.g_iconv_open(to_ptr, from_ptr)
10
+ wrap(result_ptr)
11
+ end
12
+ end
13
+ end
14
+
data/lib/ffi-glib.rb CHANGED
@@ -6,6 +6,7 @@ GirFFI.setup :GLib
6
6
  require 'ffi-glib/array'
7
7
  require 'ffi-glib/byte_array'
8
8
  require 'ffi-glib/hash_table'
9
+ require 'ffi-glib/iconv'
9
10
  require 'ffi-glib/list'
10
11
  require 'ffi-glib/ptr_array'
11
12
  require 'ffi-glib/s_list'
@@ -37,5 +38,7 @@ module GLib
37
38
  attach_function :g_ptr_array_new, [], :pointer
38
39
  attach_function :g_ptr_array_add, [:pointer, :pointer], :void
39
40
  attach_function :g_ptr_array_foreach, [:pointer, Func, :pointer], :pointer
41
+
42
+ attach_function :g_iconv_open, [:pointer, :pointer], :pointer
40
43
  end
41
44
  end
@@ -1,6 +1,6 @@
1
1
  module GObjectIntrospection
2
- # Wraps a GIFunctioInfo struct.
3
- # Represents a function.
2
+ # Wraps a GIFunctionInfo struct.
3
+ # Represents a function or method.
4
4
  class IFunctionInfo < ICallableInfo
5
5
  def symbol
6
6
  Lib.g_function_info_get_symbol @gobj
@@ -27,11 +27,12 @@ module GirFFI
27
27
  end
28
28
 
29
29
  def attach_and_define_method method, go, modul
30
- return false if go.nil?
30
+ return unless go
31
+ method = go.safe_name
31
32
  Builder.attach_ffi_function lib, go
32
- modul.class_eval { remove_method method }
33
+ modul.class_eval { remove_method method if method_defined? method }
33
34
  build_class.class_eval function_definition(go)
34
- true
35
+ return method
35
36
  end
36
37
 
37
38
  def stub_methods
@@ -14,16 +14,13 @@ module GirFFI
14
14
  GIR_FFI_BUILDER = NullBuilder.new
15
15
 
16
16
  def setup_and_call method, *arguments, &block
17
- result = self.class.ancestors.any? do |klass|
18
- klass.respond_to?(:setup_instance_method) &&
19
- klass.setup_instance_method(method.to_s)
20
- end
17
+ method_name = self.class.try_in_ancestors(:setup_instance_method, method.to_s)
21
18
 
22
- unless result
23
- raise RuntimeError, "Unable to set up instance method #{method} in #{self}"
19
+ unless method_name
20
+ raise RuntimeError, "Unable to set up instance method '#{method}' in #{self}"
24
21
  end
25
22
 
26
- self.send method, *arguments, &block
23
+ self.send method_name, *arguments, &block
27
24
  end
28
25
 
29
26
  if RUBY_PLATFORM == 'java'
@@ -39,16 +36,23 @@ module GirFFI
39
36
  end
40
37
 
41
38
  def self.setup_and_call method, *arguments, &block
42
- result = self.ancestors.any? do |klass|
43
- klass.respond_to?(:setup_method) &&
44
- klass.setup_method(method.to_s)
45
- end
39
+ method_name = self.try_in_ancestors(:setup_method, method.to_s)
46
40
 
47
- unless result
48
- raise RuntimeError, "Unable to set up method #{method} in #{self}"
41
+ unless method_name
42
+ raise RuntimeError, "Unable to set up method '#{method}' in #{self}"
49
43
  end
50
44
 
51
- self.send method, *arguments, &block
45
+ self.send method_name, *arguments, &block
46
+ end
47
+
48
+ def self.try_in_ancestors(method, *arguments)
49
+ self.ancestors.each do |klass|
50
+ if klass.respond_to?(method)
51
+ result = klass.send(method, *arguments)
52
+ return result if result
53
+ end
54
+ end
55
+ return
52
56
  end
53
57
 
54
58
  class << self
@@ -7,12 +7,11 @@ module GirFFI
7
7
  end
8
8
 
9
9
  def method_stub
10
- symbol = @info.name
11
- "
12
- def #{@info.method? ? '' : 'self.'}#{symbol} *args, &block
13
- setup_and_call :#{symbol}, *args, &block
10
+ <<-STUB.reset_indentation
11
+ def #{@info.method? ? '' : 'self.'}#{@info.safe_name} *args, &block
12
+ setup_and_call #{@info.name.to_sym.inspect}, *args, &block
14
13
  end
15
- "
14
+ STUB
16
15
  end
17
16
  end
18
17
  end
@@ -1,3 +1,3 @@
1
1
  module GirFFI
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  end
@@ -0,0 +1,18 @@
1
+ require 'gir_ffi_test_helper'
2
+
3
+ describe GLib::IConv do
4
+ describe ".open" do
5
+ it "creates a new instance of GLib::Iconv" do
6
+ instance = GLib::IConv.open("ascii", "utf-8")
7
+ instance.must_be_instance_of GLib::IConv
8
+ end
9
+ end
10
+
11
+ let(:instance) { GLib::IConv.open("ascii", "utf-8") }
12
+
13
+ describe "#setup_and_call" do
14
+ it "works for the method called ''" do
15
+ instance.setup_and_call :'', nil, nil, nil, nil
16
+ end
17
+ end
18
+ end
@@ -5,8 +5,8 @@ describe GirFFI::Builders::UnionBuilder do
5
5
  let(:builder) { GirFFI::Builders::UnionBuilder.new union_info }
6
6
 
7
7
  describe "#setup_instance_method" do
8
- it "returns false looking for a method that doesn't exist" do
9
- builder.setup_instance_method('blub').must_equal false
8
+ it "returns nil looking for a method that doesn't exist" do
9
+ builder.setup_instance_method('blub').must_be_nil
10
10
  end
11
11
  end
12
12
 
@@ -0,0 +1,30 @@
1
+ require 'gir_ffi_test_helper'
2
+
3
+ GirFFI.setup :Regress
4
+
5
+ describe GirFFI::Builders::WithMethods do
6
+ describe "#setup_instance_method" do
7
+ it "restores a method that was removed" do
8
+ Regress::TestObj.class_eval { remove_method "instance_method" }
9
+
10
+ builder = Regress::TestObj.gir_ffi_builder
11
+
12
+ builder.setup_instance_method "instance_method"
13
+
14
+ obj = Regress::TestObj.constructor
15
+ obj.must_respond_to "instance_method"
16
+ end
17
+
18
+ it "returns the name of the generated method" do
19
+ builder = Regress::TestObj.gir_ffi_builder
20
+ result = builder.setup_instance_method "instance_method"
21
+ result.must_equal "instance_method"
22
+ end
23
+
24
+ it "returns the name of the generated method if different from the info name" do
25
+ builder = GLib::IConv.gir_ffi_builder
26
+ result = builder.setup_instance_method ""
27
+ result.must_equal "_"
28
+ end
29
+ end
30
+ end
@@ -70,13 +70,13 @@ describe GirFFI::ClassBase do
70
70
  end
71
71
  end
72
72
 
73
- describe "a descendant with multiple builders" do
73
+ describe ".setup_and_call" do
74
74
  it "looks up class methods in all builders" do
75
- mock(builder = Object.new).setup_method("foo") { true }
75
+ mock(builder = Object.new).setup_method("foo") { "foo" }
76
76
  klass = Class.new GirFFI::ClassBase
77
77
  klass.const_set :GIR_FFI_BUILDER, builder
78
78
 
79
- mock(sub_builder = Object.new).setup_method("foo") { false }
79
+ mock(sub_builder = Object.new).setup_method("foo") { nil }
80
80
  sub_klass = Class.new klass do
81
81
  def self.foo; end
82
82
  end
@@ -85,12 +85,28 @@ describe GirFFI::ClassBase do
85
85
  sub_klass.setup_and_call :foo
86
86
  end
87
87
 
88
- it "looks up class methods in all builders" do
89
- mock(builder = Object.new).setup_instance_method("foo") { true }
88
+ it "calls the method given by the result of .setup_method" do
89
+ mock(builder = Object.new).setup_method("foo") { "bar" }
90
+ klass = Class.new GirFFI::ClassBase do
91
+ def self.bar
92
+ "correct-result"
93
+ end
94
+ def self.new; self._real_new; end
95
+ end
96
+ klass.const_set :GIR_FFI_BUILDER, builder
97
+
98
+ result = klass.setup_and_call :foo
99
+ result.must_equal "correct-result"
100
+ end
101
+ end
102
+
103
+ describe "#setup_and_call" do
104
+ it "looks up instance methods in all builders" do
105
+ mock(builder = Object.new).setup_instance_method("foo") { "foo" }
90
106
  klass = Class.new GirFFI::ClassBase
91
107
  klass.const_set :GIR_FFI_BUILDER, builder
92
108
 
93
- mock(sub_builder = Object.new).setup_instance_method("foo") { false }
109
+ mock(sub_builder = Object.new).setup_instance_method("foo") { nil }
94
110
  sub_klass = Class.new klass do
95
111
  def foo; end
96
112
  def initialize; end
@@ -102,5 +118,21 @@ describe GirFFI::ClassBase do
102
118
 
103
119
  obj.setup_and_call :foo
104
120
  end
121
+
122
+ it "calls the method given by the result of .setup_instance_method" do
123
+ mock(builder = Object.new).setup_instance_method("foo") { "bar" }
124
+ klass = Class.new GirFFI::ClassBase do
125
+ def bar
126
+ "correct-result"
127
+ end
128
+ def self.new; self._real_new; end
129
+ end
130
+ klass.const_set :GIR_FFI_BUILDER, builder
131
+
132
+ obj = klass.new
133
+
134
+ result = obj.setup_and_call :foo
135
+ result.must_equal "correct-result"
136
+ end
105
137
  end
106
138
  end
@@ -0,0 +1,59 @@
1
+ require 'gir_ffi_test_helper'
2
+
3
+ describe GirFFI::MethodStubber do
4
+ describe "#method_stub" do
5
+ let(:stubber) { GirFFI::MethodStubber.new(method_info) }
6
+ let(:result) { stubber.method_stub }
7
+
8
+ describe "for a regular method" do
9
+ let(:method_info) {
10
+ get_method_introspection_data("Regress", "TestObj", "instance_method") }
11
+
12
+ it "creates a method stub" do
13
+ result.must_equal <<-STUB.reset_indentation
14
+ def instance_method *args, &block
15
+ setup_and_call :instance_method, *args, &block
16
+ end
17
+ STUB
18
+ end
19
+ end
20
+
21
+ describe "for a static method" do
22
+ let(:method_info) {
23
+ get_method_introspection_data("Regress", "TestObj", "static_method") }
24
+
25
+ it "creates a class method stub" do
26
+ result.must_equal <<-STUB.reset_indentation
27
+ def self.static_method *args, &block
28
+ setup_and_call :static_method, *args, &block
29
+ end
30
+ STUB
31
+ end
32
+ end
33
+
34
+ describe "for a module function" do
35
+ let(:method_info) {
36
+ get_introspection_data("Regress", "test_int") }
37
+
38
+ it "creates a module method stub" do
39
+ result.must_equal <<-STUB.reset_indentation
40
+ def self.test_int *args, &block
41
+ setup_and_call :test_int, *args, &block
42
+ end
43
+ STUB
44
+ end
45
+ end
46
+
47
+ describe "for a method with an empty name" do
48
+ let(:method_info) { get_method_introspection_data("GLib", "IConv", "") }
49
+
50
+ it "creates a method stub with a safe name that sets up the unsafe method" do
51
+ result.must_equal <<-STUB.reset_indentation
52
+ def _ *args, &block
53
+ setup_and_call :"", *args, &block
54
+ end
55
+ STUB
56
+ end
57
+ end
58
+ end
59
+ end
@@ -210,6 +210,7 @@ describe GIMarshallingTests do
210
210
 
211
211
  describe "GIMarshallingTests::Interface3" do
212
212
  it "has a working method #test_variant_array_in" do
213
+ skip unless get_introspection_data 'GIMarshallingTests', 'Interface3'
213
214
  derived_klass.class_eval { include GIMarshallingTests::Interface3 }
214
215
  instance = make_derived_instance do |info|
215
216
  info.install_vfunc_implementation :test_variant_array_in, proc {|obj, in_|
@@ -0,0 +1,10 @@
1
+ require 'gir_ffi_test_helper'
2
+
3
+ # Tests generated classes, methods and functions in the GLib namespace.
4
+ describe "The generated GLib module" do
5
+ it "can auto-generate the GLib::IConv class" do
6
+ klass = GLib::IConv
7
+
8
+ klass.must_be_instance_of Class
9
+ end
10
+ end
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.7.0
4
+ version: 0.7.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: 2014-01-11 00:00:00.000000000 Z
11
+ date: 2014-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -80,7 +80,11 @@ dependencies:
80
80
  - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: '10.1'
83
- description:
83
+ description: |2
84
+ GirFFI creates bindings for GObject-based libraries at runtime based on introspection
85
+ data provided by the GObject Introspection Repository (GIR) system. Bindings are created
86
+ at runtime and use FFI to interface with the C libraries. In cases where the GIR does not
87
+ provide enough or correct information to create sane bindings, overrides may be created.
84
88
  email:
85
89
  - matijs@matijs.net
86
90
  executables: []
@@ -203,6 +207,7 @@ files:
203
207
  - lib/ffi-glib/variant.rb
204
208
  - lib/ffi-glib/array_methods.rb
205
209
  - lib/ffi-glib/s_list.rb
210
+ - lib/ffi-glib/iconv.rb
206
211
  - lib/ffi-gobject_introspection/i_struct_info.rb
207
212
  - lib/ffi-gobject_introspection/i_callback_info.rb
208
213
  - lib/ffi-gobject_introspection/i_arg_info.rb
@@ -238,6 +243,7 @@ files:
238
243
  - test/integration/method_lookup_test.rb
239
244
  - test/integration/generated_gimarshallingtests_test.rb
240
245
  - test/integration/generated_gio_test.rb
246
+ - test/integration/generated_glib_test.rb
241
247
  - test/integration/generated_pango_test.rb
242
248
  - test/integration/generated_secret_test.rb
243
249
  - test/integration/generated_gobject_test.rb
@@ -267,7 +273,9 @@ files:
267
273
  - test/gir_ffi/builders/object_builder_test.rb
268
274
  - test/gir_ffi/builders/property_builder_test.rb
269
275
  - test/gir_ffi/builders/module_builder_test.rb
276
+ - test/gir_ffi/builders/with_methods_test.rb
270
277
  - test/gir_ffi/builders/user_defined_builder_test.rb
278
+ - test/gir_ffi/method_stubber_test.rb
271
279
  - test/gir_ffi/variable_name_generator_test.rb
272
280
  - test/gir_ffi/ffi_ext/pointer_test.rb
273
281
  - test/gir_ffi/class_base_test.rb
@@ -294,6 +302,7 @@ files:
294
302
  - test/ffi-glib/s_list_test.rb
295
303
  - test/ffi-glib/hash_table_test.rb
296
304
  - test/ffi-glib/list_test.rb
305
+ - test/ffi-glib/iconv_test.rb
297
306
  - test/ffi-glib/array_test.rb
298
307
  - test/ffi-glib/ptr_array_test.rb
299
308
  - test/ffi-glib/byte_array_test.rb
@@ -325,7 +334,8 @@ files:
325
334
  - Rakefile
326
335
  - COPYING.LIB
327
336
  homepage: http://www.github.com/mvz/ruby-gir-ffi
328
- licenses: []
337
+ licenses:
338
+ - LGPL-2.1
329
339
  metadata: {}
330
340
  post_install_message:
331
341
  rdoc_options:
@@ -354,6 +364,7 @@ test_files:
354
364
  - test/ffi-glib/array_test.rb
355
365
  - test/ffi-glib/byte_array_test.rb
356
366
  - test/ffi-glib/hash_table_test.rb
367
+ - test/ffi-glib/iconv_test.rb
357
368
  - test/ffi-glib/list_test.rb
358
369
  - test/ffi-glib/ptr_array_test.rb
359
370
  - test/ffi-glib/ruby_closure_test.rb
@@ -394,6 +405,7 @@ test_files:
394
405
  - test/gir_ffi/builders/union_builder_test.rb
395
406
  - test/gir_ffi/builders/user_defined_builder_test.rb
396
407
  - test/gir_ffi/builders/vfunc_builder_test.rb
408
+ - test/gir_ffi/builders/with_methods_test.rb
397
409
  - test/gir_ffi/callback_base_test.rb
398
410
  - test/gir_ffi/class_base_test.rb
399
411
  - test/gir_ffi/ffi_ext/pointer_test.rb
@@ -409,6 +421,7 @@ test_files:
409
421
  - test/gir_ffi/info_ext/safe_constant_name_test.rb
410
422
  - test/gir_ffi/info_ext/safe_function_name_test.rb
411
423
  - test/gir_ffi/interface_base_test.rb
424
+ - test/gir_ffi/method_stubber_test.rb
412
425
  - test/gir_ffi/object_base_test.rb
413
426
  - test/gir_ffi/sized_array_test.rb
414
427
  - test/gir_ffi/type_map_test.rb
@@ -422,6 +435,7 @@ test_files:
422
435
  - test/integration/derived_classes_test.rb
423
436
  - test/integration/generated_gimarshallingtests_test.rb
424
437
  - test/integration/generated_gio_test.rb
438
+ - test/integration/generated_glib_test.rb
425
439
  - test/integration/generated_gobject_test.rb
426
440
  - test/integration/generated_pango_ft2_test.rb
427
441
  - test/integration/generated_pango_test.rb