ffi-module 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ffi/module/config_tool.rb +7 -1
- data/lib/ffi/module/library.rb +35 -34
- data/lib/ffi/module/loader.rb +4 -0
- data/lib/ffi/module/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b8ee4221b08ecf01f4453a41392cb0582382f5b8d377ec5a8125605ab4760e8
|
4
|
+
data.tar.gz: 4fee30465f129049c8fdd53d231d4a2baff1acacf31d2946eaa302b0551b024f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbca3d3dc2cb769015c260a205da7dd3e4fbd2ef8decc7cf79ff23ed6f86ac81a34411dc95a67a1578d87318a9a639a940e2fd94701be4f7a2458faa6f2b905d
|
7
|
+
data.tar.gz: 9b2871ac1451939a2b332af2f60cc1885b56b0daa688e882508b16007e88a1069aa5e95b67758ac55c07ba6e0ee2c0cc76788b777998c4405a8a32d9430c22cf
|
@@ -51,10 +51,16 @@ module FFI
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
result = false
|
55
|
+
|
54
56
|
# Load all specified libraries:
|
55
57
|
names.each do |name|
|
56
|
-
ffi_load(name, search_paths: search_paths, **options)
|
58
|
+
result = ffi_load(name, search_paths: search_paths, **options) || result
|
57
59
|
end
|
60
|
+
|
61
|
+
return result
|
62
|
+
rescue Errno::ENOENT
|
63
|
+
return nil
|
58
64
|
end
|
59
65
|
end
|
60
66
|
end
|
data/lib/ffi/module/library.rb
CHANGED
@@ -40,7 +40,8 @@ module FFI
|
|
40
40
|
@ffi_libraries << DynamicLibrary.open(name, flags)
|
41
41
|
|
42
42
|
return true
|
43
|
-
rescue LoadError
|
43
|
+
rescue LoadError, RuntimeError
|
44
|
+
# TruffleRuby raises a RuntimeError if the library can't be found.
|
44
45
|
return nil
|
45
46
|
end
|
46
47
|
|
@@ -52,7 +53,7 @@ module FFI
|
|
52
53
|
return @ffi_calling_convention
|
53
54
|
end
|
54
55
|
|
55
|
-
def ffi_attach_function(name,
|
56
|
+
def ffi_attach_function(name, argument_types, return_type = :void, as: name, **options)
|
56
57
|
argument_types = argument_types.map{|type| self.ffi_find_type(type)}
|
57
58
|
return_type = self.ffi_find_type(return_type)
|
58
59
|
|
@@ -65,7 +66,7 @@ module FFI
|
|
65
66
|
@ffi_libraries.each do |library|
|
66
67
|
function = nil
|
67
68
|
|
68
|
-
ffi_function_names(
|
69
|
+
ffi_function_names(name, argument_types).each do |function_name|
|
69
70
|
break if function = library.find_function(function_name.to_s)
|
70
71
|
end
|
71
72
|
|
@@ -81,29 +82,29 @@ module FFI
|
|
81
82
|
end
|
82
83
|
|
83
84
|
if invoker
|
84
|
-
invoker.attach(self,
|
85
|
+
invoker.attach(self, as.to_s)
|
85
86
|
return true
|
86
87
|
else
|
87
|
-
raise FFI::NotFoundError.new(
|
88
|
+
raise FFI::NotFoundError.new(name, @ffi_libraries)
|
88
89
|
end
|
89
90
|
end
|
90
91
|
|
91
|
-
def ffi_attach_variable(name,
|
92
|
+
def ffi_attach_variable(name, type, as: name)
|
92
93
|
address = @ffi_libraries.find do |library|
|
93
94
|
begin
|
94
|
-
library.find_variable(
|
95
|
+
library.find_variable(name)
|
95
96
|
rescue LoadError
|
96
97
|
end
|
97
98
|
end
|
98
99
|
|
99
100
|
if address.nil? || address.null?
|
100
|
-
raise FFI::NotFoundError.new(
|
101
|
+
raise FFI::NotFoundError.new(name, @ffi_libraries)
|
101
102
|
end
|
102
103
|
|
103
104
|
if type.is_a?(Class) && type < FFI::Struct
|
104
105
|
variable = type.new(address)
|
105
106
|
|
106
|
-
self.define_singleton_method(
|
107
|
+
self.define_singleton_method(as) do
|
107
108
|
variable
|
108
109
|
end
|
109
110
|
else
|
@@ -111,11 +112,11 @@ module FFI
|
|
111
112
|
container_type.layout :value, self.ffi_find_type(type)
|
112
113
|
container = container_type.new(address)
|
113
114
|
|
114
|
-
self.define_singleton_method(
|
115
|
+
self.define_singleton_method(as) do
|
115
116
|
container[:value]
|
116
117
|
end
|
117
118
|
|
118
|
-
self.define_singleton_method(:"#{
|
119
|
+
self.define_singleton_method(:"#{as}=") do |value|
|
119
120
|
container[:value] = value
|
120
121
|
end
|
121
122
|
end
|
@@ -172,6 +173,29 @@ module FFI
|
|
172
173
|
ffi_define_generic_enumeration(name, FFI::Bitmask, native_type, *arguments)
|
173
174
|
end
|
174
175
|
|
176
|
+
def ffi_find_type(argument)
|
177
|
+
if argument.kind_of?(Type)
|
178
|
+
return argument
|
179
|
+
end
|
180
|
+
|
181
|
+
if type = @ffi_type_map[argument]
|
182
|
+
return type
|
183
|
+
end
|
184
|
+
|
185
|
+
if argument.is_a?(Class) && argument < Struct
|
186
|
+
return Type::POINTER
|
187
|
+
end
|
188
|
+
|
189
|
+
if argument.is_a?(DataConverter)
|
190
|
+
# Cache the mapped type:
|
191
|
+
return ffi_define_type(argument, Type::Mapped.new(argument))
|
192
|
+
end
|
193
|
+
|
194
|
+
if argument
|
195
|
+
return FFI.find_type(argument)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
175
199
|
private
|
176
200
|
|
177
201
|
def ffi_define_generic_enumeration(name, klass, native_type, values)
|
@@ -213,29 +237,6 @@ module FFI
|
|
213
237
|
|
214
238
|
return result
|
215
239
|
end
|
216
|
-
|
217
|
-
def ffi_find_type(argument)
|
218
|
-
if argument.kind_of?(Type)
|
219
|
-
return argument
|
220
|
-
end
|
221
|
-
|
222
|
-
if type = @ffi_type_map[argument]
|
223
|
-
return type
|
224
|
-
end
|
225
|
-
|
226
|
-
if argument.is_a?(Class) && argument < Struct
|
227
|
-
return Type::POINTER
|
228
|
-
end
|
229
|
-
|
230
|
-
if argument.is_a?(DataConverter)
|
231
|
-
# Cache the mapped type:
|
232
|
-
return ffi_define_type(argument, Type::Mapped.new(argument))
|
233
|
-
end
|
234
|
-
|
235
|
-
if argument
|
236
|
-
return FFI.find_type(argument)
|
237
|
-
end
|
238
|
-
end
|
239
240
|
end
|
240
241
|
end
|
241
242
|
end
|
data/lib/ffi/module/loader.rb
CHANGED
data/lib/ffi/module/version.rb
CHANGED