gir_ffi 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +9 -0
- data/README.rdoc +7 -11
- data/examples/01_empty_window.rb +1 -1
- data/examples/02_hello_world.rb +1 -1
- data/examples/03_upgraded_hello_world.rb +1 -1
- data/examples/04_webkit.rb +2 -2
- data/lib/gir_ffi/arg_helper.rb +12 -23
- data/lib/gir_ffi/builder/argument.rb +69 -118
- data/lib/gir_ffi/builder/function.rb +2 -2
- data/lib/gir_ffi/builder/module.rb +6 -4
- data/lib/gir_ffi/builder/type/base.rb +35 -0
- data/lib/gir_ffi/builder/type/callback.rb +27 -0
- data/lib/gir_ffi/builder/type/enum.rb +27 -0
- data/lib/gir_ffi/builder/type/interface.rb +12 -0
- data/lib/gir_ffi/builder/type/object.rb +46 -0
- data/lib/gir_ffi/builder/type/registered_type.rb +156 -0
- data/lib/gir_ffi/builder/type/struct.rb +25 -0
- data/lib/gir_ffi/builder/type/struct_based.rb +40 -0
- data/lib/gir_ffi/builder/type/union.rb +26 -0
- data/lib/gir_ffi/builder/type.rb +33 -0
- data/lib/gir_ffi/builder.rb +19 -47
- data/lib/gir_ffi/i_arg_info.rb +11 -1
- data/lib/gir_ffi/i_base_info.rb +4 -3
- data/lib/gir_ffi/i_field_info.rb +4 -1
- data/lib/gir_ffi/i_interface_info.rb +3 -3
- data/lib/gir_ffi/i_object_info.rb +5 -3
- data/lib/gir_ffi/i_struct_info.rb +6 -8
- data/lib/gir_ffi/i_union_info.rb +3 -3
- data/lib/gir_ffi/overrides/gobject.rb +7 -7
- data/lib/gir_ffi.rb +2 -2
- data/test/builder_test.rb +1 -1
- data/test/girffi_test.rb +4 -2
- data/test/{class_builder_test.rb → type_builder_test.rb} +9 -9
- metadata +18 -9
- data/lib/gir_ffi/builder/class.rb +0 -286
data/lib/gir_ffi.rb
CHANGED
@@ -2,8 +2,8 @@ require 'gir_ffi/i_repository'
|
|
2
2
|
require 'gir_ffi/builder'
|
3
3
|
|
4
4
|
module GirFFI
|
5
|
-
def self.setup module_name
|
5
|
+
def self.setup module_name, version=nil
|
6
6
|
module_name = module_name.to_s
|
7
|
-
GirFFI::Builder.build_module module_name
|
7
|
+
GirFFI::Builder.build_module module_name, version
|
8
8
|
end
|
9
9
|
end
|
data/test/builder_test.rb
CHANGED
@@ -308,7 +308,7 @@ class BuilderTest < Test::Unit::TestCase
|
|
308
308
|
end
|
309
309
|
|
310
310
|
should "know its own class builder" do
|
311
|
-
assert GirFFI::Builder::
|
311
|
+
assert GirFFI::Builder::Type::Base === Regress::TestObj.gir_ffi_builder
|
312
312
|
end
|
313
313
|
|
314
314
|
context "its #torture_signature_0 method" do
|
data/test/girffi_test.rb
CHANGED
@@ -2,8 +2,10 @@ require File.expand_path('test_helper.rb', File.dirname(__FILE__))
|
|
2
2
|
|
3
3
|
class GirFFITest < Test::Unit::TestCase
|
4
4
|
context "GirFFI" do
|
5
|
-
should "
|
6
|
-
|
5
|
+
should "be able to set up cairo" do
|
6
|
+
assert_nothing_raised {
|
7
|
+
GirFFI.setup :cairo
|
8
|
+
}
|
7
9
|
end
|
8
10
|
end
|
9
11
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path('test_helper.rb', File.dirname(__FILE__))
|
2
2
|
|
3
|
-
class
|
4
|
-
context "The Builder::
|
3
|
+
class TypeBuilderTest < Test::Unit::TestCase
|
4
|
+
context "The Builder::Type class" do
|
5
5
|
setup do
|
6
6
|
@gir = GirFFI::IRepository.default
|
7
7
|
end
|
@@ -11,11 +11,11 @@ class ClassBuilderTest < Test::Unit::TestCase
|
|
11
11
|
|
12
12
|
stub(info = Object.new).parent { @gir.find_by_name 'GObject', 'Object' }
|
13
13
|
stub(info).fields { [] }
|
14
|
-
stub(info).
|
14
|
+
stub(info).info_type { :object }
|
15
15
|
stub(info).name { 'Bar' }
|
16
16
|
stub(info).namespace { 'Foo' }
|
17
17
|
|
18
|
-
@classbuilder = GirFFI::Builder::
|
18
|
+
@classbuilder = GirFFI::Builder::Type::Object.new info
|
19
19
|
|
20
20
|
spec = @classbuilder.send :layout_specification
|
21
21
|
assert_equal [:parent, GObject::Object::Struct, 0], spec
|
@@ -23,7 +23,7 @@ class ClassBuilderTest < Test::Unit::TestCase
|
|
23
23
|
|
24
24
|
context "for Gtk::Widget" do
|
25
25
|
setup do
|
26
|
-
@cbuilder = GirFFI::Builder::
|
26
|
+
@cbuilder = GirFFI::Builder::Type::Object.new @gir.find_by_name('Gtk', 'Widget')
|
27
27
|
end
|
28
28
|
|
29
29
|
context "looking at Gtk::Widget#show" do
|
@@ -42,19 +42,19 @@ class ClassBuilderTest < Test::Unit::TestCase
|
|
42
42
|
|
43
43
|
context 'the find_signal method' do
|
44
44
|
should 'find the signal "test" for TestObj' do
|
45
|
-
builder = GirFFI::Builder::
|
45
|
+
builder = GirFFI::Builder::Type::Object.new @gir.find_by_name('Regress', 'TestObj')
|
46
46
|
sig = builder.find_signal 'test'
|
47
47
|
assert_equal 'test', sig.name
|
48
48
|
end
|
49
49
|
|
50
50
|
should 'find the signal "test" for TestSubObj' do
|
51
|
-
builder = GirFFI::Builder::
|
51
|
+
builder = GirFFI::Builder::Type::Object.new @gir.find_by_name('Regress', 'TestSubObj')
|
52
52
|
sig = builder.find_signal 'test'
|
53
53
|
assert_equal 'test', sig.name
|
54
54
|
end
|
55
55
|
|
56
56
|
should 'find the signal "changed" for Gtk::Entry' do
|
57
|
-
builder = GirFFI::Builder::
|
57
|
+
builder = GirFFI::Builder::Type::Object.new @gir.find_by_name('Gtk', 'Entry')
|
58
58
|
sig = builder.find_signal 'changed'
|
59
59
|
assert_equal 'changed', sig.name
|
60
60
|
end
|
@@ -62,7 +62,7 @@ class ClassBuilderTest < Test::Unit::TestCase
|
|
62
62
|
|
63
63
|
context "for GObject::TypeCValue (a union)" do
|
64
64
|
setup do
|
65
|
-
@cbuilder = GirFFI::Builder::
|
65
|
+
@cbuilder = GirFFI::Builder::Type::Union.new @gir.find_by_name('GObject', 'TypeCValue')
|
66
66
|
end
|
67
67
|
|
68
68
|
should "not raise an error looking for a method that doesn't exist" do
|
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:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
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-04-
|
18
|
+
date: 2011-04-08 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
version: 1.0.2
|
67
67
|
type: :development
|
68
68
|
version_requirements: *id003
|
69
|
-
description:
|
69
|
+
description:
|
70
70
|
email:
|
71
71
|
- matijs@matijs.net
|
72
72
|
executables: []
|
@@ -89,7 +89,16 @@ files:
|
|
89
89
|
- lib/gir_ffi/builder.rb
|
90
90
|
- lib/gir_ffi/builder/module.rb
|
91
91
|
- lib/gir_ffi/builder/function.rb
|
92
|
-
- lib/gir_ffi/builder/
|
92
|
+
- lib/gir_ffi/builder/type/base.rb
|
93
|
+
- lib/gir_ffi/builder/type/interface.rb
|
94
|
+
- lib/gir_ffi/builder/type/struct_based.rb
|
95
|
+
- lib/gir_ffi/builder/type/struct.rb
|
96
|
+
- lib/gir_ffi/builder/type/enum.rb
|
97
|
+
- lib/gir_ffi/builder/type/registered_type.rb
|
98
|
+
- lib/gir_ffi/builder/type/callback.rb
|
99
|
+
- lib/gir_ffi/builder/type/union.rb
|
100
|
+
- lib/gir_ffi/builder/type/object.rb
|
101
|
+
- lib/gir_ffi/builder/type.rb
|
93
102
|
- lib/gir_ffi/builder/argument.rb
|
94
103
|
- lib/gir_ffi/i_enum_info.rb
|
95
104
|
- lib/gir_ffi/i_value_info.rb
|
@@ -130,12 +139,12 @@ files:
|
|
130
139
|
- test/lib/m4/jhflags.m4
|
131
140
|
- test/class_base_test.rb
|
132
141
|
- test/test_helper.rb
|
133
|
-
- test/class_builder_test.rb
|
134
142
|
- test/girffi_test.rb
|
135
143
|
- test/module_builder_test.rb
|
136
144
|
- test/i_object_info_test.rb
|
137
145
|
- test/g_object_overrides_test.rb
|
138
146
|
- test/generated_gtk_test.rb
|
147
|
+
- test/type_builder_test.rb
|
139
148
|
- test/builder_test.rb
|
140
149
|
- test/gtk_overrides_test.rb
|
141
150
|
- test/generated_gio_test.rb
|
@@ -189,12 +198,11 @@ rubyforge_project:
|
|
189
198
|
rubygems_version: 1.6.2
|
190
199
|
signing_key:
|
191
200
|
specification_version: 3
|
192
|
-
summary:
|
201
|
+
summary: FFI-based GObject binding using the GObject Introspection Repository
|
193
202
|
test_files:
|
194
203
|
- test/arg_helper_test.rb
|
195
204
|
- test/builder_test.rb
|
196
205
|
- test/class_base_test.rb
|
197
|
-
- test/class_builder_test.rb
|
198
206
|
- test/function_definition_builder_test.rb
|
199
207
|
- test/g_object_overrides_test.rb
|
200
208
|
- test/g_object_test.rb
|
@@ -211,3 +219,4 @@ test_files:
|
|
211
219
|
- test/lib/m4/jhflags.m4
|
212
220
|
- test/module_builder_test.rb
|
213
221
|
- test/test_helper.rb
|
222
|
+
- test/type_builder_test.rb
|
@@ -1,286 +0,0 @@
|
|
1
|
-
require 'gir_ffi/builder_helper'
|
2
|
-
module GirFFI
|
3
|
-
# Builds a class based on information found in the introspection
|
4
|
-
# repository.
|
5
|
-
class Builder::Class
|
6
|
-
include BuilderHelper
|
7
|
-
|
8
|
-
def initialize info
|
9
|
-
@info = info
|
10
|
-
@namespace = @info.namespace
|
11
|
-
@classname = @info.name.gsub(/^(.)/) { $1.upcase }
|
12
|
-
end
|
13
|
-
|
14
|
-
def generate
|
15
|
-
build_class
|
16
|
-
end
|
17
|
-
|
18
|
-
def setup_method method
|
19
|
-
klass = build_class
|
20
|
-
meta = (class << klass; self; end)
|
21
|
-
|
22
|
-
go = method_introspection_data method
|
23
|
-
raise NoMethodError unless go
|
24
|
-
attach_and_define_method method, go, meta
|
25
|
-
end
|
26
|
-
|
27
|
-
def setup_instance_method method
|
28
|
-
go = instance_method_introspection_data method
|
29
|
-
result = attach_and_define_method method, go, build_class
|
30
|
-
|
31
|
-
unless result
|
32
|
-
if parent
|
33
|
-
return superclass.gir_ffi_builder.setup_instance_method method
|
34
|
-
else
|
35
|
-
return false
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
true
|
40
|
-
end
|
41
|
-
|
42
|
-
def find_signal signal_name
|
43
|
-
signal_definers.each do |inf|
|
44
|
-
inf.signals.each do |sig|
|
45
|
-
return sig if sig.name == signal_name
|
46
|
-
end
|
47
|
-
end
|
48
|
-
if parent
|
49
|
-
return superclass.gir_ffi_builder.find_signal signal_name
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
def build_class
|
56
|
-
unless defined? @klass
|
57
|
-
case info.type
|
58
|
-
when :object, :struct, :interface
|
59
|
-
instantiate_struct_class
|
60
|
-
when :union
|
61
|
-
instantiate_union_class
|
62
|
-
when :enum, :flags
|
63
|
-
instantiate_enum_class
|
64
|
-
when :callback
|
65
|
-
instantiate_callback_class
|
66
|
-
else
|
67
|
-
raise NotImplementedError, "Cannot build classes of type #{info.type}"
|
68
|
-
end
|
69
|
-
end
|
70
|
-
@klass
|
71
|
-
end
|
72
|
-
|
73
|
-
def info
|
74
|
-
unless defined? @info
|
75
|
-
@info = gir.find_by_name @namespace, @classname
|
76
|
-
raise "Class #{@classname} not found in namespace #{@namespace}" if @info.nil?
|
77
|
-
end
|
78
|
-
@info
|
79
|
-
end
|
80
|
-
|
81
|
-
def parent
|
82
|
-
unless defined? @parent
|
83
|
-
if info.type == :object
|
84
|
-
pr = info.parent
|
85
|
-
if pr.nil? or (pr.name == @classname and pr.namespace == @namespace)
|
86
|
-
@parent = nil
|
87
|
-
else
|
88
|
-
@parent = pr
|
89
|
-
end
|
90
|
-
else
|
91
|
-
@parent = nil
|
92
|
-
end
|
93
|
-
end
|
94
|
-
@parent
|
95
|
-
end
|
96
|
-
|
97
|
-
def superclass
|
98
|
-
unless defined? @superclass
|
99
|
-
if parent
|
100
|
-
@superclass = Builder.build_class parent
|
101
|
-
else
|
102
|
-
@superclass = GirFFI::ClassBase
|
103
|
-
end
|
104
|
-
end
|
105
|
-
@superclass
|
106
|
-
end
|
107
|
-
|
108
|
-
def namespace_module
|
109
|
-
@namespace_module ||= Builder.build_module @namespace
|
110
|
-
end
|
111
|
-
|
112
|
-
def lib
|
113
|
-
@lib ||= namespace_module.const_get :Lib
|
114
|
-
end
|
115
|
-
|
116
|
-
def instantiate_struct_class
|
117
|
-
@klass = get_or_define_class namespace_module, @classname, superclass
|
118
|
-
@structklass = get_or_define_class @klass, :Struct, FFI::Struct
|
119
|
-
setup_class unless already_set_up
|
120
|
-
end
|
121
|
-
|
122
|
-
def instantiate_union_class
|
123
|
-
@klass = get_or_define_class namespace_module, @classname, superclass
|
124
|
-
@structklass = get_or_define_class @klass, :Struct, FFI::Union
|
125
|
-
setup_class unless already_set_up
|
126
|
-
end
|
127
|
-
|
128
|
-
def instantiate_enum_class
|
129
|
-
@klass = optionally_define_constant namespace_module, @classname do
|
130
|
-
vals = info.values.map {|vinfo| [vinfo.name.to_sym, vinfo.value]}.flatten
|
131
|
-
lib.enum(@classname.to_sym, vals)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
def instantiate_callback_class
|
136
|
-
@klass = optionally_define_constant namespace_module, @classname do
|
137
|
-
args = Builder.ffi_function_argument_types info
|
138
|
-
ret = Builder.ffi_function_return_type info
|
139
|
-
lib.callback @classname.to_sym, args, ret
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def setup_class
|
144
|
-
setup_layout
|
145
|
-
setup_constants
|
146
|
-
stub_methods
|
147
|
-
setup_gtype_getter
|
148
|
-
|
149
|
-
setup_vfunc_invokers if info.type == :object
|
150
|
-
provide_struct_constructor if info.type == :struct
|
151
|
-
end
|
152
|
-
|
153
|
-
def setup_layout
|
154
|
-
spec = layout_specification
|
155
|
-
@structklass.class_eval { layout(*spec) }
|
156
|
-
end
|
157
|
-
|
158
|
-
def layout_specification
|
159
|
-
fields = if info.type == :interface
|
160
|
-
[]
|
161
|
-
else
|
162
|
-
info.fields
|
163
|
-
end
|
164
|
-
|
165
|
-
if fields.empty?
|
166
|
-
if parent
|
167
|
-
return [:parent, superclass.const_get(:Struct), 0]
|
168
|
-
else
|
169
|
-
return [:dummy, :char, 0]
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
fields.map do |finfo|
|
174
|
-
[ finfo.name.to_sym,
|
175
|
-
itypeinfo_to_ffitype_for_struct(finfo.type),
|
176
|
-
finfo.offset ]
|
177
|
-
end.flatten
|
178
|
-
end
|
179
|
-
|
180
|
-
def itypeinfo_to_ffitype_for_struct typeinfo
|
181
|
-
ffitype = Builder.itypeinfo_to_ffitype typeinfo
|
182
|
-
if ffitype.kind_of?(Class) and const_defined_for ffitype, :Struct
|
183
|
-
ffitype = ffitype.const_get :Struct
|
184
|
-
end
|
185
|
-
if ffitype == :bool
|
186
|
-
ffitype = :int
|
187
|
-
end
|
188
|
-
ffitype
|
189
|
-
end
|
190
|
-
|
191
|
-
def stub_methods
|
192
|
-
info.methods.each do |minfo|
|
193
|
-
@klass.class_eval method_stub(minfo.name, minfo.method?)
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
def method_stub symbol, is_instance_method
|
198
|
-
"
|
199
|
-
def #{is_instance_method ? '' : 'self.'}#{symbol} *args, &block
|
200
|
-
setup_and_call :#{symbol}, *args, &block
|
201
|
-
end
|
202
|
-
"
|
203
|
-
end
|
204
|
-
|
205
|
-
def setup_gtype_getter
|
206
|
-
getter = info.type_init
|
207
|
-
return if getter.nil? or getter == "intern"
|
208
|
-
lib.attach_function getter.to_sym, [], :size_t
|
209
|
-
@klass.class_eval "
|
210
|
-
def self.get_gtype
|
211
|
-
::#{lib}.#{getter}
|
212
|
-
end
|
213
|
-
"
|
214
|
-
end
|
215
|
-
|
216
|
-
def setup_vfunc_invokers
|
217
|
-
info.vfuncs.each do |vfinfo|
|
218
|
-
invoker = vfinfo.invoker
|
219
|
-
next if invoker.nil?
|
220
|
-
next if invoker.name == vfinfo.name
|
221
|
-
|
222
|
-
@klass.class_eval "
|
223
|
-
def #{vfinfo.name} *args, &block
|
224
|
-
#{invoker.name}(*args, &block)
|
225
|
-
end
|
226
|
-
"
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
def provide_struct_constructor
|
231
|
-
return if info.find_method 'new'
|
232
|
-
|
233
|
-
(class << @klass; self; end).class_eval {
|
234
|
-
alias_method :new, :allocate
|
235
|
-
}
|
236
|
-
end
|
237
|
-
|
238
|
-
def setup_constants
|
239
|
-
@klass.const_set :GIR_INFO, info
|
240
|
-
@klass.const_set :GIR_FFI_BUILDER, self
|
241
|
-
end
|
242
|
-
|
243
|
-
def already_set_up
|
244
|
-
const_defined_for @klass, :GIR_FFI_BUILDER
|
245
|
-
end
|
246
|
-
|
247
|
-
def method_introspection_data method
|
248
|
-
info.find_method method
|
249
|
-
end
|
250
|
-
|
251
|
-
def instance_method_introspection_data method
|
252
|
-
data = method_introspection_data method
|
253
|
-
return !data.nil? && data.method? ? data : nil
|
254
|
-
end
|
255
|
-
|
256
|
-
def function_definition go
|
257
|
-
Builder::Function.new(go, lib).generate
|
258
|
-
end
|
259
|
-
|
260
|
-
def attach_and_define_method method, go, modul
|
261
|
-
return false if go.nil?
|
262
|
-
Builder.attach_ffi_function lib, go
|
263
|
-
modul.class_eval { remove_method method }
|
264
|
-
modul.class_eval function_definition(go)
|
265
|
-
true
|
266
|
-
end
|
267
|
-
|
268
|
-
def gir
|
269
|
-
unless defined? @gir
|
270
|
-
@gir = IRepository.default
|
271
|
-
@gir.require @namespace, nil
|
272
|
-
end
|
273
|
-
@gir
|
274
|
-
end
|
275
|
-
|
276
|
-
def get_or_define_class namespace, name, parent
|
277
|
-
optionally_define_constant(namespace, name) {
|
278
|
-
Class.new parent
|
279
|
-
}
|
280
|
-
end
|
281
|
-
|
282
|
-
def signal_definers
|
283
|
-
[info] + (info.type == :object ? info.interfaces : [])
|
284
|
-
end
|
285
|
-
end
|
286
|
-
end
|