gir_ffi 0.6.6 → 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +14 -0
- data/TODO.rdoc +23 -5
- data/lib/ffi-glib/array.rb +14 -15
- data/lib/ffi-glib/container_class_methods.rb +0 -1
- data/lib/ffi-glib/hash_table.rb +3 -4
- data/lib/ffi-glib/ptr_array.rb +12 -4
- data/lib/ffi-glib/sized_array.rb +27 -7
- data/lib/ffi-gobject.rb +14 -15
- data/lib/ffi-gobject/closure.rb +1 -1
- data/lib/ffi-gobject/object.rb +40 -15
- data/lib/ffi-gobject/ruby_closure.rb +0 -1
- data/lib/ffi-gobject/value.rb +45 -21
- data/lib/ffi-gobject_introspection/i_arg_info.rb +4 -0
- data/lib/ffi-gobject_introspection/i_base_info.rb +42 -2
- data/lib/ffi-gobject_introspection/i_callable_info.rb +8 -0
- data/lib/ffi-gobject_introspection/i_enum_info.rb +1 -4
- data/lib/ffi-gobject_introspection/i_interface_info.rb +1 -0
- data/lib/ffi-gobject_introspection/i_object_info.rb +2 -0
- data/lib/ffi-gobject_introspection/i_repository.rb +2 -3
- data/lib/ffi-gobject_introspection/i_struct_info.rb +3 -8
- data/lib/ffi-gobject_introspection/lib.rb +3 -0
- data/lib/gir_ffi-base.rb +3 -1
- data/lib/gir_ffi-base/gir_ffi/struct.rb +27 -0
- data/lib/gir_ffi-base/glib/boolean.rb +13 -1
- data/lib/gir_ffi-base/gobject.rb +7 -0
- data/lib/gir_ffi-base/gobject/lib.rb +0 -2
- data/lib/gir_ffi.rb +1 -3
- data/lib/gir_ffi/arg_helper.rb +4 -85
- data/lib/gir_ffi/builder.rb +5 -5
- data/lib/gir_ffi/builder_helper.rb +7 -0
- data/lib/gir_ffi/builders/argument_builder.rb +132 -0
- data/lib/gir_ffi/{base_argument_builder.rb → builders/base_argument_builder.rb} +32 -41
- data/lib/gir_ffi/builders/base_type_builder.rb +47 -0
- data/lib/gir_ffi/builders/callback_builder.rb +38 -0
- data/lib/gir_ffi/builders/constant_builder.rb +18 -0
- data/lib/gir_ffi/builders/enum_builder.rb +62 -0
- data/lib/gir_ffi/builders/error_argument_builder.rb +18 -0
- data/lib/gir_ffi/builders/field_builder.rb +94 -0
- data/lib/gir_ffi/builders/function_builder.rb +123 -0
- data/lib/gir_ffi/builders/interface_builder.rb +29 -0
- data/lib/gir_ffi/builders/mapping_method_builder.rb +88 -0
- data/lib/gir_ffi/builders/module_builder.rb +124 -0
- data/lib/gir_ffi/{null_argument_builder.rb → builders/null_argument_builder.rb} +0 -0
- data/lib/gir_ffi/builders/null_builder.rb +11 -0
- data/lib/gir_ffi/builders/object_builder.rb +123 -0
- data/lib/gir_ffi/{builder/property.rb → builders/property_builder.rb} +0 -0
- data/lib/gir_ffi/builders/registered_type_builder.rb +50 -0
- data/lib/gir_ffi/builders/return_value_builder.rb +68 -0
- data/lib/gir_ffi/builders/signal_builder.rb +91 -0
- data/lib/gir_ffi/builders/struct_builder.rb +35 -0
- data/lib/gir_ffi/builders/type_builder.rb +40 -0
- data/lib/gir_ffi/builders/unintrospectable_builder.rb +35 -0
- data/lib/gir_ffi/builders/union_builder.rb +34 -0
- data/lib/gir_ffi/builders/user_defined_builder.rb +103 -0
- data/lib/gir_ffi/builders/with_layout.rb +55 -0
- data/lib/gir_ffi/builders/with_methods.rb +44 -0
- data/lib/gir_ffi/callback_base.rb +31 -0
- data/lib/gir_ffi/class_base.rb +16 -10
- data/lib/gir_ffi/enum_base.rb +8 -4
- data/lib/gir_ffi/ffi_ext/pointer.rb +19 -2
- data/lib/gir_ffi/in_out_pointer.rb +38 -39
- data/lib/gir_ffi/in_pointer.rb +33 -18
- data/lib/gir_ffi/info_ext.rb +0 -4
- data/lib/gir_ffi/info_ext/i_arg_info.rb +0 -18
- data/lib/gir_ffi/info_ext/i_callable_info.rb +2 -1
- data/lib/gir_ffi/info_ext/i_registered_type_info.rb +6 -8
- data/lib/gir_ffi/info_ext/i_signal_info.rb +6 -21
- data/lib/gir_ffi/info_ext/i_type_info.rb +54 -29
- data/lib/gir_ffi/info_ext/safe_constant_name.rb +8 -1
- data/lib/gir_ffi/interface_base.rb +1 -1
- data/lib/gir_ffi/module_base.rb +5 -1
- data/lib/gir_ffi/object_base.rb +5 -1
- data/lib/gir_ffi/setter_argument_info.rb +4 -0
- data/lib/gir_ffi/signal_base.rb +21 -0
- data/lib/gir_ffi/struct_base.rb +24 -0
- data/lib/gir_ffi/type_base.rb +11 -0
- data/lib/gir_ffi/type_map.rb +4 -2
- data/lib/gir_ffi/union_base.rb +24 -0
- data/lib/gir_ffi/version.rb +1 -1
- data/tasks/test.rake +73 -7
- data/test/base_test_helper.rb +3 -19
- data/test/ffi-glib/array_test.rb +6 -0
- data/test/ffi-glib/ptr_array_test.rb +13 -0
- data/test/ffi-glib/ruby_closure_test.rb +7 -7
- data/test/ffi-glib/sized_array_test.rb +2 -2
- data/test/ffi-gobject/gobject_test.rb +3 -12
- data/test/ffi-gobject/object_test.rb +33 -2
- data/test/ffi-gobject/value_test.rb +114 -1
- data/test/ffi-gobject_introspection/i_enum_info_test.rb +2 -2
- data/test/ffi-gobject_introspection/i_object_info_test.rb +3 -3
- data/test/ffi-gobject_introspection/i_repository_test.rb +26 -21
- data/test/ffi-gobject_test.rb +14 -14
- data/test/gir_ffi-base/glib/boolean_test.rb +6 -0
- data/test/gir_ffi/arg_helper_test.rb +2 -122
- data/test/gir_ffi/builder_test.rb +67 -204
- data/test/gir_ffi/{argument_builder_test.rb → builders/argument_builder_test.rb} +230 -108
- data/test/gir_ffi/builders/base_argument_builder_test.rb +5 -0
- data/test/gir_ffi/builders/callback_builder_test.rb +50 -0
- data/test/gir_ffi/builders/constant_builder_test.rb +4 -0
- data/test/gir_ffi/{builder/type/enum_test.rb → builders/enum_builder_test.rb} +2 -3
- data/test/gir_ffi/builders/field_builder_test.rb +94 -0
- data/test/gir_ffi/{function_builder_test.rb → builders/function_builder_test.rb} +43 -24
- data/test/gir_ffi/{builder/type/interface_test.rb → builders/interface_builder_test.rb} +2 -2
- data/test/gir_ffi/{builder/module_test.rb → builders/module_builder_test.rb} +12 -13
- data/test/gir_ffi/{builder/type/object_test.rb → builders/object_builder_test.rb} +9 -9
- data/test/gir_ffi/{return_value_builder_test.rb → builders/return_value_builder_test.rb} +94 -58
- data/test/gir_ffi/builders/signal_builder_test.rb +62 -0
- data/test/gir_ffi/{builder/type/struct_test.rb → builders/struct_builder_test.rb} +36 -19
- data/test/gir_ffi/{builder/type/unintrospectable_test.rb → builders/unintrospectable_builder_test.rb} +3 -3
- data/test/gir_ffi/builders/union_builder_test.rb +29 -0
- data/test/gir_ffi/{builder/type/user_defined_test.rb → builders/user_defined_builder_test.rb} +2 -2
- data/test/gir_ffi/callback_base_test.rb +11 -0
- data/test/gir_ffi/class_base_test.rb +22 -22
- data/test/gir_ffi/ffi_ext/pointer_test.rb +18 -0
- data/test/gir_ffi/in_out_pointer_test.rb +0 -7
- data/test/gir_ffi/in_pointer_test.rb +27 -3
- data/test/gir_ffi/info_ext/i_signal_info_test.rb +16 -44
- data/test/gir_ffi/info_ext/i_type_info_test.rb +315 -74
- data/test/gir_ffi/info_ext/safe_constant_name_test.rb +6 -0
- data/test/gir_ffi/interface_base_test.rb +3 -5
- data/test/gir_ffi/object_base_test.rb +10 -6
- data/test/gir_ffi/type_map_test.rb +2 -2
- data/test/gir_ffi/unintrospectable_type_info_test.rb +2 -2
- data/test/gir_ffi_test_helper.rb +12 -4
- data/test/integration/generated_gimarshallingtests_test.rb +436 -76
- data/test/integration/generated_gio_test.rb +5 -11
- data/test/integration/generated_gobject_test.rb +8 -0
- data/test/integration/generated_regress_test.rb +755 -309
- data/test/integration/generated_secret_test.rb +2 -1
- metadata +73 -72
- data/lib/ffi-gobject/ruby_style.rb +0 -23
- data/lib/gir_ffi/argument_builder.rb +0 -154
- data/lib/gir_ffi/builder/field.rb +0 -60
- data/lib/gir_ffi/builder/module.rb +0 -127
- data/lib/gir_ffi/builder/type.rb +0 -39
- data/lib/gir_ffi/builder/type/base.rb +0 -48
- data/lib/gir_ffi/builder/type/callback.rb +0 -30
- data/lib/gir_ffi/builder/type/constant.rb +0 -22
- data/lib/gir_ffi/builder/type/enum.rb +0 -66
- data/lib/gir_ffi/builder/type/interface.rb +0 -33
- data/lib/gir_ffi/builder/type/object.rb +0 -134
- data/lib/gir_ffi/builder/type/registered_type.rb +0 -62
- data/lib/gir_ffi/builder/type/struct.rb +0 -34
- data/lib/gir_ffi/builder/type/unintrospectable.rb +0 -39
- data/lib/gir_ffi/builder/type/union.rb +0 -34
- data/lib/gir_ffi/builder/type/user_defined.rb +0 -107
- data/lib/gir_ffi/builder/type/with_layout.rb +0 -62
- data/lib/gir_ffi/builder/type/with_methods.rb +0 -64
- data/lib/gir_ffi/callback.rb +0 -72
- data/lib/gir_ffi/callback_helper.rb +0 -11
- data/lib/gir_ffi/error_argument_builder.rb +0 -17
- data/lib/gir_ffi/function_builder.rb +0 -112
- data/lib/gir_ffi/info_ext/i_enum_info.rb +0 -11
- data/lib/gir_ffi/info_ext/i_object_info.rb +0 -11
- data/lib/gir_ffi/info_ext/i_struct_info.rb +0 -11
- data/lib/gir_ffi/info_ext/i_union_info.rb +0 -12
- data/lib/gir_ffi/return_value_builder.rb +0 -81
- data/test/ffi-gobject/ruby_style_test.rb +0 -38
- data/test/gir_ffi/base_argument_builder_test.rb +0 -13
- data/test/gir_ffi/builder/type/callback_test.rb +0 -6
- data/test/gir_ffi/builder/type/constant_test.rb +0 -4
- data/test/gir_ffi/builder/type/union_test.rb +0 -12
- data/test/gir_ffi/callback_helper_test.rb +0 -10
- data/test/gir_ffi/callback_test.rb +0 -49
- data/test/gir_ffi/info_ext/i_arg_info_test.rb +0 -39
- data/test/gir_ffi/info_ext/i_object_info_test.rb +0 -14
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'gir_ffi/builder/type/base'
|
2
|
-
require 'gir_ffi/class_base'
|
3
|
-
|
4
|
-
module GirFFI
|
5
|
-
module Builder
|
6
|
-
module Type
|
7
|
-
|
8
|
-
# Base class for type builders building types specified by subtypes
|
9
|
-
# of IRegisteredTypeInfo. These are types whose C representation is
|
10
|
-
# complex, i.e., a struct or a union.
|
11
|
-
class RegisteredType < Base
|
12
|
-
private
|
13
|
-
|
14
|
-
def setup_constants
|
15
|
-
@klass.const_set :GIR_INFO, info
|
16
|
-
@klass.const_set :GIR_FFI_BUILDER, self
|
17
|
-
end
|
18
|
-
|
19
|
-
def already_set_up
|
20
|
-
const_defined_for @klass, :GIR_FFI_BUILDER
|
21
|
-
end
|
22
|
-
|
23
|
-
def target_gtype
|
24
|
-
info.g_type
|
25
|
-
end
|
26
|
-
|
27
|
-
# TODO: Rename the created method, or use a constant.
|
28
|
-
# FIXME: Only used in some of the subclases. Make mixin?
|
29
|
-
def setup_gtype_getter
|
30
|
-
gtype = target_gtype
|
31
|
-
return if gtype.nil?
|
32
|
-
@klass.instance_eval "
|
33
|
-
def self.get_gtype
|
34
|
-
#{gtype}
|
35
|
-
end
|
36
|
-
"
|
37
|
-
end
|
38
|
-
|
39
|
-
# FIXME: Only used in some of the subclases. Make mixin?
|
40
|
-
def provide_constructor
|
41
|
-
return if info.find_method 'new'
|
42
|
-
|
43
|
-
(class << @klass; self; end).class_eval {
|
44
|
-
alias_method :new, :_allocate
|
45
|
-
}
|
46
|
-
end
|
47
|
-
|
48
|
-
def parent
|
49
|
-
nil
|
50
|
-
end
|
51
|
-
|
52
|
-
def fields
|
53
|
-
info.fields
|
54
|
-
end
|
55
|
-
|
56
|
-
def superclass
|
57
|
-
@superclass ||= ClassBase
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'gir_ffi/builder/type/registered_type'
|
2
|
-
require 'gir_ffi/builder/type/with_layout'
|
3
|
-
require 'gir_ffi/builder/type/with_methods'
|
4
|
-
|
5
|
-
module GirFFI
|
6
|
-
module Builder
|
7
|
-
module Type
|
8
|
-
|
9
|
-
# Implements the creation of a class representing a Struct.
|
10
|
-
class Struct < RegisteredType
|
11
|
-
include WithMethods
|
12
|
-
include WithLayout
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def setup_class
|
17
|
-
setup_layout
|
18
|
-
setup_constants
|
19
|
-
stub_methods
|
20
|
-
setup_gtype_getter
|
21
|
-
setup_field_accessors
|
22
|
-
provide_constructor
|
23
|
-
end
|
24
|
-
|
25
|
-
# FIXME: Private method only in subclass
|
26
|
-
def layout_superclass
|
27
|
-
FFI::Struct
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'gir_ffi/builder/type/object'
|
2
|
-
|
3
|
-
module GirFFI
|
4
|
-
module Builder
|
5
|
-
module Type
|
6
|
-
|
7
|
-
# Implements the creation of a class representing an object type for
|
8
|
-
# which no data is found in the GIR. Typically, these are created to
|
9
|
-
# cast objects returned by a function that returns an interface.
|
10
|
-
class Unintrospectable < Object
|
11
|
-
def instantiate_class
|
12
|
-
gtype = target_gtype
|
13
|
-
CACHE[gtype] ||= Class.new(superclass)
|
14
|
-
@klass = CACHE[gtype]
|
15
|
-
@structklass = get_or_define_class @klass, :Struct, layout_superclass
|
16
|
-
setup_class unless already_set_up
|
17
|
-
end
|
18
|
-
|
19
|
-
def setup_class
|
20
|
-
setup_constants
|
21
|
-
setup_layout
|
22
|
-
setup_interfaces
|
23
|
-
setup_gtype_getter
|
24
|
-
end
|
25
|
-
|
26
|
-
def setup_instance_method method
|
27
|
-
false
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def signal_definers
|
33
|
-
info.interfaces
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'gir_ffi/builder/type/registered_type'
|
2
|
-
require 'gir_ffi/builder/type/with_layout'
|
3
|
-
require 'gir_ffi/builder/type/with_methods'
|
4
|
-
|
5
|
-
module GirFFI
|
6
|
-
module Builder
|
7
|
-
module Type
|
8
|
-
|
9
|
-
# Implements the creation of a class representing union type. The
|
10
|
-
# class will have a nested FFI::Union class to represent its C union.
|
11
|
-
class Union < RegisteredType
|
12
|
-
include WithMethods
|
13
|
-
include WithLayout
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def setup_class
|
18
|
-
setup_layout
|
19
|
-
setup_constants
|
20
|
-
stub_methods
|
21
|
-
setup_gtype_getter
|
22
|
-
setup_field_accessors
|
23
|
-
provide_constructor
|
24
|
-
end
|
25
|
-
|
26
|
-
def layout_superclass
|
27
|
-
FFI::Union
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
|
@@ -1,107 +0,0 @@
|
|
1
|
-
require 'gir_ffi/builder/type/object'
|
2
|
-
|
3
|
-
module GirFFI
|
4
|
-
module Builder
|
5
|
-
module Type
|
6
|
-
|
7
|
-
# Implements the creation of GObject subclasses from Ruby.
|
8
|
-
class UserDefined < Object
|
9
|
-
def initialize info
|
10
|
-
@info = info
|
11
|
-
end
|
12
|
-
|
13
|
-
def instantiate_class
|
14
|
-
@klass = @info.described_class
|
15
|
-
|
16
|
-
parent_type = @klass.get_gtype
|
17
|
-
@parent = gir.find_by_gtype(parent_type)
|
18
|
-
|
19
|
-
query_result = GObject.type_query parent_type
|
20
|
-
type_info = GObject::TypeInfo.new
|
21
|
-
type_info.class_size = query_result.class_size
|
22
|
-
type_info.instance_size = query_result.instance_size
|
23
|
-
properties.each do
|
24
|
-
type_info.instance_size += FFI.type_size(:int32)
|
25
|
-
end
|
26
|
-
|
27
|
-
@gtype = GObject.type_register_static(parent_type, @klass.name,
|
28
|
-
type_info, 0)
|
29
|
-
|
30
|
-
@structklass = get_or_define_class @klass, :Struct, layout_superclass
|
31
|
-
setup_class unless already_set_up
|
32
|
-
CACHE[@gtype] = @klass
|
33
|
-
end
|
34
|
-
|
35
|
-
def setup_class
|
36
|
-
setup_layout
|
37
|
-
setup_constants
|
38
|
-
#stub_methods
|
39
|
-
setup_gtype_getter
|
40
|
-
setup_property_accessors
|
41
|
-
#setup_vfunc_invokers
|
42
|
-
#setup_interfaces
|
43
|
-
setup_constructor
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
def target_gtype
|
49
|
-
@gtype
|
50
|
-
end
|
51
|
-
|
52
|
-
def parent
|
53
|
-
@parent
|
54
|
-
end
|
55
|
-
|
56
|
-
def properties
|
57
|
-
info.properties
|
58
|
-
end
|
59
|
-
|
60
|
-
def layout_specification
|
61
|
-
parent_spec = [:parent, superclass::Struct, 0]
|
62
|
-
offset = superclass::Struct.size
|
63
|
-
fields_spec = properties.map do |pinfo|
|
64
|
-
spec = [pinfo.name.to_sym, :int32, offset]
|
65
|
-
offset += FFI.type_size(:int32)
|
66
|
-
spec
|
67
|
-
end.flatten(1)
|
68
|
-
parent_spec + fields_spec
|
69
|
-
end
|
70
|
-
|
71
|
-
def setup_property_accessors
|
72
|
-
properties.each do |pinfo|
|
73
|
-
setup_accessors_for_param_info pinfo
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def setup_accessors_for_param_info pinfo
|
78
|
-
code = <<-CODE
|
79
|
-
def #{pinfo.name}
|
80
|
-
@struct[:#{pinfo.name}]
|
81
|
-
end
|
82
|
-
def #{pinfo.name}= val
|
83
|
-
@struct[:#{pinfo.name}] = val
|
84
|
-
end
|
85
|
-
CODE
|
86
|
-
|
87
|
-
@klass.class_eval code
|
88
|
-
end
|
89
|
-
|
90
|
-
def method_introspection_data method
|
91
|
-
nil
|
92
|
-
end
|
93
|
-
|
94
|
-
def setup_constructor
|
95
|
-
code = <<-CODE
|
96
|
-
def self.new
|
97
|
-
gptr = GObject::Lib.g_object_newv #{@gtype}, 0, nil
|
98
|
-
self.wrap(gptr)
|
99
|
-
end
|
100
|
-
CODE
|
101
|
-
@klass.class_eval code
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'gir_ffi/builder/field'
|
2
|
-
|
3
|
-
module GirFFI
|
4
|
-
module Builder
|
5
|
-
module Type
|
6
|
-
|
7
|
-
# Implements the creation of classes representing types with layout,
|
8
|
-
# i.e., :union, :struct, :object.
|
9
|
-
# Note: This module depends on the additional inclusion of
|
10
|
-
# WithMethods.
|
11
|
-
module WithLayout
|
12
|
-
private
|
13
|
-
|
14
|
-
def setup_layout
|
15
|
-
spec = layout_specification
|
16
|
-
@structklass.class_eval { layout(*spec) }
|
17
|
-
end
|
18
|
-
|
19
|
-
def dummy_layout_specification
|
20
|
-
if parent
|
21
|
-
[:parent, superclass.const_get(:Struct), 0]
|
22
|
-
else
|
23
|
-
[:dummy, :char, 0]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def base_layout_specification
|
28
|
-
fields.map { |finfo| finfo.layout_specification }.flatten(1)
|
29
|
-
end
|
30
|
-
|
31
|
-
def layout_specification
|
32
|
-
spec = base_layout_specification
|
33
|
-
if spec.empty?
|
34
|
-
dummy_layout_specification
|
35
|
-
else
|
36
|
-
spec
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def setup_accessors_for_field_info finfo
|
41
|
-
builder = Builder::Field.new(finfo, lib, @structklass)
|
42
|
-
unless has_instance_method finfo.name
|
43
|
-
@klass.class_eval builder.getter_def
|
44
|
-
end
|
45
|
-
@klass.class_eval builder.setter_def if finfo.writable?
|
46
|
-
end
|
47
|
-
|
48
|
-
def setup_field_accessors
|
49
|
-
fields.each do |finfo|
|
50
|
-
setup_accessors_for_field_info finfo
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def instantiate_class
|
55
|
-
@klass = get_or_define_class namespace_module, @classname, superclass
|
56
|
-
@structklass = get_or_define_class @klass, :Struct, layout_superclass
|
57
|
-
setup_class unless already_set_up
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'gir_ffi/method_stubber'
|
2
|
-
|
3
|
-
module GirFFI
|
4
|
-
module Builder
|
5
|
-
module Type
|
6
|
-
|
7
|
-
# Implements method creation for types such as, :union, :struct,
|
8
|
-
# :object, :interface.
|
9
|
-
module WithMethods
|
10
|
-
def setup_method method
|
11
|
-
go = method_introspection_data method
|
12
|
-
attach_and_define_method method, go, meta_class
|
13
|
-
end
|
14
|
-
|
15
|
-
def setup_instance_method method
|
16
|
-
go = instance_method_introspection_data method
|
17
|
-
attach_and_define_method method, go, build_class
|
18
|
-
end
|
19
|
-
|
20
|
-
def has_instance_method method
|
21
|
-
!!instance_method_introspection_data(method)
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def meta_class
|
27
|
-
klass = build_class
|
28
|
-
return (class << klass; self; end)
|
29
|
-
end
|
30
|
-
|
31
|
-
def method_introspection_data method
|
32
|
-
info.find_method method
|
33
|
-
end
|
34
|
-
|
35
|
-
def instance_method_introspection_data method
|
36
|
-
data = method_introspection_data method
|
37
|
-
return data if data && data.method?
|
38
|
-
end
|
39
|
-
|
40
|
-
def function_definition_builder go
|
41
|
-
FunctionBuilder.new(go, lib)
|
42
|
-
end
|
43
|
-
|
44
|
-
def function_definition go
|
45
|
-
function_definition_builder(go).generate
|
46
|
-
end
|
47
|
-
|
48
|
-
def attach_and_define_method method, go, modul
|
49
|
-
return false if go.nil?
|
50
|
-
Builder.attach_ffi_function lib, go
|
51
|
-
modul.class_eval { remove_method method }
|
52
|
-
build_class.class_eval function_definition(go)
|
53
|
-
true
|
54
|
-
end
|
55
|
-
|
56
|
-
def stub_methods
|
57
|
-
info.get_methods.each do |minfo|
|
58
|
-
@klass.class_eval MethodStubber.new(minfo).method_stub
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
data/lib/gir_ffi/callback.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
module GirFFI
|
2
|
-
# Specialized kind of Proc to be used for callback arguments.
|
3
|
-
# TODO: Create superclass for all actual callback types that does the wrapping for this.
|
4
|
-
class Callback < Proc
|
5
|
-
# Create Callback from a Proc. Makes sure arguments are properly wrapped,
|
6
|
-
# and the callback is stored to prevent garbage collection.
|
7
|
-
def self.from namespace, name, prc
|
8
|
-
wrap_in_callback_args_mapper(namespace, name, prc).tap do |cb|
|
9
|
-
CallbackHelper.store_callback cb
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
# TODO: Create actual callback class from the callback info, so no lookup
|
14
|
-
# is needed. This class can then also perform the argument mapping.
|
15
|
-
def self.wrap_in_callback_args_mapper namespace, name, prc
|
16
|
-
return prc if FFI::Function === prc
|
17
|
-
return nil if prc.nil?
|
18
|
-
info = GObjectIntrospection::IRepository.default.find_by_name namespace, name
|
19
|
-
return self.new do |*args|
|
20
|
-
prc.call(*map_callback_args(args, info))
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.map_callback_args args, info
|
25
|
-
args.zip(info.args).map { |arg, inf|
|
26
|
-
map_single_callback_arg arg, inf.argument_type }
|
27
|
-
end
|
28
|
-
|
29
|
-
# TODO: Use GirFFI::ReturnValue classes for mapping.
|
30
|
-
def self.map_single_callback_arg arg, type
|
31
|
-
case type.tag
|
32
|
-
when :interface
|
33
|
-
map_interface_callback_arg arg, type
|
34
|
-
when :utf8
|
35
|
-
ArgHelper.ptr_to_utf8 arg
|
36
|
-
when :void
|
37
|
-
map_void_callback_arg arg
|
38
|
-
when :array
|
39
|
-
subtype = type.param_type(0)
|
40
|
-
if subtype.tag == :interface and arg.is_a?(FFI::Pointer)
|
41
|
-
map_interface_callback_arg arg, subtype
|
42
|
-
else
|
43
|
-
raise NotImplementedError
|
44
|
-
end
|
45
|
-
else
|
46
|
-
arg
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.map_interface_callback_arg arg, type
|
51
|
-
iface = type.interface
|
52
|
-
case iface.info_type
|
53
|
-
when :object, :interface
|
54
|
-
arg.to_object
|
55
|
-
when :struct
|
56
|
-
klass = GirFFI::Builder.build_class iface
|
57
|
-
klass.wrap arg
|
58
|
-
else
|
59
|
-
arg
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.map_void_callback_arg arg
|
64
|
-
if arg.null?
|
65
|
-
nil
|
66
|
-
else
|
67
|
-
GirFFI::ArgHelper::OBJECT_STORE[arg.address]
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
end
|