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.
- data/History.txt +8 -0
- data/README.md +1 -1
- data/TODO.rdoc +12 -4
- data/lib/ffi-glib.rb +0 -5
- data/lib/ffi-glib/list.rb +1 -1
- data/lib/ffi-glib/s_list.rb +1 -1
- data/lib/ffi-gobject.rb +2 -3
- data/lib/ffi-gobject/closure.rb +4 -3
- data/lib/ffi-gobject_introspection/i_base_info.rb +11 -14
- data/lib/ffi-gobject_introspection/i_constant_info.rb +1 -1
- data/lib/ffi-gobject_introspection/i_function_info.rb +0 -6
- data/lib/ffi-gobject_introspection/lib.rb +8 -2
- data/lib/gir_ffi.rb +5 -0
- data/lib/gir_ffi/arg_helper.rb +1 -1
- data/lib/gir_ffi/argument_builder.rb +161 -0
- data/lib/gir_ffi/base_argument_builder.rb +146 -0
- data/lib/gir_ffi/builder/field.rb +7 -5
- data/lib/gir_ffi/builder/module.rb +3 -14
- data/lib/gir_ffi/builder/property.rb +0 -2
- data/lib/gir_ffi/builder/type/callback.rb +0 -8
- data/lib/gir_ffi/builder/type/constant.rb +0 -4
- data/lib/gir_ffi/builder/type/enum.rb +0 -4
- data/lib/gir_ffi/builder/type/interface.rb +0 -4
- data/lib/gir_ffi/builder/type/object.rb +0 -1
- data/lib/gir_ffi/builder/type/struct_based.rb +0 -6
- data/lib/gir_ffi/builder/type/union.rb +0 -4
- data/lib/gir_ffi/builder/type/with_layout.rb +0 -1
- data/lib/gir_ffi/builder/type/with_methods.rb +1 -7
- data/lib/gir_ffi/callback.rb +9 -0
- data/lib/gir_ffi/callback_helper.rb +8 -1
- data/lib/gir_ffi/class_base.rb +6 -26
- data/lib/gir_ffi/error_argument_builder.rb +17 -0
- data/lib/gir_ffi/{builder/function.rb → function_builder.rb} +14 -11
- data/lib/gir_ffi/in_out_pointer.rb +29 -36
- data/lib/gir_ffi/in_pointer.rb +1 -1
- data/lib/gir_ffi/info_ext.rb +6 -0
- data/lib/gir_ffi/info_ext/i_field_info.rb +0 -2
- data/lib/gir_ffi/info_ext/i_type_info.rb +29 -10
- data/lib/gir_ffi/info_ext/safe_constant_name.rb +21 -0
- data/lib/gir_ffi/info_ext/safe_function_name.rb +13 -0
- data/lib/gir_ffi/interface_base.rb +1 -11
- data/lib/gir_ffi/module_base.rb +0 -10
- data/lib/gir_ffi/null_argument_builder.rb +9 -0
- data/lib/gir_ffi/return_value_builder.rb +75 -0
- data/lib/gir_ffi/setter_argument_info.rb +16 -0
- data/lib/gir_ffi/type_map.rb +10 -1
- data/lib/gir_ffi/version.rb +1 -1
- data/tasks/test.rake +61 -0
- data/test/base_test_helper.rb +0 -2
- data/test/ffi-gobject/value_test.rb +15 -0
- data/test/ffi-gobject_introspection/i_base_info_test.rb +31 -6
- data/test/ffi-gobject_introspection/i_function_info_test.rb +0 -17
- data/test/ffi-gobject_introspection/lib_test.rb +0 -55
- data/test/ffi-gobject_test.rb +2 -1
- data/test/gir_ffi/argument_builder_test.rb +414 -0
- data/test/gir_ffi/base_argument_builder_test.rb +13 -0
- data/test/gir_ffi/builder/module_test.rb +4 -40
- data/test/gir_ffi/builder/type/callback_test.rb +0 -27
- data/test/gir_ffi/builder/type/constant_test.rb +0 -12
- data/test/gir_ffi/builder/type/enum_test.rb +0 -20
- data/test/gir_ffi/builder/type/interface_test.rb +0 -11
- data/test/gir_ffi/builder/type/object_test.rb +2 -2
- data/test/gir_ffi/builder/type/struct_test.rb +0 -39
- data/test/gir_ffi/builder/type/unintrospectable_test.rb +1 -1
- data/test/gir_ffi/builder/type/union_test.rb +0 -11
- data/test/gir_ffi/builder_test.rb +3 -11
- data/test/gir_ffi/callback_helper_test.rb +7 -0
- data/test/gir_ffi/{builder/function_test.rb → function_builder_test.rb} +16 -28
- data/test/gir_ffi/in_out_pointer_test.rb +0 -20
- data/test/gir_ffi/info_ext/i_type_info_test.rb +112 -26
- data/test/gir_ffi/info_ext/safe_constant_name_test.rb +16 -0
- data/test/gir_ffi/info_ext/safe_function_name_test.rb +22 -0
- data/test/gir_ffi/return_value_builder_test.rb +355 -0
- data/test/integration/generated_gimarshallingtests_test.rb +608 -296
- data/test/integration/generated_regress_test.rb +879 -494
- metadata +35 -24
- data/lib/gir_ffi/builder/argument.rb +0 -569
- data/lib/gir_ffi/builder/argument/base.rb +0 -151
- data/lib/gir_ffi/builder/argument/in_base.rb +0 -14
- data/lib/gir_ffi/builder/argument/in_out_base.rb +0 -18
- data/lib/gir_ffi/builder/argument/out_base.rb +0 -15
- data/test/gir_ffi/builder/argument/base_test.rb +0 -55
- data/test/integration/pretty_print_test.rb +0 -33
@@ -1,5 +1,7 @@
|
|
1
|
-
require 'gir_ffi/
|
1
|
+
require 'gir_ffi/argument_builder'
|
2
|
+
require 'gir_ffi/return_value_builder'
|
2
3
|
require 'gir_ffi/variable_name_generator'
|
4
|
+
require 'gir_ffi/setter_argument_info'
|
3
5
|
|
4
6
|
module GirFFI
|
5
7
|
module Builder
|
@@ -44,14 +46,14 @@ module GirFFI
|
|
44
46
|
end
|
45
47
|
|
46
48
|
def return_value_builder
|
47
|
-
|
48
|
-
|
49
|
+
vargen = VariableNameGenerator.new
|
50
|
+
@rv_builder ||= ReturnValueBuilder.new vargen, @info.field_type, false
|
49
51
|
end
|
50
52
|
|
51
53
|
def setter_builder
|
52
|
-
type = @info.field_type
|
53
54
|
vargen = VariableNameGenerator.new
|
54
|
-
|
55
|
+
argument_info = SetterArgumentInfo.new "value", @info.field_type
|
56
|
+
ArgumentBuilder.new vargen, argument_info
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'gir_ffi/builder_helper'
|
2
2
|
require 'gir_ffi/module_base'
|
3
|
-
require 'gir_ffi/
|
3
|
+
require 'gir_ffi/function_builder'
|
4
4
|
require 'indentation'
|
5
5
|
|
6
6
|
module GirFFI
|
@@ -60,15 +60,6 @@ module GirFFI
|
|
60
60
|
@module
|
61
61
|
end
|
62
62
|
|
63
|
-
def pretty_print
|
64
|
-
buf = "module #{@safe_namespace}\n"
|
65
|
-
gir.infos(@namespace).each do |info|
|
66
|
-
buf << sub_builder(info).pretty_print.indent
|
67
|
-
buf << "\n"
|
68
|
-
end
|
69
|
-
buf << "end"
|
70
|
-
end
|
71
|
-
|
72
63
|
private
|
73
64
|
|
74
65
|
def build_dependencies
|
@@ -103,13 +94,11 @@ module GirFFI
|
|
103
94
|
@lib.ffi_lib(*libspec.split(/,/))
|
104
95
|
end
|
105
96
|
end
|
106
|
-
|
107
|
-
optionally_define_constant(@lib, :CALLBACKS) { [] }
|
108
97
|
end
|
109
98
|
|
110
99
|
def sub_builder info
|
111
100
|
if info.info_type == :function
|
112
|
-
|
101
|
+
FunctionBuilder.new(info, libmodule)
|
113
102
|
else
|
114
103
|
Builder::Type.builder_for info
|
115
104
|
end
|
@@ -126,7 +115,7 @@ module GirFFI
|
|
126
115
|
end
|
127
116
|
|
128
117
|
def function_definition info, libmodule
|
129
|
-
|
118
|
+
FunctionBuilder.new(info, libmodule).generate
|
130
119
|
end
|
131
120
|
|
132
121
|
def gir
|
@@ -13,14 +13,6 @@ module GirFFI
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
def pretty_print
|
17
|
-
args = argument_types.map do |arg|
|
18
|
-
arg.is_a?(FFI::Enum) ? arg.tag : arg.inspect
|
19
|
-
end
|
20
|
-
return "#{@classname} = Lib.callback #{callback_sym.inspect}, " +
|
21
|
-
"[#{args.join(', ')}], #{return_type.inspect}"
|
22
|
-
end
|
23
|
-
|
24
16
|
def callback_sym
|
25
17
|
@classname.to_sym
|
26
18
|
end
|
@@ -8,10 +8,6 @@ module GirFFI
|
|
8
8
|
# triggered by a missing constant in the parent namespace. The
|
9
9
|
# constant will be attached to the appropriate namespace module.
|
10
10
|
class Constant < Base
|
11
|
-
def pretty_print
|
12
|
-
"#{@classname} = #{info.value.inspect}"
|
13
|
-
end
|
14
|
-
|
15
11
|
private
|
16
12
|
|
17
13
|
def instantiate_class
|
@@ -7,10 +7,6 @@ module GirFFI
|
|
7
7
|
# attached to the appropriate namespace module, and will be defined
|
8
8
|
# as an enum for FFI.
|
9
9
|
class Enum < RegisteredType
|
10
|
-
def pretty_print
|
11
|
-
"#{@classname} = Lib.enum #{enum_sym.inspect}, #{value_spec.inspect}"
|
12
|
-
end
|
13
|
-
|
14
10
|
private
|
15
11
|
|
16
12
|
def enum_sym
|
@@ -38,7 +38,7 @@ module GirFFI
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def function_definition_builder go
|
41
|
-
|
41
|
+
FunctionBuilder.new(go, lib)
|
42
42
|
end
|
43
43
|
|
44
44
|
def function_definition go
|
@@ -58,12 +58,6 @@ module GirFFI
|
|
58
58
|
@klass.class_eval MethodStubber.new(minfo).method_stub
|
59
59
|
end
|
60
60
|
end
|
61
|
-
|
62
|
-
def pretty_print_methods
|
63
|
-
info.get_methods.map do |minfo|
|
64
|
-
function_definition_builder(minfo).pretty_print.indent + "\n"
|
65
|
-
end.join
|
66
|
-
end
|
67
61
|
end
|
68
62
|
end
|
69
63
|
end
|
@@ -1,10 +1,13 @@
|
|
1
1
|
module GirFFI
|
2
|
+
# TODO: Turn module into a class, use instance methods.
|
2
3
|
module CallbackHelper
|
4
|
+
CALLBACKS = []
|
5
|
+
|
3
6
|
def self.wrap_in_callback_args_mapper namespace, name, prc
|
4
7
|
return prc if FFI::Function === prc
|
5
8
|
return nil if prc.nil?
|
6
9
|
info = GObjectIntrospection::IRepository.default.find_by_name namespace, name
|
7
|
-
return
|
10
|
+
return Callback.new do |*args|
|
8
11
|
prc.call(*map_callback_args(args, info))
|
9
12
|
end
|
10
13
|
end
|
@@ -55,6 +58,10 @@ module GirFFI
|
|
55
58
|
GirFFI::ArgHelper::OBJECT_STORE[arg.address]
|
56
59
|
end
|
57
60
|
end
|
61
|
+
|
62
|
+
def self.store_callback prc
|
63
|
+
CALLBACKS << prc
|
64
|
+
end
|
58
65
|
end
|
59
66
|
end
|
60
67
|
|
data/lib/gir_ffi/class_base.rb
CHANGED
@@ -11,8 +11,8 @@ module GirFFI
|
|
11
11
|
|
12
12
|
def setup_and_call method, *arguments, &block
|
13
13
|
result = self.class.ancestors.any? do |klass|
|
14
|
-
klass.respond_to?(:
|
15
|
-
klass.
|
14
|
+
klass.respond_to?(:setup_instance_method) &&
|
15
|
+
klass.setup_instance_method(method.to_s)
|
16
16
|
end
|
17
17
|
|
18
18
|
unless result
|
@@ -24,8 +24,8 @@ module GirFFI
|
|
24
24
|
|
25
25
|
def self.setup_and_call method, *arguments, &block
|
26
26
|
result = self.ancestors.any? do |klass|
|
27
|
-
klass.respond_to?(:
|
28
|
-
klass.
|
27
|
+
klass.respond_to?(:setup_method) &&
|
28
|
+
klass.setup_method(method.to_s)
|
29
29
|
end
|
30
30
|
|
31
31
|
unless result
|
@@ -36,40 +36,20 @@ module GirFFI
|
|
36
36
|
end
|
37
37
|
|
38
38
|
class << self
|
39
|
-
# @deprecated Compatibility function. Remove in version 0.5.0.
|
40
|
-
def ffi_structure
|
41
|
-
self::Struct
|
42
|
-
end
|
43
|
-
|
44
39
|
def gir_info
|
45
40
|
self.const_get :GIR_INFO
|
46
41
|
end
|
47
42
|
|
48
|
-
# @deprecated Compatibility function. Remove in version 0.5.0.
|
49
|
-
def _builder
|
50
|
-
gir_ffi_builder
|
51
|
-
end
|
52
|
-
|
53
43
|
def gir_ffi_builder
|
54
44
|
self.const_get :GIR_FFI_BUILDER
|
55
45
|
end
|
56
46
|
|
57
|
-
# @deprecated Compatibility function. Remove in version 0.5.0.
|
58
|
-
def _setup_method name
|
59
|
-
setup_method name
|
60
|
-
end
|
61
|
-
|
62
47
|
def setup_method name
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
# @deprecated Compatibility function. Remove in version 0.5.0.
|
67
|
-
def _setup_instance_method name
|
68
|
-
setup_instance_method name
|
48
|
+
gir_ffi_builder.setup_method name
|
69
49
|
end
|
70
50
|
|
71
51
|
def setup_instance_method name
|
72
|
-
|
52
|
+
gir_ffi_builder.setup_instance_method name
|
73
53
|
end
|
74
54
|
|
75
55
|
alias_method :_real_new, :new
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'gir_ffi/base_argument_builder'
|
2
|
+
|
3
|
+
module GirFFI
|
4
|
+
# Implements argument processing for error handling arguments. These
|
5
|
+
# arguments are not part of the introspected signature, but their
|
6
|
+
# presence is indicated by the 'throws' attribute of the function.
|
7
|
+
class ErrorArgumentBuilder < BaseArgumentBuilder
|
8
|
+
def pre
|
9
|
+
[ "#{callarg} = FFI::MemoryPointer.new(:pointer).write_pointer nil" ]
|
10
|
+
end
|
11
|
+
|
12
|
+
def post
|
13
|
+
[ "GirFFI::ArgHelper.check_error(#{callarg})" ]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
@@ -1,10 +1,13 @@
|
|
1
|
-
require 'gir_ffi/
|
1
|
+
require 'gir_ffi/argument_builder'
|
2
|
+
require 'gir_ffi/return_value_builder'
|
3
|
+
require 'gir_ffi/error_argument_builder'
|
4
|
+
require 'gir_ffi/null_argument_builder'
|
2
5
|
require 'gir_ffi/variable_name_generator'
|
3
6
|
|
4
|
-
module GirFFI
|
7
|
+
module GirFFI
|
5
8
|
# Implements the creation of a Ruby function definition out of a GIR
|
6
9
|
# IFunctionInfo.
|
7
|
-
class
|
10
|
+
class FunctionBuilder
|
8
11
|
def initialize info, libmodule
|
9
12
|
@info = info
|
10
13
|
@libmodule = libmodule
|
@@ -12,8 +15,9 @@ module GirFFI::Builder
|
|
12
15
|
|
13
16
|
def generate
|
14
17
|
vargen = GirFFI::VariableNameGenerator.new
|
15
|
-
@data = @info.args.map {|arg|
|
16
|
-
@rvdata =
|
18
|
+
@data = @info.args.map {|arg| ArgumentBuilder.new vargen, arg }
|
19
|
+
@rvdata = ReturnValueBuilder.new(vargen, @info.return_type,
|
20
|
+
@info.constructor?)
|
17
21
|
|
18
22
|
alldata = @data.dup << @rvdata
|
19
23
|
|
@@ -29,14 +33,10 @@ module GirFFI::Builder
|
|
29
33
|
return filled_out_template
|
30
34
|
end
|
31
35
|
|
32
|
-
def pretty_print
|
33
|
-
generate
|
34
|
-
end
|
35
|
-
|
36
36
|
private
|
37
37
|
|
38
38
|
def setup_error_argument vargen
|
39
|
-
klass = @info.throws? ?
|
39
|
+
klass = @info.throws? ? ErrorArgumentBuilder : NullArgumentBuilder
|
40
40
|
@errarg = klass.new vargen, nil, nil, :error
|
41
41
|
end
|
42
42
|
|
@@ -78,7 +78,10 @@ module GirFFI::Builder
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def post
|
81
|
-
|
81
|
+
args = @data.sort_by {|arg| arg.type_info.array_length}
|
82
|
+
|
83
|
+
po = args.map {|arg|arg.post} +
|
84
|
+
@rvdata.post
|
82
85
|
po.unshift @errarg.post
|
83
86
|
|
84
87
|
po += @data.map {|item| item.cleanup}
|
@@ -4,11 +4,17 @@ module GirFFI
|
|
4
4
|
class InOutPointer < FFI::Pointer
|
5
5
|
attr_reader :value_type, :sub_type
|
6
6
|
|
7
|
-
def initialize
|
8
|
-
|
9
|
-
@ffi_type = ffi_type
|
7
|
+
def initialize value, type, sub_type=nil
|
8
|
+
@ffi_type = TypeMap.map_basic_type_or_string type
|
10
9
|
@value_type = type
|
11
10
|
@sub_type = sub_type
|
11
|
+
|
12
|
+
value = adjust_value_in value
|
13
|
+
|
14
|
+
ptr = AllocationHelper.safe_malloc(FFI.type_size @ffi_type)
|
15
|
+
ptr.send "put_#{@ffi_type}", 0, value
|
16
|
+
|
17
|
+
super ptr
|
12
18
|
end
|
13
19
|
|
14
20
|
private :initialize
|
@@ -20,30 +26,26 @@ module GirFFI
|
|
20
26
|
|
21
27
|
def to_sized_array_value size
|
22
28
|
# FIXME: Simulated Polymorphism.
|
23
|
-
raise "Not allowed" if @
|
29
|
+
raise "Not allowed" if @ffi_type != :pointer or @sub_type.nil?
|
24
30
|
block = self.read_pointer
|
25
31
|
return nil if block.null?
|
26
32
|
ArgHelper.ptr_to_typed_array @sub_type, block, size
|
27
33
|
end
|
28
34
|
|
29
35
|
def self.for type, sub_type=nil
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
self.new
|
36
|
+
if Array === type
|
37
|
+
return self.new nil, *type
|
38
|
+
end
|
39
|
+
self.new nil, type, sub_type
|
34
40
|
end
|
35
41
|
|
36
42
|
def self.from type, value, sub_type=nil
|
37
43
|
if Array === type
|
38
|
-
|
44
|
+
_, sub_t = *type
|
39
45
|
# TODO: Take array type into account (zero-terminated or not)
|
40
46
|
return self.from_array sub_t, value
|
41
47
|
end
|
42
|
-
value
|
43
|
-
ffi_type = TypeMap.map_basic_type_or_string type
|
44
|
-
ptr = AllocationHelper.safe_malloc(FFI.type_size ffi_type)
|
45
|
-
ptr.send "put_#{ffi_type}", 0, value
|
46
|
-
self.new ptr, type, ffi_type, sub_type
|
48
|
+
self.new value, type, sub_type
|
47
49
|
end
|
48
50
|
|
49
51
|
def self.from_array type, array
|
@@ -52,33 +54,24 @@ module GirFFI
|
|
52
54
|
self.from :pointer, ptr, type
|
53
55
|
end
|
54
56
|
|
55
|
-
|
56
|
-
self.for :pointer, type
|
57
|
-
end
|
57
|
+
private
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
case type
|
62
|
-
when :gboolean
|
63
|
-
(value ? 1 : 0)
|
64
|
-
when :utf8
|
65
|
-
InPointer.from :utf8, value
|
66
|
-
else
|
67
|
-
value
|
68
|
-
end
|
69
|
-
end
|
59
|
+
def adjust_value_in value
|
60
|
+
return nil_value if value.nil?
|
70
61
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
62
|
+
case @value_type
|
63
|
+
when :gboolean
|
64
|
+
(value ? 1 : 0)
|
65
|
+
when :utf8
|
66
|
+
InPointer.from :utf8, value
|
67
|
+
else
|
68
|
+
value
|
78
69
|
end
|
79
70
|
end
|
80
71
|
|
81
|
-
|
72
|
+
def nil_value
|
73
|
+
@ffi_type == :pointer ? nil : 0
|
74
|
+
end
|
82
75
|
|
83
76
|
def adjust_value_out value
|
84
77
|
case @value_type
|