gir_ffi 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,11 @@
1
+ == 0.0.14 / 2011-10-28
2
+
3
+ * Support GObject Introspection version 1.30:
4
+ - Add support for layouts with fixed-length arrays.
5
+ - Handle type names starting with underscores.
6
+ - Call g_signal_emitv directly to avoid conflict in introspection info
7
+ with earlier versions of GObject Introspection.
8
+
1
9
  == 0.0.13 / 2011-09-09
2
10
 
3
11
  * Remove IErrorDomain related code. This functinality was removed from
@@ -11,6 +11,7 @@ module GirFFI
11
11
  def initialize namespace, version=nil
12
12
  @namespace = namespace
13
13
  @version = version
14
+ # FIXME: Pass safe namespace as an argument
14
15
  @safe_namespace = @namespace.gsub(/^(.)/) { $1.upcase }
15
16
  end
16
17
 
@@ -7,7 +7,7 @@ module GirFFI
7
7
  def initialize info
8
8
  @info = info
9
9
  @namespace = @info.namespace
10
- @classname = @info.name.gsub(/^(.)/) { $1.upcase }
10
+ @classname = @info.safe_name
11
11
  end
12
12
 
13
13
  def build_class
@@ -20,6 +20,10 @@ module GirFFI
20
20
  if ffitype == :bool
21
21
  ffitype = :int
22
22
  end
23
+ if ffitype == :array
24
+ subtype = itypeinfo_to_ffitype_for_struct typeinfo.param_type(0)
25
+ ffitype = [subtype, typeinfo.array_fixed_size]
26
+ end
23
27
  ffitype
24
28
  end
25
29
 
@@ -31,11 +31,12 @@ module GirFFI
31
31
  end
32
32
  end
33
33
 
34
- fields.map do |finfo|
35
- [ finfo.name.to_sym,
36
- itypeinfo_to_ffitype_for_struct(finfo.field_type),
37
- finfo.offset ]
38
- end.flatten
34
+ fields.inject([]) do |spec, finfo|
35
+ spec +
36
+ [ finfo.name.to_sym,
37
+ itypeinfo_to_ffitype_for_struct(finfo.field_type),
38
+ finfo.offset ]
39
+ end
39
40
  end
40
41
  end
41
42
  end
@@ -53,6 +53,7 @@ module GirFFI
53
53
  Builder::Module.new(namespace, version).build_module_non_recursive
54
54
  end
55
55
 
56
+ # TODO: Move elsewhere, perhaps to Builder::Function.
56
57
  def self.attach_ffi_function lib, info
57
58
  sym = info.symbol
58
59
  argtypes = ffi_function_argument_types info
@@ -37,6 +37,14 @@ module GirFFI
37
37
  Lib.g_base_info_get_name @gobj
38
38
  end
39
39
 
40
+ def safe_name
41
+ if name =~ /^_/
42
+ "Private__" + name
43
+ else
44
+ name.gsub(/^(.)/) { $1.upcase }
45
+ end
46
+ end
47
+
40
48
  def info_type
41
49
  Lib.g_base_info_get_type @gobj
42
50
  end
@@ -6,6 +6,7 @@ module GirFFI
6
6
  base.extend ClassMethods
7
7
  extend_classes(base)
8
8
  attach_non_introspectable_functions(base)
9
+ preload_methods(base)
9
10
  build_extra_classes(base)
10
11
  end
11
12
 
@@ -29,6 +30,10 @@ module GirFFI
29
30
  [:pointer, base::ClosureMarshal], :void
30
31
  end
31
32
 
33
+ def self.preload_methods base
34
+ base._setup_method :signal_emitv
35
+ end
36
+
32
37
  def self.build_extra_classes base
33
38
  build_ruby_closure_class base
34
39
  end
@@ -99,7 +104,7 @@ module GirFFI
99
104
  arr = Helper.signal_arguments_to_gvalue_array signal, object, *args
