ffi-module 0.1.3 → 0.2.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/library.rb +11 -10
- 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: ca3d8712f429164d44b3b16b650bfa3f9184e4fb266c2da5ffe47588d4670679
|
4
|
+
data.tar.gz: 27ef2aa8e1fe00c763fd3e01e82ddce0d879705c19bb35a29bfca56214d07ac6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28f5d178cd0d7278cb7de726c12a948c94f7e83e86aaf8672e8f0d60d00da4fc5435a6e709e169bc8db2469b3377c68e2607da8e04a14a5273435c0220ba4aa3
|
7
|
+
data.tar.gz: 6c272955bfabb1d1f929a09908e5a33a67688d97a83f9364c3bf590313d84ffc7269d5ce0d3ee489069517d76f6ef9a5370ca6e7c925ec7478eacc3701a70602
|
data/lib/ffi/module/library.rb
CHANGED
@@ -41,6 +41,7 @@ module FFI
|
|
41
41
|
|
42
42
|
return true
|
43
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
|
data/lib/ffi/module/version.rb
CHANGED