ffi 0.6.3-x86-mingw32 → 1.0.1-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of ffi might be problematic. Click here for more details.
- data/History.txt +7 -0
- data/LICENSE +10 -21
- data/README.rdoc +1 -0
- data/Rakefile +4 -2
- data/ext/ffi_c/AbstractMemory.c +103 -38
- data/ext/ffi_c/AbstractMemory.h +15 -22
- data/ext/ffi_c/Buffer.c +61 -22
- data/ext/ffi_c/Call.c +52 -540
- data/ext/ffi_c/Call.h +1 -1
- data/ext/ffi_c/DataConverter.c +62 -0
- data/ext/ffi_c/DynamicLibrary.c +21 -1
- data/ext/ffi_c/Function.c +315 -30
- data/ext/ffi_c/MappedType.c +146 -0
- data/ext/ffi_c/MappedType.h +57 -0
- data/ext/ffi_c/MemoryPointer.c +12 -33
- data/ext/ffi_c/Platform.c +2 -0
- data/ext/ffi_c/Pointer.c +66 -28
- data/ext/ffi_c/Struct.c +19 -306
- data/ext/ffi_c/Struct.h +6 -0
- data/ext/ffi_c/StructByReference.c +150 -0
- data/ext/ffi_c/StructByReference.h +50 -0
- data/ext/ffi_c/StructLayout.c +25 -14
- data/ext/ffi_c/Type.c +39 -68
- data/ext/ffi_c/Type.h +12 -22
- data/ext/ffi_c/Types.c +20 -5
- data/ext/ffi_c/Types.h +7 -7
- data/ext/ffi_c/Variadic.c +21 -17
- data/ext/ffi_c/extconf.rb +4 -0
- data/ext/ffi_c/ffi.c +8 -2
- data/ext/ffi_c/rbffi.h +1 -0
- data/lib/ffi/autopointer.rb +23 -22
- data/lib/ffi/enum.rb +36 -21
- data/lib/ffi/errno.rb +20 -0
- data/lib/ffi/ffi.rb +13 -80
- data/lib/ffi/io.rb +12 -20
- data/lib/ffi/library.rb +109 -92
- data/lib/ffi/managedstruct.rb +1 -1
- data/lib/ffi/memorypointer.rb +15 -21
- data/lib/ffi/platform.rb +24 -28
- data/lib/ffi/pointer.rb +14 -21
- data/lib/ffi/struct.rb +98 -49
- data/lib/ffi/struct_layout_builder.rb +158 -0
- data/lib/ffi/types.rb +99 -128
- data/lib/ffi/union.rb +20 -0
- data/lib/ffi/variadic.rb +33 -22
- data/lib/ffi_c.so +0 -0
- data/spec/ffi/async_callback_spec.rb +23 -0
- data/spec/ffi/callback_spec.rb +62 -0
- data/spec/ffi/custom_param_type.rb +31 -0
- data/spec/ffi/custom_type_spec.rb +73 -0
- data/spec/ffi/enum_spec.rb +19 -0
- data/spec/ffi/ffi_spec.rb +24 -0
- data/spec/ffi/pointer_spec.rb +15 -0
- data/spec/ffi/rbx/memory_pointer_spec.rb +7 -1
- data/spec/ffi/strptr_spec.rb +36 -0
- data/spec/ffi/struct_packed_spec.rb +46 -0
- data/spec/ffi/struct_spec.rb +19 -5
- data/spec/ffi/typedef_spec.rb +14 -0
- data/tasks/setup.rb +2 -1
- metadata +15 -6
- data/ext/ffi_c/AutoPointer.c +0 -60
- data/ext/ffi_c/AutoPointer.h +0 -18
- data/lib/1.8/ffi_c.so +0 -0
- data/lib/1.9/ffi_c.so +0 -0
data/lib/ffi/ffi.rb
CHANGED
@@ -1,43 +1,21 @@
|
|
1
1
|
#
|
2
|
-
# Copyright (C) 2008 JRuby project
|
3
|
-
#
|
2
|
+
# Copyright (C) 2008-2010 JRuby project
|
3
|
+
#
|
4
4
|
# All rights reserved.
|
5
5
|
#
|
6
|
-
#
|
7
|
-
# modification, are permitted provided that the following conditions are met:
|
6
|
+
# This file is part of ruby-ffi.
|
8
7
|
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# this list of conditions and the following disclaimer in the documentation
|
13
|
-
# and/or other materials provided with the distribution.
|
14
|
-
# * Neither the name of the Evan Phoenix nor the names of its contributors
|
15
|
-
# may be used to endorse or promote products derived from this software
|
16
|
-
# without specific prior written permission.
|
8
|
+
# This code is free software: you can redistribute it and/or modify it under
|
9
|
+
# the terms of the GNU Lesser General Public License version 3 only, as
|
10
|
+
# published by the Free Software Foundation.
|
17
11
|
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
26
|
-
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27
|
-
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28
|
-
|
29
|
-
module FFI
|
30
|
-
# Specialised error classes
|
31
|
-
class NativeError < LoadError; end
|
32
|
-
|
33
|
-
class SignatureError < NativeError; end
|
34
|
-
|
35
|
-
class NotFoundError < NativeError
|
36
|
-
def initialize(function, *libraries)
|
37
|
-
super("Function '#{function}' not found in [#{libraries[0].nil? ? 'current process' : libraries.join(", ")}]")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
12
|
+
# This code is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
15
|
+
# version 3 for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
41
19
|
|
42
20
|
require 'ffi/platform'
|
43
21
|
require 'ffi/types'
|
@@ -52,48 +30,3 @@ require 'ffi/io'
|
|
52
30
|
require 'ffi/autopointer'
|
53
31
|
require 'ffi/variadic'
|
54
32
|
require 'ffi/enum'
|
55
|
-
|
56
|
-
module FFI
|
57
|
-
|
58
|
-
def self.map_library_name(lib)
|
59
|
-
# Mangle the library name to reflect the native library naming conventions
|
60
|
-
lib = lib.to_s unless lib.kind_of?(String)
|
61
|
-
lib = Platform::LIBC if Platform::IS_LINUX && lib == 'c'
|
62
|
-
if lib && File.basename(lib) == lib
|
63
|
-
ext = ".#{Platform::LIBSUFFIX}"
|
64
|
-
lib = Platform::LIBPREFIX + lib unless lib =~ /^#{Platform::LIBPREFIX}/
|
65
|
-
lib += ext unless lib =~ /#{ext}/
|
66
|
-
end
|
67
|
-
lib
|
68
|
-
end
|
69
|
-
|
70
|
-
|
71
|
-
def self.create_invoker(lib, name, args, ret_type, options = { :convention => :default })
|
72
|
-
# Current artificial limitation based on JRuby::FFI limit
|
73
|
-
raise SignatureError, 'FFI functions may take max 32 arguments!' if args.size > 32
|
74
|
-
|
75
|
-
# Open the library if needed
|
76
|
-
library = if lib.kind_of?(DynamicLibrary)
|
77
|
-
lib
|
78
|
-
elsif lib.kind_of?(String)
|
79
|
-
# Allow FFI.create_invoker to be called with a library name
|
80
|
-
DynamicLibrary.open(FFI.map_library_name(lib), DynamicLibrary::RTLD_LAZY)
|
81
|
-
elsif lib.nil?
|
82
|
-
FFI::Library::DEFAULT
|
83
|
-
else
|
84
|
-
raise LoadError, "Invalid library '#{lib}'"
|
85
|
-
end
|
86
|
-
function = library.find_function(name)
|
87
|
-
raise NotFoundError.new(name, library.name) unless function
|
88
|
-
|
89
|
-
args = args.map {|e| find_type(e) }
|
90
|
-
invoker = if args.length > 0 && args[args.length - 1] == FFI::NativeType::VARARGS
|
91
|
-
FFI::VariadicInvoker.new(function, args, find_type(ret_type), options)
|
92
|
-
else
|
93
|
-
FFI::Function.new(find_type(ret_type), args, function, options)
|
94
|
-
end
|
95
|
-
raise NotFoundError.new(name, library.name) unless invoker
|
96
|
-
|
97
|
-
return invoker
|
98
|
-
end
|
99
|
-
end
|
data/lib/ffi/io.rb
CHANGED
@@ -3,28 +3,20 @@
|
|
3
3
|
#
|
4
4
|
# All rights reserved.
|
5
5
|
#
|
6
|
-
#
|
7
|
-
# modification, are permitted provided that the following conditions are met:
|
6
|
+
# This file is part of ruby-ffi.
|
8
7
|
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
8
|
+
# This code is free software: you can redistribute it and/or modify it under
|
9
|
+
# the terms of the GNU Lesser General Public License version 3 only, as
|
10
|
+
# published by the Free Software Foundation.
|
11
|
+
#
|
12
|
+
# This code is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
15
|
+
# version 3 for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
17
19
|
#
|
18
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
19
|
-
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
20
|
-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21
|
-
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
22
|
-
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
23
|
-
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
24
|
-
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
25
|
-
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
26
|
-
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27
|
-
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28
20
|
|
29
21
|
module FFI
|
30
22
|
module IO
|
data/lib/ffi/library.rb
CHANGED
@@ -1,35 +1,46 @@
|
|
1
1
|
#
|
2
|
-
# Copyright (C) 2008
|
2
|
+
# Copyright (C) 2008-2010 Wayne Meissner
|
3
3
|
# Copyright (C) 2008 Luc Heinrich <luc@honk-honk.com>
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# All rights reserved.
|
6
6
|
#
|
7
|
-
#
|
8
|
-
#
|
7
|
+
# This file is part of ruby-ffi.
|
8
|
+
#
|
9
|
+
# This code is free software: you can redistribute it and/or modify it under
|
10
|
+
# the terms of the GNU Lesser General Public License version 3 only, as
|
11
|
+
# published by the Free Software Foundation.
|
9
12
|
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# and/or other materials provided with the distribution.
|
15
|
-
# * Neither the name of the Evan Phoenix nor the names of its contributors
|
16
|
-
# may be used to endorse or promote products derived from this software
|
17
|
-
# without specific prior written permission.
|
13
|
+
# This code is distributed in the hope that it will be useful, but WITHOUT
|
14
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
16
|
+
# version 3 for more details.
|
18
17
|
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
22
|
-
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
23
|
-
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
24
|
-
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
25
|
-
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
26
|
-
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
27
|
-
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
-
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
18
|
+
# You should have received a copy of the GNU Lesser General Public License
|
19
|
+
# version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
29
20
|
|
30
21
|
module FFI
|
31
22
|
CURRENT_PROCESS = USE_THIS_PROCESS_AS_LIBRARY = Object.new
|
32
23
|
|
24
|
+
def self.map_library_name(lib)
|
25
|
+
# Mangle the library name to reflect the native library naming conventions
|
26
|
+
lib = lib.to_s unless lib.kind_of?(String)
|
27
|
+
lib = Library::LIBC if lib == 'c'
|
28
|
+
|
29
|
+
if lib && File.basename(lib) == lib
|
30
|
+
lib = Platform::LIBPREFIX + lib unless lib =~ /^#{Platform::LIBPREFIX}/
|
31
|
+
r = Platform::IS_LINUX ? "\\.so($|\\.[1234567890]+)" : "\\.#{Platform::LIBSUFFIX}$"
|
32
|
+
lib += ".#{Platform::LIBSUFFIX}" unless lib =~ /#{r}/
|
33
|
+
end
|
34
|
+
|
35
|
+
lib
|
36
|
+
end
|
37
|
+
|
38
|
+
class NotFoundError < LoadError
|
39
|
+
def initialize(function, *libraries)
|
40
|
+
super("Function '#{function}' not found in [#{libraries[0].nil? ? 'current process' : libraries.join(", ")}]")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
33
44
|
module Library
|
34
45
|
CURRENT_PROCESS = FFI::CURRENT_PROCESS
|
35
46
|
LIBC = FFI::Platform::LIBC
|
@@ -39,10 +50,12 @@ module FFI
|
|
39
50
|
end
|
40
51
|
|
41
52
|
def ffi_lib(*names)
|
42
|
-
|
53
|
+
lib_flags = defined?(@ffi_lib_flags) ? @ffi_lib_flags : FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_LOCAL
|
43
54
|
ffi_libs = names.map do |name|
|
55
|
+
|
44
56
|
if name == FFI::CURRENT_PROCESS
|
45
57
|
FFI::DynamicLibrary.open(nil, FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_LOCAL)
|
58
|
+
|
46
59
|
else
|
47
60
|
libnames = (name.is_a?(::Array) ? name : [ name ]).map { |n| [ n, FFI.map_library_name(n) ].uniq }.flatten.compact
|
48
61
|
lib = nil
|
@@ -50,8 +63,9 @@ module FFI
|
|
50
63
|
|
51
64
|
libnames.each do |libname|
|
52
65
|
begin
|
53
|
-
lib = FFI::DynamicLibrary.open(libname,
|
66
|
+
lib = FFI::DynamicLibrary.open(libname, lib_flags)
|
54
67
|
break if lib
|
68
|
+
|
55
69
|
rescue Exception => ex
|
56
70
|
errors[libname] = ex
|
57
71
|
end
|
@@ -80,66 +94,63 @@ module FFI
|
|
80
94
|
@ffi_libs
|
81
95
|
end
|
82
96
|
|
97
|
+
FlagsMap = {
|
98
|
+
:global => DynamicLibrary::RTLD_GLOBAL,
|
99
|
+
:local => DynamicLibrary::RTLD_LOCAL,
|
100
|
+
:lazy => DynamicLibrary::RTLD_LAZY,
|
101
|
+
:now => DynamicLibrary::RTLD_NOW
|
102
|
+
}
|
103
|
+
|
104
|
+
def ffi_lib_flags(*flags)
|
105
|
+
@ffi_lib_flags = flags.inject(0) { |result, f| result | FlagsMap[f] }
|
106
|
+
end
|
107
|
+
|
108
|
+
|
83
109
|
##
|
84
|
-
# Attach C function
|
85
|
-
#
|
86
|
-
# If you want to provide an alternate name for the module function, supply
|
87
|
-
# it after the +name+, otherwise the C function name will be used.#
|
88
|
-
#
|
89
|
-
# After the +name+, the C function argument types are provided as an Array.
|
110
|
+
# Attach C function to this module.
|
90
111
|
#
|
91
|
-
|
92
|
-
|
93
|
-
def attach_function(mname, a3, a4, a5=nil)
|
94
|
-
cname, arg_types, ret_type = a5 ? [ a3, a4, a5 ] : [ mname.to_s, a3, a4 ]
|
112
|
+
def attach_function(mname, a2, a3, a4=nil, a5 = nil)
|
113
|
+
cname, arg_types, ret_type, opts = (a4 && (a2.is_a?(String) || a2.is_a?(Symbol))) ? [ a2, a3, a4, a5 ] : [ mname.to_s, a2, a3, a4 ]
|
95
114
|
|
96
115
|
# Convert :foo to the native type
|
97
116
|
arg_types.map! { |e| find_type(e) }
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
117
|
+
options = {
|
118
|
+
:convention => defined?(@ffi_convention) ? @ffi_convention : :default,
|
119
|
+
:type_map => defined?(@ffi_typedefs) ? @ffi_typedefs : nil,
|
120
|
+
:blocking => defined?(@blocking) && @blocking,
|
121
|
+
:enums => defined?(@ffi_enums) ? @ffi_enums : nil,
|
122
|
+
}
|
123
|
+
|
124
|
+
@blocking = false
|
125
|
+
options.merge!(opts) if opts && opts.is_a?(Hash)
|
103
126
|
|
104
127
|
# Try to locate the function in any of the libraries
|
105
128
|
invokers = []
|
106
129
|
ffi_libraries.each do |lib|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
end
|
112
|
-
invoker = invokers.compact.shift
|
113
|
-
raise FFI::NotFoundError.new(cname.to_s, ffi_libraries.map { |lib| lib.name }) unless invoker
|
130
|
+
if invokers.empty?
|
131
|
+
begin
|
132
|
+
function = lib.find_function(cname.to_s)
|
133
|
+
raise LoadError unless function
|
114
134
|
|
115
|
-
|
116
|
-
|
117
|
-
params = (1..arity).map {|i| "a#{i}" }.join(",")
|
135
|
+
invokers << if arg_types.length > 0 && arg_types[arg_types.length - 1] == FFI::NativeType::VARARGS
|
136
|
+
VariadicInvoker.new(function, arg_types, find_type(ret_type), options)
|
118
137
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
end
|
123
|
-
call = arity <= 3 && !has_callback && !invoker.kind_of?(FFI::VariadicInvoker)? "call#{arity}" : "call"
|
138
|
+
else
|
139
|
+
Function.new(find_type(ret_type), arg_types, function, options)
|
140
|
+
end
|
124
141
|
|
125
|
-
|
126
|
-
# Attach the invoker to this module as 'mname'.
|
127
|
-
#
|
128
|
-
if !has_callback && !invoker.kind_of?(FFI::VariadicInvoker)
|
129
|
-
invoker.attach(self, mname.to_s)
|
130
|
-
else
|
131
|
-
self.module_eval <<-code
|
132
|
-
@@#{mname} = invoker
|
133
|
-
def self.#{mname}(#{params})
|
134
|
-
@@#{mname}.#{call}(#{params})
|
142
|
+
rescue LoadError => ex
|
135
143
|
end
|
136
|
-
|
137
|
-
@@#{mname}.#{call}(#{params})
|
138
|
-
end
|
139
|
-
code
|
144
|
+
end
|
140
145
|
end
|
146
|
+
invoker = invokers.compact.shift
|
147
|
+
raise FFI::NotFoundError.new(cname.to_s, ffi_libraries.map { |lib| lib.name }) unless invoker
|
148
|
+
|
149
|
+
invoker.attach(self, mname.to_s)
|
141
150
|
invoker
|
142
151
|
end
|
152
|
+
|
153
|
+
|
143
154
|
def attach_variable(mname, a1, a2 = nil)
|
144
155
|
cname, type = a2 ? [ a1, a2 ] : [ mname.to_s, a1 ]
|
145
156
|
address = nil
|
@@ -199,28 +210,34 @@ module FFI
|
|
199
210
|
|
200
211
|
# Add to the symbol -> type map (unless there was no name)
|
201
212
|
unless name.nil?
|
202
|
-
|
203
|
-
@ffi_callbacks[name] = cb
|
213
|
+
typedef cb, name
|
204
214
|
end
|
205
215
|
|
206
216
|
cb
|
207
217
|
end
|
208
218
|
|
209
|
-
def typedef(
|
219
|
+
def typedef(old, add, info=nil)
|
210
220
|
@ffi_typedefs = Hash.new unless defined?(@ffi_typedefs)
|
211
|
-
|
212
|
-
|
213
|
-
|
221
|
+
|
222
|
+
@ffi_typedefs[add] = if old.kind_of?(FFI::Type)
|
223
|
+
old
|
224
|
+
|
225
|
+
elsif @ffi_typedefs.has_key?(old)
|
226
|
+
@ffi_typedefs[old]
|
227
|
+
|
228
|
+
elsif old.is_a?(DataConverter)
|
229
|
+
FFI::Type::Mapped.new(old)
|
230
|
+
|
231
|
+
elsif old == :enum
|
214
232
|
if add.kind_of?(Array)
|
215
233
|
self.enum(add)
|
216
234
|
else
|
217
235
|
self.enum(info, add)
|
218
236
|
end
|
237
|
+
|
219
238
|
else
|
220
|
-
|
239
|
+
FFI.find_type(old)
|
221
240
|
end
|
222
|
-
|
223
|
-
@ffi_typedefs[add] = code
|
224
241
|
end
|
225
242
|
|
226
243
|
def enum(*args)
|
@@ -253,21 +270,21 @@ module FFI
|
|
253
270
|
@ffi_enums.__map_symbol(symbol)
|
254
271
|
end
|
255
272
|
|
256
|
-
def find_type(
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
elsif
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
end
|
273
|
+
def find_type(t)
|
274
|
+
if t.kind_of?(Type)
|
275
|
+
t
|
276
|
+
|
277
|
+
elsif defined?(@ffi_typedefs) && @ffi_typedefs.has_key?(t)
|
278
|
+
@ffi_typedefs[t]
|
279
|
+
|
280
|
+
elsif t.is_a?(Class) && t < Struct
|
281
|
+
Type::POINTER
|
282
|
+
|
283
|
+
elsif t.is_a?(DataConverter)
|
284
|
+
# Add a typedef so next time the converter is used, it hits the cache
|
285
|
+
typedef Type::Mapped.new(t), t
|
286
|
+
|
287
|
+
end || FFI.find_type(t)
|
271
288
|
end
|
272
289
|
end
|
273
290
|
end
|
data/lib/ffi/managedstruct.rb
CHANGED
@@ -48,7 +48,7 @@ module FFI
|
|
48
48
|
def initialize(pointer=nil)
|
49
49
|
raise NoMethodError, "release() not implemented for class #{self}" unless self.class.respond_to? :release
|
50
50
|
raise ArgumentError, "Must supply a pointer to memory for the Struct" unless pointer
|
51
|
-
super
|
51
|
+
super AutoPointer.new(pointer, self.class.method(:release))
|
52
52
|
end
|
53
53
|
|
54
54
|
end
|
data/lib/ffi/memorypointer.rb
CHANGED
@@ -2,35 +2,29 @@
|
|
2
2
|
# Copyright (C) 2008, 2009 Wayne Meissner
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
5
|
-
#
|
6
|
-
#
|
5
|
+
# All rights reserved.
|
6
|
+
#
|
7
|
+
# This file is part of ruby-ffi.
|
8
|
+
#
|
9
|
+
# This code is free software: you can redistribute it and/or modify it under
|
10
|
+
# the terms of the GNU Lesser General Public License version 3 only, as
|
11
|
+
# published by the Free Software Foundation.
|
12
|
+
#
|
13
|
+
# This code is distributed in the hope that it will be useful, but WITHOUT
|
14
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
16
|
+
# version 3 for more details.
|
7
17
|
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# * Redistributions in binary form must reproduce the above copyright notice
|
11
|
-
# this list of conditions and the following disclaimer in the documentation
|
12
|
-
# and/or other materials provided with the distribution.
|
13
|
-
# * Neither the name of the Evan Phoenix nor the names of its contributors
|
14
|
-
# may be used to endorse or promote products derived from this software
|
15
|
-
# without specific prior written permission.
|
18
|
+
# You should have received a copy of the GNU Lesser General Public License
|
19
|
+
# version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
16
20
|
#
|
17
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
18
|
-
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
19
|
-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
20
|
-
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
21
|
-
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
22
|
-
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
23
|
-
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
24
|
-
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
25
|
-
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
26
|
-
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
21
|
|
28
22
|
require 'ffi/pointer'
|
29
23
|
module FFI
|
30
24
|
class MemoryPointer
|
31
25
|
|
32
26
|
def self.from_string(s)
|
33
|
-
ptr = self.new(s.
|
27
|
+
ptr = self.new(s.bytesize + 1, 1, false)
|
34
28
|
ptr.put_string(0, s)
|
35
29
|
ptr
|
36
30
|
end
|