gir_ffi 0.7.4 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +7 -0
- data/TODO.md +8 -0
- data/lib/ffi-glib/array.rb +7 -7
- data/lib/ffi-glib/byte_array.rb +3 -4
- data/lib/ffi-glib/bytes.rb +3 -3
- data/lib/ffi-glib/error.rb +2 -2
- data/lib/ffi-glib/hash_table.rb +7 -7
- data/lib/ffi-glib/iconv.rb +3 -4
- data/lib/ffi-glib/list.rb +3 -3
- data/lib/ffi-glib/list_methods.rb +3 -3
- data/lib/ffi-glib/ptr_array.rb +6 -6
- data/lib/ffi-glib/s_list.rb +3 -3
- data/lib/ffi-glib/strv.rb +3 -3
- data/lib/ffi-glib/variant.rb +6 -2
- data/lib/ffi-glib.rb +3 -0
- data/lib/ffi-gobject/base.rb +1 -0
- data/lib/ffi-gobject/closure.rb +2 -2
- data/lib/ffi-gobject/initially_unowned.rb +4 -3
- data/lib/ffi-gobject/object.rb +5 -5
- data/lib/ffi-gobject/object_class.rb +2 -2
- data/lib/ffi-gobject/ruby_closure.rb +2 -3
- data/lib/ffi-gobject/value.rb +5 -5
- data/lib/ffi-gobject.rb +17 -22
- data/lib/ffi-gobject_introspection/i_arg_info.rb +0 -1
- data/lib/ffi-gobject_introspection/i_base_info.rb +3 -4
- data/lib/ffi-gobject_introspection/i_callable_info.rb +1 -2
- data/lib/ffi-gobject_introspection/i_constant_info.rb +19 -11
- data/lib/ffi-gobject_introspection/i_enum_info.rb +4 -3
- data/lib/ffi-gobject_introspection/i_function_info.rb +7 -1
- data/lib/ffi-gobject_introspection/i_interface_info.rb +12 -0
- data/lib/ffi-gobject_introspection/i_object_info.rb +19 -8
- data/lib/ffi-gobject_introspection/i_registered_type_info.rb +0 -1
- data/lib/ffi-gobject_introspection/i_repository.rb +10 -15
- data/lib/ffi-gobject_introspection/i_struct_info.rb +4 -2
- data/lib/ffi-gobject_introspection/i_type_info.rb +4 -2
- data/lib/ffi-gobject_introspection/i_union_info.rb +7 -3
- data/lib/ffi-gobject_introspection/i_value_info.rb +0 -1
- data/lib/ffi-gobject_introspection/lib.rb +1 -2
- data/lib/ffi-gobject_introspection.rb +0 -1
- data/lib/gir_ffi/allocation_helper.rb +2 -1
- data/lib/gir_ffi/arg_helper.rb +6 -2
- data/lib/gir_ffi/builder_helper.rb +1 -0
- data/lib/gir_ffi/builders/argument_builder_collection.rb +67 -0
- data/lib/gir_ffi/builders/c_to_ruby_convertor.rb +2 -0
- data/lib/gir_ffi/builders/callback_argument_builder.rb +7 -5
- data/lib/gir_ffi/builders/callback_builder.rb +3 -1
- data/lib/gir_ffi/builders/callback_return_value_builder.rb +2 -0
- data/lib/gir_ffi/builders/closure_argument_builder.rb +13 -0
- data/lib/gir_ffi/builders/closure_convertor.rb +2 -0
- data/lib/gir_ffi/builders/closure_to_pointer_convertor.rb +2 -0
- data/lib/gir_ffi/builders/constructor_result_convertor.rb +1 -0
- data/lib/gir_ffi/builders/enum_builder.rb +1 -4
- data/lib/gir_ffi/builders/field_builder.rb +2 -2
- data/lib/gir_ffi/builders/function_builder.rb +2 -1
- data/lib/gir_ffi/builders/interface_builder.rb +0 -3
- data/lib/gir_ffi/builders/mapping_method_builder.rb +24 -92
- data/lib/gir_ffi/builders/marshalling_method_builder.rb +73 -0
- data/lib/gir_ffi/builders/null_argument_builder.rb +3 -0
- data/lib/gir_ffi/builders/null_builder.rb +1 -0
- data/lib/gir_ffi/builders/object_builder.rb +0 -2
- data/lib/gir_ffi/builders/property_builder.rb +4 -4
- data/lib/gir_ffi/builders/registered_type_builder.rb +35 -1
- data/lib/gir_ffi/builders/return_value_builder.rb +4 -6
- data/lib/gir_ffi/builders/ruby_to_c_convertor.rb +2 -0
- data/lib/gir_ffi/builders/signal_closure_builder.rb +46 -0
- data/lib/gir_ffi/builders/struct_builder.rb +0 -2
- data/lib/gir_ffi/builders/type_builder.rb +1 -1
- data/lib/gir_ffi/builders/unintrospectable_builder.rb +1 -1
- data/lib/gir_ffi/builders/union_builder.rb +0 -2
- data/lib/gir_ffi/builders/user_defined_builder.rb +6 -18
- data/lib/gir_ffi/builders/vfunc_builder.rb +6 -4
- data/lib/gir_ffi/builders/with_layout.rb +1 -2
- data/lib/gir_ffi/callback_base.rb +4 -4
- data/lib/gir_ffi/class_base.rb +28 -18
- data/lib/gir_ffi/enum_base.rb +2 -2
- data/lib/gir_ffi/ffi_ext/pointer.rb +1 -0
- data/lib/gir_ffi/in_out_pointer.rb +4 -4
- data/lib/gir_ffi/in_pointer.rb +2 -2
- data/lib/gir_ffi/info_ext/full_type_name.rb +16 -0
- data/lib/gir_ffi/info_ext/i_arg_info.rb +2 -3
- data/lib/gir_ffi/info_ext/i_callback_info.rb +1 -8
- data/lib/gir_ffi/info_ext/i_property_info.rb +0 -1
- data/lib/gir_ffi/info_ext/i_registered_type_info.rb +0 -1
- data/lib/gir_ffi/info_ext/i_signal_info.rb +8 -40
- data/lib/gir_ffi/info_ext/i_type_info.rb +12 -2
- data/lib/gir_ffi/info_ext/i_vfunc_info.rb +1 -6
- data/lib/gir_ffi/info_ext/safe_constant_name.rb +0 -5
- data/lib/gir_ffi/info_ext.rb +1 -0
- data/lib/gir_ffi/lib_c.rb +1 -0
- data/lib/gir_ffi/module_base.rb +2 -2
- data/lib/gir_ffi/object_base.rb +0 -16
- data/lib/gir_ffi/receiver_argument_info.rb +0 -4
- data/lib/gir_ffi/registered_type_base.rb +0 -1
- data/lib/gir_ffi/sized_array.rb +5 -5
- data/lib/gir_ffi/struct_base.rb +4 -0
- data/lib/gir_ffi/type_base.rb +2 -2
- data/lib/gir_ffi/type_map.rb +1 -0
- data/lib/gir_ffi/unintrospectable_type_info.rb +1 -3
- data/lib/gir_ffi/user_data_type_info.rb +2 -0
- data/lib/gir_ffi/version.rb +2 -1
- data/lib/gir_ffi/zero_terminated.rb +6 -6
- data/lib/gir_ffi-base/glib/boolean.rb +2 -2
- data/lib/gir_ffi-base/glib/strv.rb +1 -1
- data/lib/gir_ffi-base/gobject/lib.rb +1 -0
- data/lib/gir_ffi-base/gobject.rb +1 -1
- data/lib/gir_ffi.rb +2 -0
- data/test/ffi-glib/hash_table_test.rb +1 -1
- data/test/ffi-glib/strv_test.rb +27 -0
- data/test/ffi-gobject_introspection/i_constant_info_test.rb +1 -5
- data/test/ffi-gobject_test.rb +3 -3
- data/test/gir_ffi/builders/{with_methods_test.rb → registered_type_builder_test.rb} +1 -1
- data/test/gir_ffi/builders/signal_closure_builder_test.rb +136 -0
- data/test/gir_ffi/builders/user_defined_builder_test.rb +2 -1
- data/test/gir_ffi/info_ext/i_signal_info_test.rb +0 -11
- data/test/integration/generated_gimarshallingtests_test.rb +47 -2
- data/test/integration/generated_regress_test.rb +19 -11
- metadata +82 -25
- data/lib/gir_ffi/builders/signal_builder.rb +0 -51
- data/lib/gir_ffi/builders/with_methods.rb +0 -45
- data/lib/gir_ffi/signal_base.rb +0 -21
- data/lib/gir_ffi/vfunc_base.rb +0 -9
- data/test/gir_ffi/builders/signal_builder_test.rb +0 -106
data/lib/gir_ffi/class_base.rb
CHANGED
@@ -3,12 +3,13 @@ require 'gir_ffi/builders/null_builder'
|
|
3
3
|
require 'gir_ffi/registered_type_base'
|
4
4
|
|
5
5
|
module GirFFI
|
6
|
-
# Base class for all generated classes. Contains code for dealing
|
7
|
-
# the generated Struct classes.
|
6
|
+
# Base class for all generated classes and structs. Contains code for dealing
|
7
|
+
# with the generated nested Struct classes.
|
8
8
|
class ClassBase
|
9
9
|
extend RegisteredTypeBase
|
10
10
|
extend Forwardable
|
11
11
|
|
12
|
+
attr_reader :struct
|
12
13
|
def_delegators :@struct, :to_ptr
|
13
14
|
|
14
15
|
GIR_FFI_BUILDER = NullBuilder.new
|
@@ -20,39 +21,32 @@ module GirFFI
|
|
20
21
|
raise RuntimeError, "Unable to set up instance method '#{method}' in #{self}"
|
21
22
|
end
|
22
23
|
|
23
|
-
|
24
|
+
send method_name, *arguments, &block
|
24
25
|
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
other.class == self.class && self.to_ptr.address == other.to_ptr.address
|
31
|
-
end
|
32
|
-
else
|
33
|
-
def ==(other)
|
34
|
-
other.class == self.class && self.to_ptr == other.to_ptr
|
35
|
-
end
|
27
|
+
# NOTE: JRuby should fix FFI::MemoryPointer#== to return true for
|
28
|
+
# equivalent FFI::Pointer. For now, user to_ptr.address
|
29
|
+
def == other
|
30
|
+
other.class == self.class && to_ptr.address == other.to_ptr.address
|
36
31
|
end
|
37
32
|
|
38
33
|
def self.setup_and_call method, *arguments, &block
|
39
|
-
method_name =
|
34
|
+
method_name = try_in_ancestors(:setup_method, method.to_s)
|
40
35
|
|
41
36
|
unless method_name
|
42
37
|
raise RuntimeError, "Unable to set up method '#{method}' in #{self}"
|
43
38
|
end
|
44
39
|
|
45
|
-
|
40
|
+
send method_name, *arguments, &block
|
46
41
|
end
|
47
42
|
|
48
|
-
def self.try_in_ancestors
|
49
|
-
|
43
|
+
def self.try_in_ancestors method, *arguments
|
44
|
+
ancestors.each do |klass|
|
50
45
|
if klass.respond_to?(method)
|
51
46
|
result = klass.send(method, *arguments)
|
52
47
|
return result if result
|
53
48
|
end
|
54
49
|
end
|
55
|
-
return
|
56
50
|
end
|
57
51
|
|
58
52
|
class << self
|
@@ -99,5 +93,21 @@ module GirFFI
|
|
99
93
|
val
|
100
94
|
end
|
101
95
|
end
|
96
|
+
|
97
|
+
#
|
98
|
+
# Wraps a pointer retrieved from a constructor method. Here, it is simply
|
99
|
+
# defined as a wrapper around direct_wrap, but, e.g., InitiallyUnowned
|
100
|
+
# overrides it to sink the floating object.
|
101
|
+
#
|
102
|
+
# This method assumes the pointer will always be of the type corresponding
|
103
|
+
# to the current class, and never of a subtype.
|
104
|
+
#
|
105
|
+
# @param ptr Pointer to the object's C structure
|
106
|
+
#
|
107
|
+
# @return An object of the current class wrapping the pointer
|
108
|
+
#
|
109
|
+
def self.constructor_wrap ptr
|
110
|
+
direct_wrap ptr
|
111
|
+
end
|
102
112
|
end
|
103
113
|
end
|
data/lib/gir_ffi/enum_base.rb
CHANGED
@@ -18,7 +18,7 @@ module GirFFI
|
|
18
18
|
self::Enum.from_native(*args)
|
19
19
|
end
|
20
20
|
|
21
|
-
def []
|
21
|
+
def [] arg
|
22
22
|
self::Enum[arg]
|
23
23
|
end
|
24
24
|
|
@@ -45,7 +45,7 @@ module GirFFI
|
|
45
45
|
raise RuntimeError, "Unable to set up method #{method} in #{self}"
|
46
46
|
end
|
47
47
|
|
48
|
-
|
48
|
+
send method, *arguments, &block
|
49
49
|
end
|
50
50
|
|
51
51
|
def to_ffitype
|
@@ -21,7 +21,7 @@ module GirFFI
|
|
21
21
|
when Module
|
22
22
|
value_ffi_type.get_value_from_pointer(self)
|
23
23
|
when Symbol
|
24
|
-
|
24
|
+
send("get_#{value_ffi_type}", 0)
|
25
25
|
else
|
26
26
|
raise NotImplementedError
|
27
27
|
end
|
@@ -47,7 +47,7 @@ module GirFFI
|
|
47
47
|
when Module
|
48
48
|
value_ffi_type.copy_value_to_pointer(value, self)
|
49
49
|
when Symbol
|
50
|
-
|
50
|
+
send "put_#{value_ffi_type}", 0, value
|
51
51
|
else
|
52
52
|
raise NotImplementedError, value_ffi_type
|
53
53
|
end
|
@@ -58,11 +58,11 @@ module GirFFI
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def self.for type
|
61
|
-
|
61
|
+
new(type).tap {|ptr| ptr.clear}
|
62
62
|
end
|
63
63
|
|
64
64
|
def self.from type, value
|
65
|
-
|
65
|
+
new(type).tap {|ptr| ptr.set_value value}
|
66
66
|
end
|
67
67
|
|
68
68
|
private
|
data/lib/gir_ffi/in_pointer.rb
CHANGED
@@ -35,11 +35,11 @@ module GirFFI
|
|
35
35
|
when :utf8, :filename
|
36
36
|
from_utf8 val
|
37
37
|
when :gint32, :guint32, :gint8
|
38
|
-
|
38
|
+
new val
|
39
39
|
when Class, :void
|
40
40
|
val.to_ptr
|
41
41
|
when Module
|
42
|
-
|
42
|
+
new type[val]
|
43
43
|
else
|
44
44
|
raise NotImplementedError, type
|
45
45
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module GirFFI
|
2
|
+
module InfoExt
|
3
|
+
# Extension module provinding a #full_type_name method suitable for
|
4
|
+
# callbacks, constants and registered types. Signals and vfuncs need a
|
5
|
+
# different implementation.
|
6
|
+
module FullTypeName
|
7
|
+
def full_type_name
|
8
|
+
"#{safe_namespace}::#{safe_name}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
GObjectIntrospection::ICallbackInfo.send :include, GirFFI::InfoExt::FullTypeName
|
15
|
+
GObjectIntrospection::IConstantInfo.send :include, GirFFI::InfoExt::FullTypeName
|
16
|
+
GObjectIntrospection::IRegisteredTypeInfo.send :include, GirFFI::InfoExt::FullTypeName
|
@@ -4,16 +4,15 @@ module GirFFI
|
|
4
4
|
module IArgInfo
|
5
5
|
def to_ffitype
|
6
6
|
return :pointer if direction != :in
|
7
|
-
|
7
|
+
argument_type.to_ffitype
|
8
8
|
end
|
9
9
|
|
10
10
|
def to_callback_ffitype
|
11
11
|
return :pointer if direction != :in
|
12
|
-
|
12
|
+
argument_type.to_callback_ffitype
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
GObjectIntrospection::IArgInfo.send :include, GirFFI::InfoExt::IArgInfo
|
19
|
-
|
@@ -11,17 +11,10 @@ module GirFFI
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def return_ffi_type
|
14
|
-
|
15
|
-
# FIXME: Should this be in ITypeInfo#to_callback_ffitype?
|
16
|
-
if result == GLib::Boolean
|
17
|
-
:bool
|
18
|
-
else
|
19
|
-
result
|
20
|
-
end
|
14
|
+
return_type.to_callback_ffitype
|
21
15
|
end
|
22
16
|
end
|
23
17
|
end
|
24
18
|
end
|
25
19
|
|
26
20
|
GObjectIntrospection::ICallbackInfo.send :include, GirFFI::InfoExt::ICallbackInfo
|
27
|
-
|
@@ -2,32 +2,21 @@ module GirFFI
|
|
2
2
|
module InfoExt
|
3
3
|
# Extensions for GObjectIntrospection::ISignalInfo needed by GirFFI
|
4
4
|
module ISignalInfo
|
5
|
-
# Create a signal hander
|
6
|
-
#
|
5
|
+
# Create a signal hander closure. Wraps the given block in a custom
|
6
|
+
# descendent of RubyClosure with a marshaller tailored for this signal.
|
7
7
|
#
|
8
8
|
# @param block The body of the signal handler
|
9
9
|
#
|
10
|
-
# @return [
|
11
|
-
#
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
# TODO: Find the signal module directly, then retrieve the info
|
16
|
-
# from that, instead of vice versa.
|
17
|
-
bldr = Builders::SignalBuilder.new(self)
|
18
|
-
wrapped = bldr.build_class.from(block)
|
19
|
-
# FIXME: Logically, this should use CallbackBase#to_native
|
20
|
-
FFI::Function.new return_ffi_type, ffi_callback_argument_types, &wrapped
|
10
|
+
# @return [GObject::RubyClosure] The signal handler closure, ready to be
|
11
|
+
# passed as a GClosure to C.
|
12
|
+
def wrap_in_closure &block
|
13
|
+
bldr = Builders::SignalClosureBuilder.new(self)
|
14
|
+
bldr.build_class.new(&block)
|
21
15
|
end
|
22
16
|
|
23
17
|
# TODO: Use argument info to convert out arguments and array lengths.
|
24
|
-
def arguments_to_gvalue_array_pointer object, args
|
25
|
-
arr = arguments_to_gvalues object, args
|
26
|
-
GirFFI::InPointer.from_array GObject::Value, arr
|
27
|
-
end
|
28
|
-
|
29
18
|
def arguments_to_gvalues instance, arguments
|
30
|
-
arg_values =
|
19
|
+
arg_values = args.zip(arguments).map do |info, arg|
|
31
20
|
info.argument_type.make_g_value.set_value(arg)
|
32
21
|
end
|
33
22
|
|
@@ -37,27 +26,6 @@ module GirFFI
|
|
37
26
|
def gvalue_for_return_value
|
38
27
|
return_type.make_g_value
|
39
28
|
end
|
40
|
-
|
41
|
-
# TODO: Rename and clarify relation to argument_ffi_types:
|
42
|
-
# The types returned by ffi_callback_argument_types are more basic than
|
43
|
-
# those returned by argument_ffi_types. Is there a way to make these
|
44
|
-
# methods more related? Perhaps argument_ffi_types can return more basic
|
45
|
-
# types as well?
|
46
|
-
def ffi_callback_argument_types
|
47
|
-
types = args.map do |arg|
|
48
|
-
arg.to_callback_ffitype
|
49
|
-
end
|
50
|
-
types.unshift(:pointer).push(:pointer)
|
51
|
-
end
|
52
|
-
|
53
|
-
def return_ffi_type
|
54
|
-
result = return_type.to_ffitype
|
55
|
-
if result == GLib::Boolean
|
56
|
-
:bool
|
57
|
-
else
|
58
|
-
result
|
59
|
-
end
|
60
|
-
end
|
61
29
|
end
|
62
30
|
end
|
63
31
|
end
|
@@ -112,16 +112,22 @@ module GirFFI
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
+
# TODO: Use either ffitype or ffi_type everywhere
|
115
116
|
def to_callback_ffitype
|
116
117
|
return :pointer if pointer?
|
117
118
|
|
118
|
-
|
119
|
+
case tag
|
120
|
+
when :interface
|
121
|
+
# TODO: Move this logic into interface
|
119
122
|
case interface.info_type
|
120
123
|
when :enum, :flags
|
121
124
|
:int32
|
122
125
|
else
|
123
126
|
:pointer
|
124
127
|
end
|
128
|
+
when :gboolean
|
129
|
+
# TODO: Move this logic into TypeMap
|
130
|
+
:bool
|
125
131
|
else
|
126
132
|
TypeMap.map_basic_type tag
|
127
133
|
end
|
@@ -156,6 +162,10 @@ module GirFFI
|
|
156
162
|
needs_c_to_ruby_conversion_for_functions?
|
157
163
|
end
|
158
164
|
|
165
|
+
def needs_c_to_ruby_conversion_for_closures?
|
166
|
+
[:array, :c, :ghash, :struct, :strv].include?(flattened_tag)
|
167
|
+
end
|
168
|
+
|
159
169
|
def extra_conversion_arguments
|
160
170
|
case flattened_tag
|
161
171
|
when :utf8, :void
|
@@ -183,7 +193,7 @@ module GirFFI
|
|
183
193
|
subtype_tag_or_class 0
|
184
194
|
end
|
185
195
|
|
186
|
-
def subtype_ffitype
|
196
|
+
def subtype_ffitype index
|
187
197
|
subtype = param_type(index).to_ffitype
|
188
198
|
if subtype == :pointer
|
189
199
|
# NOTE: Don't use pointer directly to appease JRuby.
|
data/lib/gir_ffi/info_ext.rb
CHANGED
data/lib/gir_ffi/lib_c.rb
CHANGED
data/lib/gir_ffi/module_base.rb
CHANGED
@@ -4,7 +4,7 @@ module GirFFI
|
|
4
4
|
def method_missing method, *arguments, &block
|
5
5
|
result = setup_method method.to_s
|
6
6
|
return super unless result
|
7
|
-
|
7
|
+
send method, *arguments, &block
|
8
8
|
end
|
9
9
|
|
10
10
|
def const_missing classname
|
@@ -18,7 +18,7 @@ module GirFFI
|
|
18
18
|
alias load_class setup_class
|
19
19
|
|
20
20
|
def gir_ffi_builder
|
21
|
-
|
21
|
+
const_get :GIR_FFI_BUILDER
|
22
22
|
end
|
23
23
|
|
24
24
|
def setup_method name
|
data/lib/gir_ffi/object_base.rb
CHANGED
@@ -1,22 +1,6 @@
|
|
1
1
|
module GirFFI
|
2
2
|
# Base class for all generated classes of type :object.
|
3
3
|
class ObjectBase < ClassBase
|
4
|
-
#
|
5
|
-
# Wraps a pointer retrieved from a constructor method. Here, it is simply
|
6
|
-
# defined as a wrapper around direct_wrap, but, e.g., InitiallyUnowned
|
7
|
-
# overrides it to sink the floating object.
|
8
|
-
#
|
9
|
-
# Unlike wrap, this method assumes the pointer will always be of the type
|
10
|
-
# corresponding to the current class, and never of a subtype.
|
11
|
-
#
|
12
|
-
# @param ptr Pointer to the object's C structure
|
13
|
-
#
|
14
|
-
# @return An object of the current class wrapping the pointer
|
15
|
-
#
|
16
|
-
def self.constructor_wrap ptr
|
17
|
-
direct_wrap ptr
|
18
|
-
end
|
19
|
-
|
20
4
|
# Wrap the passed pointer in an instance of its type's corresponding class,
|
21
5
|
# generally assumed to be a descendant of the current type.
|
22
6
|
def self.wrap ptr
|
data/lib/gir_ffi/sized_array.rb
CHANGED
@@ -19,14 +19,14 @@ module GirFFI
|
|
19
19
|
ptr.to_ruby_value
|
20
20
|
end
|
21
21
|
|
22
|
-
def each
|
22
|
+
def each
|
23
23
|
size.times do |idx|
|
24
24
|
yield index(idx)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
def ==
|
29
|
-
|
28
|
+
def == other
|
29
|
+
to_a == other.to_a
|
30
30
|
end
|
31
31
|
|
32
32
|
def size_in_bytes
|
@@ -81,10 +81,10 @@ module GirFFI
|
|
81
81
|
size = arr.size
|
82
82
|
check_size expected_size, size
|
83
83
|
ptr = GirFFI::InPointer.from_array element_type, arr
|
84
|
-
|
84
|
+
wrap element_type, size, ptr
|
85
85
|
end
|
86
86
|
|
87
|
-
def check_size
|
87
|
+
def check_size expected_size, size
|
88
88
|
if expected_size > 0 && size != expected_size
|
89
89
|
raise ArgumentError, "Expected size #{expected_size}, got #{size}"
|
90
90
|
end
|
data/lib/gir_ffi/struct_base.rb
CHANGED
data/lib/gir_ffi/type_base.rb
CHANGED
@@ -2,11 +2,11 @@ module GirFFI
|
|
2
2
|
# Base module for all generated GLib types.
|
3
3
|
module TypeBase
|
4
4
|
def gir_ffi_builder
|
5
|
-
|
5
|
+
const_get :GIR_FFI_BUILDER
|
6
6
|
end
|
7
7
|
|
8
8
|
def gir_info
|
9
|
-
|
9
|
+
const_get :GIR_INFO
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
data/lib/gir_ffi/type_map.rb
CHANGED
@@ -4,9 +4,7 @@ module GirFFI
|
|
4
4
|
class UnintrospectableTypeInfo
|
5
5
|
attr_reader :g_type
|
6
6
|
|
7
|
-
def initialize
|
8
|
-
gir = GObjectIntrospection::IRepository.default,
|
9
|
-
gobject = ::GObject)
|
7
|
+
def initialize gtype, gir = GObjectIntrospection::IRepository.default, gobject = GObject
|
10
8
|
@g_type = gtype
|
11
9
|
@gir = gir
|
12
10
|
@gobject = gobject
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'gir_ffi/info_ext/i_type_info'
|
2
2
|
|
3
|
+
# Represents the type of the user data (closure argument) of a signal or vfunc,
|
4
|
+
# conforming, as needed, to the interface of GObjectIntrospection::ITypeInfo.
|
3
5
|
class GirFFI::UserDataTypeInfo
|
4
6
|
include GirFFI::InfoExt::ITypeInfo
|
5
7
|
|
data/lib/gir_ffi/version.rb
CHANGED
@@ -15,24 +15,24 @@ module GirFFI
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.from type, arg
|
18
|
-
|
18
|
+
new type, InPointer.from_array(type, arg)
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.wrap type, arg
|
22
|
-
|
22
|
+
new type, arg
|
23
23
|
end
|
24
24
|
|
25
25
|
def each
|
26
26
|
return if @ptr.null?
|
27
27
|
offset = 0
|
28
28
|
while val = read_value(offset)
|
29
|
-
offset +=
|
29
|
+
offset += ffi_type_size
|
30
30
|
yield wrap_value(val)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def ==
|
35
|
-
|
34
|
+
def == other
|
35
|
+
to_a == other.to_a
|
36
36
|
end
|
37
37
|
|
38
38
|
private
|
@@ -46,7 +46,7 @@ module GirFFI
|
|
46
46
|
@getter_method ||= "get_#{ffi_type}"
|
47
47
|
end
|
48
48
|
|
49
|
-
def wrap_value
|
49
|
+
def wrap_value val
|
50
50
|
case element_type
|
51
51
|
when Array
|
52
52
|
element_type.last.wrap val
|
@@ -6,11 +6,11 @@ module GLib
|
|
6
6
|
extend FFI::DataConverter
|
7
7
|
native_type FFI::Type::INT
|
8
8
|
|
9
|
-
def self.from_native value,
|
9
|
+
def self.from_native value, _context
|
10
10
|
value != 0 ? true : false
|
11
11
|
end
|
12
12
|
|
13
|
-
def self.to_native value,
|
13
|
+
def self.to_native value, _context
|
14
14
|
value ? 1 : 0
|
15
15
|
end
|
16
16
|
|
data/lib/gir_ffi-base/gobject.rb
CHANGED
data/lib/gir_ffi.rb
CHANGED
@@ -17,6 +17,8 @@ require 'gir_ffi/user_defined_type_info'
|
|
17
17
|
require 'gir_ffi/builder'
|
18
18
|
require 'gir_ffi/version'
|
19
19
|
|
20
|
+
# Main module containing classes and modules needed for generating GLib and
|
21
|
+
# GObject bindings.
|
20
22
|
module GirFFI
|
21
23
|
def self.setup module_name, version=nil
|
22
24
|
module_name = module_name.to_s
|
@@ -8,7 +8,7 @@ describe GLib::HashTable do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
describe "::from" do
|
11
|
-
it "creates a GHashTable from a Ruby
|
11
|
+
it "creates a GHashTable from a Ruby hash" do
|
12
12
|
hsh = GLib::HashTable.from [:utf8, :gint32],
|
13
13
|
{"foo" => 23, "bar" => 32}
|
14
14
|
assert_equal({"foo" => 23, "bar" => 32}, hsh.to_hash)
|