100
105
  rval = Helper.gvalue_for_signal_return_value signal, object
101
106
 
102
- signal_emitv arr[:values], id, 0, rval
107
+ ::GObject::Lib.g_signal_emitv arr[:values], id, 0, rval
103
108
 
104
109
  rval
105
110
  end
@@ -129,7 +134,9 @@ module GirFFI
129
134
 
130
135
  module Helper
131
136
  TAG_TYPE_TO_GTYPE_NAME_MAP = {
132
- :utf8 => "gchararray"
137
+ :utf8 => "gchararray",
138
+ :gboolean => "gboolean",
139
+ :void => "void"
133
140
  }
134
141
 
135
142
  def self.signal_callback_args sig, klass, &block
@@ -162,13 +169,11 @@ module GirFFI
162
169
 
163
170
  def self.signal_argument_to_gvalue info, arg
164
171
  arg_type = info.argument_type
165
- tag = arg_type.tag
166
172
 
167
- if tag == :interface
168
- interface = info.argument_type.interface
173
+ val = gvalue_for_type_info arg_type
169
174
 
170
- val = ::GObject::Value.new
171
- val.init info.argument_type.interface.g_type
175
+ if arg_type.tag == :interface
176
+ interface = arg_type.interface
172
177
  case interface.info_type
173
178
  when :struct
174
179
  val.set_boxed arg
@@ -179,30 +184,31 @@ module GirFFI
179
184
  else
180
185
  raise NotImplementedError, interface.info_type
181
186
  end
182
-
183
- return val
184
187
  else
185
- val = ::GObject::Value.new
186
- val.init ::GObject.type_from_name(TAG_TYPE_TO_GTYPE_NAME_MAP[tag])
187
188
  val.set_ruby_value arg
188
189
  end
189
- end
190
190
 
191
- def self.gvalue_for_signal_return_value signal, object
192
- type = ::GObject.type_from_instance object
191
+ return val
192
+ end
193
193
 
194
- # TODO: Use same signal info as signal_arguments_to_gvalue_array
195
- id = ::GObject.signal_lookup signal, type
194
+ def self.gvalue_for_type_info info
195
+ tag = info.tag
196
+ gtype = case tag
197
+ when :interface
198
+ info.interface.g_type
199
+ when :void
200
+ return nil
201
+ else
202
+ ::GObject.type_from_name(TAG_TYPE_TO_GTYPE_NAME_MAP[tag])
203
+ end
204
+ ::GObject::Value.new.tap {|val| val.init gtype}
205
+ end
196
206
 
197
- query = ::GObject::SignalQuery.new
198
- ::GObject.signal_query id, query
207
+ def self.gvalue_for_signal_return_value signal, object
208
+ sig = object.class._find_signal signal
209
+ rettypeinfo = sig.return_type
199
210
 
200
- use_ret = (query[:return_type] != ::GObject.type_from_name("void"))
201
- if use_ret
202
- rval = ::GObject::Value.new
203
- rval.init query[:return_type]
204
- end
205
- rval
211
+ gvalue_for_type_info rettypeinfo
206
212
  end
207
213
 
208
214
  # TODO: Generate cast back methods using existing Argument builders.
@@ -1,4 +1,4 @@
1
1
  module GirFFI
2
- VERSION = "0.0.13"
2
+ VERSION = "0.0.14"
3
3
  end
4
4
 
@@ -9,7 +9,7 @@ class TypeBuilderTest < MiniTest::Spec
9
9
  stub(info = Object.new).parent { @gir.find_by_name 'GObject', 'Object' }
10
10
  stub(info).fields { [] }
11
11
  stub(info).info_type { :object }
12
- stub(info).name { 'Bar' }
12
+ stub(info).safe_name { 'Bar' }
13
13
  stub(info).namespace { 'Foo' }
14
14
 
15
15
  @classbuilder = GirFFI::Builder::Type::Object.new info
@@ -18,6 +18,38 @@ class TypeBuilderTest < MiniTest::Spec
18
18
  assert_equal [:parent, GObject::Object::Struct, 0], spec
19
19
  end
20
20
 
21
+ describe "for a layout with a fixed-length array" do
22
+ before do
23
+ stub(subtype = Object.new).pointer? { false }
24
+ stub(subtype).tag { :foo }
25
+
26
+ stub(@type = Object.new).pointer? { false }
27
+ stub(@type).tag { :array }
28
+ stub(@type).array_fixed_size { 2 }
29
+ stub(@type).param_type { subtype }
30
+
31
+ stub(field = Object.new).field_type { @type }
32
+ stub(field).name { "bar" }
33
+ stub(field).offset { 0 }
34
+
35
+ stub(@struct = Object.new).safe_name { 'Bar' }
36
+ stub(@struct).namespace { 'Foo' }
37
+ stub(@struct).fields { [ field ] }
38
+ end
39
+
40
+ it "creates the correct ffi type for the array" do
41
+ builder = GirFFI::Builder::Type::RegisteredType.new @struct
42
+ spec = builder.send :itypeinfo_to_ffitype_for_struct, @type
43
+ assert_equal [:foo, 2], spec
44
+ end
45
+
46
+ it "creates the correct layout specification" do
47
+ builder = GirFFI::Builder::Type::Struct.new @struct
48
+ spec = builder.send :layout_specification
49
+ assert_equal [:bar, [:foo, 2], 0], spec
50
+ end
51
+ end
52
+
21
53
  context "for Gtk::Widget" do
22
54
  setup do
23
55
  @cbuilder = GirFFI::Builder::Type::Object.new get_introspection_data('Gtk', 'Widget')
@@ -0,0 +1,16 @@
1
+ require File.expand_path('../test_helper.rb', File.dirname(__FILE__))
2
+
3
+ describe GirFFI::IBaseInfo do
4
+ describe "#safe_name" do
5
+ it "makes names starting with an underscore safe" do
6
+ stub(ptr = Object.new).null? { false }
7
+
8
+ info = GirFFI::IBaseInfo.wrap ptr
9
+
10
+ stub(info).name { "_foo" }
11
+
12
+ assert_equal "Private___foo", info.safe_name
13
+ end
14
+ end
15
+ end
16
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gir_ffi
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 13
10
- version: 0.0.13
9
+ - 14
10
+ version: 0.0.14
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matijs van Zuijlen
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-09 00:00:00 Z
18
+ date: 2011-10-28 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: ffi
@@ -158,6 +158,7 @@ files:
158
158
  - test/unit/i_repository_test.rb
159
159
  - test/unit/constant_builder_test.rb
160
160
  - test/unit/in_out_pointer_test.rb
161
+ - test/unit/i_base_info_test.rb
161
162
  - test/unit/callback_helper_test.rb
162
163
  - test/unit/builder_test.rb
163
164
  - test/unit/in_pointer_test.rb
@@ -222,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
223
  requirements: []
223
224
 
224
225
  rubyforge_project:
225
- rubygems_version: 1.7.2
226
+ rubygems_version: 1.8.10
226
227
  signing_key:
227
228
  specification_version: 3
228
229
  summary: FFI-based GObject binding using the GObject Introspection Repository
@@ -254,9 +255,9 @@ test_files:
254
255
  - test/unit/builder_test.rb
255
256
  - test/unit/callback_helper_test.rb
256
257
  - test/unit/constant_builder_test.rb
258
+ - test/unit/i_base_info_test.rb
257
259
  - test/unit/i_constant_info_test.rb
258
260
  - test/unit/i_repository_test.rb
259
261
  - test/unit/in_out_pointer_test.rb
260
262
  - test/unit/in_pointer_test.rb
261
263
  - test/unit/object_type_builder_test.rb
262
- has_rdoc: