ffi 1.1.1.rc1 → 1.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.
- data/COPYING +674 -0
- data/COPYING.LESSER +165 -0
- data/README.md +109 -0
- data/Rakefile +67 -43
- data/ext/ffi_c/AbstractMemory.c +16 -22
- data/ext/ffi_c/AbstractMemory.h +1 -1
- data/ext/ffi_c/ArrayType.c +6 -2
- data/ext/ffi_c/Buffer.c +5 -3
- data/ext/ffi_c/Call.c +18 -29
- data/ext/ffi_c/ClosurePool.c +1 -1
- data/ext/ffi_c/DynamicLibrary.c +2 -2
- data/ext/ffi_c/Ffi_c.iml +12 -0
- data/ext/ffi_c/Function.c +26 -25
- data/ext/ffi_c/Function.h +1 -1
- data/ext/ffi_c/FunctionInfo.c +27 -2
- data/ext/ffi_c/LongDouble.c +4 -0
- data/ext/ffi_c/MappedType.c +1 -3
- data/ext/ffi_c/MemoryPointer.c +37 -12
- data/ext/ffi_c/MethodHandle.c +7 -4
- data/ext/ffi_c/Pointer.c +6 -5
- data/ext/ffi_c/Struct.c +131 -14
- data/ext/ffi_c/StructByReference.c +33 -0
- data/ext/ffi_c/StructByValue.c +3 -3
- data/ext/ffi_c/StructLayout.c +143 -8
- data/ext/ffi_c/Thread.c +2 -2
- data/ext/ffi_c/Type.c +5 -4
- data/ext/ffi_c/Types.c +4 -2
- data/ext/ffi_c/Types.h +0 -4
- data/ext/ffi_c/Variadic.c +8 -2
- data/ext/ffi_c/extconf.rb +9 -8
- data/ext/ffi_c/ffi.c +2 -2
- data/ext/ffi_c/libffi.bsd.mk +1 -1
- data/ext/ffi_c/libffi.darwin.mk +8 -6
- data/ext/ffi_c/libffi.mk +2 -2
- data/ext/ffi_c/rbffi_endian.h +10 -1
- data/ffi.gemspec +18 -0
- data/gen/log +1 -0
- data/lib/Lib.iml +21 -0
- data/lib/ffi/autopointer.rb +9 -8
- data/lib/ffi/enum.rb +2 -1
- data/lib/ffi/library.rb +6 -2
- data/lib/ffi/managedstruct.rb +37 -37
- data/lib/ffi/platform.rb +6 -1
- data/lib/ffi/struct.rb +74 -1
- data/lib/ffi/struct_layout_builder.rb +50 -1
- data/lib/ffi/tools/generator.rb +2 -0
- data/lib/ffi/tools/generator_task.rb +1 -0
- data/lib/ffi/tools/types_generator.rb +2 -0
- data/lib/ffi.rb +12 -1
- data/libtest/Benchmark.c +52 -0
- data/libtest/BoolTest.c +31 -0
- data/libtest/BufferTest.c +31 -0
- data/libtest/ClosureTest.c +190 -0
- data/libtest/EnumTest.c +34 -0
- data/libtest/FunctionTest.c +58 -0
- data/libtest/GNUmakefile +149 -0
- data/libtest/GlobalVariable.c +62 -0
- data/libtest/LastErrorTest.c +21 -0
- data/libtest/NumberTest.c +132 -0
- data/libtest/PointerTest.c +63 -0
- data/libtest/ReferenceTest.c +23 -0
- data/libtest/StringTest.c +34 -0
- data/libtest/StructTest.c +240 -0
- data/libtest/UnionTest.c +43 -0
- data/libtest/VariadicTest.c +62 -0
- data/spec/ffi/Ffi.iml +12 -0
- data/spec/ffi/async_callback_spec.rb +3 -14
- data/spec/ffi/bool_spec.rb +7 -18
- data/spec/ffi/buffer_spec.rb +60 -34
- data/spec/ffi/callback_spec.rb +107 -108
- data/spec/ffi/custom_param_type.rb +2 -13
- data/spec/ffi/custom_type_spec.rb +1 -12
- data/spec/ffi/dup_spec.rb +7 -18
- data/spec/ffi/enum_spec.rb +132 -139
- data/spec/ffi/errno_spec.rb +2 -13
- data/spec/ffi/ffi_spec.rb +4 -15
- data/spec/ffi/function_spec.rb +6 -17
- data/spec/ffi/library_spec.rb +26 -26
- data/spec/ffi/long_double.rb +1 -12
- data/spec/ffi/managed_struct_spec.rb +3 -18
- data/spec/ffi/number_spec.rb +32 -43
- data/spec/ffi/pointer_spec.rb +24 -22
- data/spec/ffi/rbx/memory_pointer_spec.rb +21 -17
- data/spec/ffi/rbx/struct_spec.rb +2 -2
- data/spec/ffi/spec_helper.rb +10 -12
- data/spec/ffi/string_spec.rb +9 -20
- data/spec/ffi/strptr_spec.rb +2 -13
- data/spec/ffi/struct_callback_spec.rb +3 -14
- data/spec/ffi/struct_initialize_spec.rb +3 -14
- data/spec/ffi/struct_packed_spec.rb +7 -18
- data/spec/ffi/struct_spec.rb +129 -100
- data/spec/ffi/typedef_spec.rb +5 -16
- data/spec/ffi/union_spec.rb +4 -15
- data/spec/ffi/variadic_spec.rb +7 -18
- metadata +167 -136
- data/README.rdoc +0 -102
- data/lib/ffi_c.bundle +0 -0
- data/tasks/ann.rake +0 -80
- data/tasks/extension.rake +0 -32
- data/tasks/gem.rake +0 -199
- data/tasks/git.rake +0 -41
- data/tasks/notes.rake +0 -27
- data/tasks/post_load.rake +0 -34
- data/tasks/rdoc.rake +0 -50
- data/tasks/rubyforge.rake +0 -55
- data/tasks/setup.rb +0 -301
- data/tasks/spec.rake +0 -54
- data/tasks/svn.rake +0 -47
- data/tasks/test.rake +0 -40
- data/tasks/yard.rake +0 -11
data/COPYING.LESSER
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
data/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# ruby-ffi http://wiki.github.com/ffi/ffi
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
Ruby-FFI is a ruby extension for programmatically loading dynamic
|
|
6
|
+
libraries, binding functions within them, and calling those functions
|
|
7
|
+
from Ruby code. Moreover, a Ruby-FFI extension works without changes
|
|
8
|
+
on Ruby and JRuby. Discover why should you write your next extension
|
|
9
|
+
using Ruby-FFI [here](http://wiki.github.com/ffi/ffi/why-use-ffi).
|
|
10
|
+
|
|
11
|
+
## Features/problems
|
|
12
|
+
|
|
13
|
+
* Intuitive DSL
|
|
14
|
+
* Supports all C native types
|
|
15
|
+
* C structs (also nested), enums and global variables
|
|
16
|
+
* Callbacks from C to ruby
|
|
17
|
+
* Automatic garbage collection of native memory
|
|
18
|
+
|
|
19
|
+
## Synopsis
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
require 'ffi'
|
|
23
|
+
|
|
24
|
+
module MyLib
|
|
25
|
+
extend FFI::Library
|
|
26
|
+
ffi_lib 'c'
|
|
27
|
+
attach_function :puts, [ :string ], :int
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
MyLib.puts 'Hello, World using libc!'
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
For less minimalistic and more sane examples you may look at:
|
|
34
|
+
|
|
35
|
+
* the samples/ folder
|
|
36
|
+
* the examples on the [wiki](http://wiki.github.com/ffi/ffi)
|
|
37
|
+
* the projects using FFI listed on this page (http://wiki.github.com/ffi/ffi/projects-using-ffi)
|
|
38
|
+
|
|
39
|
+
## Requirements
|
|
40
|
+
|
|
41
|
+
You need a sane building environment in order to compile the extension.
|
|
42
|
+
At a minimum, you will need:
|
|
43
|
+
* A C compiler (e.g. Xcode on OSX, gcc on everything else)
|
|
44
|
+
* libffi development library - this is commonly in the libffi-dev or libffi-devel
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
From rubygems:
|
|
49
|
+
|
|
50
|
+
[sudo] gem install ffi
|
|
51
|
+
|
|
52
|
+
or from the git repository on github:
|
|
53
|
+
|
|
54
|
+
git clone git://github.com/ffi/ffi.git
|
|
55
|
+
cd ffi
|
|
56
|
+
rake gem:install
|
|
57
|
+
|
|
58
|
+
## License
|
|
59
|
+
|
|
60
|
+
The ffi library is covered by the LGPL3 license, also see the LICENSE file.
|
|
61
|
+
The specs are shared with Rubyspec and are licensed by the same license
|
|
62
|
+
as Rubyspec, see the LICENSE.SPECS file.
|
|
63
|
+
|
|
64
|
+
## Credits
|
|
65
|
+
|
|
66
|
+
The following people have submitted code, bug reports, or otherwide contributed to the success of this project:
|
|
67
|
+
|
|
68
|
+
* Alban Peignier <alban.peignier@free.fr>
|
|
69
|
+
* Aman Gupta <aman@tmm1.net>
|
|
70
|
+
* Andrea Fazzi <andrea.fazzi@alcacoop.it>
|
|
71
|
+
* Andreas Niederl <rico32@gmx.net>
|
|
72
|
+
* Andrew Cholakian <andrew@andrewvc.com>
|
|
73
|
+
* Antonio Terceiro <terceiro@softwarelivre.org>
|
|
74
|
+
* Brian Candler <B.Candler@pobox.com>
|
|
75
|
+
* Brian D. Burns <burns180@gmail.com>
|
|
76
|
+
* Bryan Kearney <bkearney@redhat.com>
|
|
77
|
+
* Charlie Savage <cfis@zerista.com>
|
|
78
|
+
* Chikanaga Tomoyuki <nagachika00@gmail.com>
|
|
79
|
+
* Hongli Lai <hongli@phusion.nl>
|
|
80
|
+
* Ian MacLeod <ian@nevir.net>
|
|
81
|
+
* Jake Douglas <jake@shiftedlabs.com>
|
|
82
|
+
* Jean-Dominique Morani <jdmorani@mac.com>
|
|
83
|
+
* Jeremy Hinegardner <jeremy@hinegardner.org>
|
|
84
|
+
* Jesús García Sáez <blaxter@gmail.com>
|
|
85
|
+
* Joe Khoobyar <joe@ankhcraft.com>
|
|
86
|
+
* Jurij Smakov <jurij@wooyd.org>
|
|
87
|
+
* KISHIMOTO, Makoto <ksmakoto@dd.iij4u.or.jp>
|
|
88
|
+
* Kim Burgestrand <kim@burgestrand.se>
|
|
89
|
+
* Lars Kanis <kanis@comcard.de>
|
|
90
|
+
* Luc Heinrich <luc@honk-honk.com>
|
|
91
|
+
* Luis Lavena <luislavena@gmail.com>
|
|
92
|
+
* Matijs van Zuijlen <matijs@matijs.net>
|
|
93
|
+
* Matthew King <automatthew@gmail.com>
|
|
94
|
+
* Mike Dalessio <mike.dalessio@gmail.com>
|
|
95
|
+
* NARUSE, Yui <naruse@airemix.jp>
|
|
96
|
+
* Park Heesob <phasis@gmail.com>
|
|
97
|
+
* Shin Yee <shinyee@speedgocomputing.com>
|
|
98
|
+
* Stephen Bannasch <stephen.bannasch@gmail.com>
|
|
99
|
+
* Suraj N. Kurapati <sunaku@gmail.com>
|
|
100
|
+
* Sylvain Daubert <sylvain.daubert@laposte.net>
|
|
101
|
+
* Victor Costan
|
|
102
|
+
* beoran@gmail.com
|
|
103
|
+
* ctide <christide@christide.com>
|
|
104
|
+
* emboss <Martin.Bosslet@googlemail.com>
|
|
105
|
+
* hobophobe <unusualtears@gmail.com>
|
|
106
|
+
* meh <meh@paranoici.org>
|
|
107
|
+
* postmodern <postmodern.mod3@gmail.com>
|
|
108
|
+
* wycats@gmail.com <wycats@gmail.com>
|
|
109
|
+
* Wayne Meissner <wmeissner@gmail.com>
|
data/Rakefile
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'rubygems'
|
|
2
|
+
require 'rubygems/package_task'
|
|
2
3
|
require 'rbconfig'
|
|
3
4
|
|
|
4
5
|
USE_RAKE_COMPILER = (RUBY_PLATFORM =~ /java/) ? false : true
|
|
@@ -11,7 +12,6 @@ require 'date'
|
|
|
11
12
|
require 'fileutils'
|
|
12
13
|
require 'rbconfig'
|
|
13
14
|
|
|
14
|
-
load 'tasks/setup.rb'
|
|
15
15
|
|
|
16
16
|
LIBEXT = case RbConfig::CONFIG['host_os'].downcase
|
|
17
17
|
when /darwin/
|
|
@@ -40,6 +40,9 @@ CPU = case RbConfig::CONFIG['host_cpu'].downcase
|
|
|
40
40
|
when /ppc|powerpc/
|
|
41
41
|
"powerpc"
|
|
42
42
|
|
|
43
|
+
when /^arm/
|
|
44
|
+
"arm"
|
|
45
|
+
|
|
43
46
|
else
|
|
44
47
|
RbConfig::CONFIG['host_cpu']
|
|
45
48
|
end
|
|
@@ -61,7 +64,7 @@ OS = case RbConfig::CONFIG['host_os'].downcase
|
|
|
61
64
|
RbConfig::CONFIG['host_os'].downcase
|
|
62
65
|
end
|
|
63
66
|
|
|
64
|
-
CC=ENV['CC'] || RbConfig::CONFIG['CC'] || "gcc"
|
|
67
|
+
CC = ENV['CC'] || RbConfig::CONFIG['CC'] || "gcc"
|
|
65
68
|
|
|
66
69
|
GMAKE = system('which gmake >/dev/null') && 'gmake' || 'make'
|
|
67
70
|
|
|
@@ -69,47 +72,15 @@ LIBTEST = "build/libtest.#{LIBEXT}"
|
|
|
69
72
|
BUILD_DIR = "build"
|
|
70
73
|
BUILD_EXT_DIR = File.join(BUILD_DIR, "#{RbConfig::CONFIG['arch']}", 'ffi_c', RUBY_VERSION)
|
|
71
74
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
PROJ.email = 'wmeissner@gmail.com'
|
|
76
|
-
PROJ.url = 'http://wiki.github.com/ffi/ffi'
|
|
77
|
-
PROJ.version = '1.1.1.rc1'
|
|
78
|
-
PROJ.rubyforge.name = 'ffi'
|
|
79
|
-
PROJ.readme_file = 'README.rdoc'
|
|
80
|
-
|
|
81
|
-
# Annoucement
|
|
82
|
-
PROJ.ann.paragraphs << 'FEATURES' << 'SYNOPSIS' << 'REQUIREMENTS' << 'DOWNLOAD/INSTALL' << 'CREDITS' << 'LICENSE'
|
|
83
|
-
|
|
84
|
-
PROJ.ann.email[:from] = 'andrea.fazzi@alcacoop.it'
|
|
85
|
-
PROJ.ann.email[:to] = ['ruby-ffi@googlegroups.com']
|
|
86
|
-
PROJ.ann.email[:server] = 'smtp.gmail.com'
|
|
87
|
-
|
|
88
|
-
# Gem specifications
|
|
89
|
-
PROJ.gem.need_tar = false
|
|
90
|
-
PROJ.gem.files = %w(History.txt LICENSE README.rdoc Rakefile) + Dir.glob("{ext,gen,lib,spec,tasks}/**/*")
|
|
91
|
-
PROJ.gem.platform = Gem::Platform::RUBY
|
|
92
|
-
#PROJ.gem.required_ruby_version = ">= 1.9.2"
|
|
93
|
-
|
|
94
|
-
# Override Mr. Bones autogenerated extensions and force ours in
|
|
95
|
-
PROJ.gem.extras['extensions'] = %w(ext/ffi_c/extconf.rb)
|
|
96
|
-
#PROJ.gem.extras['required_ruby_version'] = ">= 1.9.2"
|
|
97
|
-
|
|
98
|
-
# RDoc
|
|
99
|
-
PROJ.rdoc.exclude << '^ext\/'
|
|
100
|
-
PROJ.rdoc.opts << '-x' << 'ext'
|
|
101
|
-
|
|
102
|
-
# Ruby
|
|
103
|
-
PROJ.ruby_opts = []
|
|
104
|
-
PROJ.ruby_opts << '-I' << BUILD_EXT_DIR unless RUBY_PLATFORM == "java"
|
|
105
|
-
|
|
106
|
-
# RSpec
|
|
107
|
-
PROJ.spec.files.exclude /rbx/
|
|
108
|
-
PROJ.spec.opts << '--color' << '-fs'
|
|
109
|
-
|
|
110
|
-
# Dependencies
|
|
75
|
+
def gem_spec
|
|
76
|
+
@gem_spec ||= Gem::Specification.load('ffi.gemspec')
|
|
77
|
+
end
|
|
111
78
|
|
|
112
|
-
|
|
79
|
+
Gem::PackageTask.new(gem_spec) do |pkg|
|
|
80
|
+
pkg.need_zip = true
|
|
81
|
+
pkg.need_tar = true
|
|
82
|
+
pkg.package_dir = 'pkg'
|
|
83
|
+
end
|
|
113
84
|
|
|
114
85
|
TEST_DEPS = [ LIBTEST ]
|
|
115
86
|
if RUBY_PLATFORM == "java"
|
|
@@ -141,6 +112,11 @@ task :package => 'gem:package'
|
|
|
141
112
|
desc "Install the gem locally"
|
|
142
113
|
task :install => 'gem:install'
|
|
143
114
|
|
|
115
|
+
namespace :gem do
|
|
116
|
+
task :install => :gem do
|
|
117
|
+
ruby %{ -S gem install pkg/ffi-#{gem_spec.version}.gem }
|
|
118
|
+
end
|
|
119
|
+
end
|
|
144
120
|
|
|
145
121
|
desc "Clean all built files"
|
|
146
122
|
task :distclean => :clobber do
|
|
@@ -155,7 +131,7 @@ end
|
|
|
155
131
|
|
|
156
132
|
|
|
157
133
|
desc "Build the native test lib"
|
|
158
|
-
|
|
134
|
+
file "build/libtest.#{LIBEXT}" => FileList['libtest/**/*.[ch]'] do
|
|
159
135
|
sh %{#{GMAKE} -f libtest/GNUmakefile CPU=#{CPU} OS=#{OS} }
|
|
160
136
|
end
|
|
161
137
|
|
|
@@ -191,3 +167,51 @@ task :default => :specs
|
|
|
191
167
|
task 'gem:win32' do
|
|
192
168
|
sh("rake cross native gem RUBY_CC_VERSION='1.8.7:1.9.3'") || raise("win32 build failed!")
|
|
193
169
|
end
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
namespace 'java' do
|
|
173
|
+
|
|
174
|
+
java_gem_spec = Gem::Specification.new do |s|
|
|
175
|
+
s.name = gem_spec.name
|
|
176
|
+
s.version = gem_spec.version
|
|
177
|
+
s.author = gem_spec.author
|
|
178
|
+
s.email = gem_spec.email
|
|
179
|
+
s.homepage = gem_spec.homepage
|
|
180
|
+
s.summary = gem_spec.summary
|
|
181
|
+
s.description = gem_spec.description
|
|
182
|
+
s.files = %w(History.txt LICENSE COPYING COPYING.LESSER README.md Rakefile)
|
|
183
|
+
s.has_rdoc = false
|
|
184
|
+
s.license = gem_spec.license
|
|
185
|
+
s.platform = 'java'
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
Gem::PackageTask.new(java_gem_spec) do |pkg|
|
|
189
|
+
pkg.need_zip = true
|
|
190
|
+
pkg.need_tar = true
|
|
191
|
+
pkg.package_dir = 'pkg'
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
task 'gem:java' => 'java:gem'
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
if USE_RAKE_COMPILER
|
|
199
|
+
Rake::ExtensionTask.new('ffi_c', gem_spec) do |ext|
|
|
200
|
+
ext.name = 'ffi_c' # indicate the name of the extension.
|
|
201
|
+
# ext.lib_dir = BUILD_DIR # put binaries into this folder.
|
|
202
|
+
ext.tmp_dir = BUILD_DIR # temporary folder used during compilation.
|
|
203
|
+
ext.cross_compile = true # enable cross compilation (requires cross compile toolchain)
|
|
204
|
+
ext.cross_platform = 'i386-mingw32' # forces the Windows platform instead of the default one
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
begin
|
|
209
|
+
require 'yard'
|
|
210
|
+
|
|
211
|
+
namespace :doc do
|
|
212
|
+
YARD::Rake::YardocTask.new do |yard|
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
rescue LoadError
|
|
216
|
+
warn "[warn] YARD unavailable"
|
|
217
|
+
end
|
data/ext/ffi_c/AbstractMemory.c
CHANGED
|
@@ -431,11 +431,6 @@ memory_put_string(VALUE self, VALUE offset, VALUE str)
|
|
|
431
431
|
|
|
432
432
|
checkWrite(ptr);
|
|
433
433
|
checkBounds(ptr, off, len + 1);
|
|
434
|
-
|
|
435
|
-
if (rb_safe_level() >= 1 && OBJ_TAINTED(str)) {
|
|
436
|
-
rb_raise(rb_eSecurityError, "Writing unsafe string to memory");
|
|
437
|
-
return Qnil;
|
|
438
|
-
}
|
|
439
434
|
|
|
440
435
|
memcpy(ptr->address + off, RSTRING_PTR(str), len);
|
|
441
436
|
*((char *) ptr->address + off + len) = '\0';
|
|
@@ -651,25 +646,24 @@ memory_op_put_strptr(AbstractMemory* ptr, long offset, VALUE value)
|
|
|
651
646
|
|
|
652
647
|
static MemoryOp memory_op_strptr = { memory_op_get_strptr, memory_op_put_strptr };
|
|
653
648
|
|
|
654
|
-
//static MemoryOp memory_op_pointer = { memory_op_get_pointer, memory_op_put_pointer };
|
|
655
649
|
|
|
656
650
|
MemoryOps rbffi_AbstractMemoryOps = {
|
|
657
|
-
&memory_op_int8,
|
|
658
|
-
&memory_op_uint8,
|
|
659
|
-
&memory_op_int16,
|
|
660
|
-
&memory_op_uint16,
|
|
661
|
-
&memory_op_int32,
|
|
662
|
-
&memory_op_uint32,
|
|
663
|
-
&memory_op_int64,
|
|
664
|
-
&memory_op_uint64,
|
|
665
|
-
&memory_op_long,
|
|
666
|
-
&memory_op_ulong,
|
|
667
|
-
&memory_op_float32,
|
|
668
|
-
&memory_op_float64,
|
|
669
|
-
&memory_op_longdouble,
|
|
670
|
-
&memory_op_pointer,
|
|
671
|
-
&memory_op_strptr,
|
|
672
|
-
&memory_op_bool
|
|
651
|
+
&memory_op_int8, /*.int8 */
|
|
652
|
+
&memory_op_uint8, /* .uint8 */
|
|
653
|
+
&memory_op_int16, /* .int16 */
|
|
654
|
+
&memory_op_uint16, /* .uint16 */
|
|
655
|
+
&memory_op_int32, /* .int32 */
|
|
656
|
+
&memory_op_uint32, /* .uint32 */
|
|
657
|
+
&memory_op_int64, /* .int64 */
|
|
658
|
+
&memory_op_uint64, /* .uint64 */
|
|
659
|
+
&memory_op_long, /* .slong */
|
|
660
|
+
&memory_op_ulong, /* .uslong */
|
|
661
|
+
&memory_op_float32, /* .float32 */
|
|
662
|
+
&memory_op_float64, /* .float64 */
|
|
663
|
+
&memory_op_longdouble, /* .longdouble */
|
|
664
|
+
&memory_op_pointer, /* .pointer */
|
|
665
|
+
&memory_op_strptr, /* .strptr */
|
|
666
|
+
&memory_op_bool /* .boolOp */
|
|
673
667
|
};
|
|
674
668
|
|
|
675
669
|
void
|
data/ext/ffi_c/AbstractMemory.h
CHANGED
|
@@ -70,7 +70,7 @@ typedef struct {
|
|
|
70
70
|
} MemoryOps;
|
|
71
71
|
|
|
72
72
|
struct AbstractMemory_ {
|
|
73
|
-
char* address;
|
|
73
|
+
char* address; /* Use char* instead of void* to ensure adding to it works correctly */
|
|
74
74
|
long size;
|
|
75
75
|
int flags;
|
|
76
76
|
int typeSize;
|
data/ext/ffi_c/ArrayType.c
CHANGED
|
@@ -126,12 +126,16 @@ array_type_element_type(VALUE self)
|
|
|
126
126
|
void
|
|
127
127
|
rbffi_ArrayType_Init(VALUE moduleFFI)
|
|
128
128
|
{
|
|
129
|
+
VALUE ffi_Type;
|
|
130
|
+
|
|
131
|
+
ffi_Type = rbffi_TypeClass;
|
|
132
|
+
|
|
129
133
|
/*
|
|
130
134
|
* Document-class: FFI::ArrayType < FFI::Type
|
|
131
135
|
*
|
|
132
136
|
* This is a typed array. The type is a {NativeType native type}.
|
|
133
137
|
*/
|
|
134
|
-
rbffi_ArrayTypeClass = rb_define_class_under(moduleFFI, "ArrayType",
|
|
138
|
+
rbffi_ArrayTypeClass = rb_define_class_under(moduleFFI, "ArrayType", ffi_Type);
|
|
135
139
|
/*
|
|
136
140
|
* Document-variable: FFI::ArrayType
|
|
137
141
|
*/
|
|
@@ -139,7 +143,7 @@ rbffi_ArrayType_Init(VALUE moduleFFI)
|
|
|
139
143
|
/*
|
|
140
144
|
* Document-constant: FFI::Type::Array
|
|
141
145
|
*/
|
|
142
|
-
rb_define_const(
|
|
146
|
+
rb_define_const(ffi_Type, "Array", rbffi_ArrayTypeClass);
|
|
143
147
|
|
|
144
148
|
rb_define_alloc_func(rbffi_ArrayTypeClass, array_type_s_allocate);
|
|
145
149
|
rb_define_method(rbffi_ArrayTypeClass, "initialize", array_type_initialize, 2);
|
data/ext/ffi_c/Buffer.c
CHANGED
|
@@ -41,7 +41,7 @@ typedef struct Buffer {
|
|
|
41
41
|
union {
|
|
42
42
|
VALUE rbParent; /* link to parent buffer */
|
|
43
43
|
char* storage; /* start of malloc area */
|
|
44
|
-
long embed[BUFFER_EMBED_MAXLEN / sizeof(long)];
|
|
44
|
+
long embed[BUFFER_EMBED_MAXLEN / sizeof(long)]; /* storage for tiny allocations */
|
|
45
45
|
} data;
|
|
46
46
|
} Buffer;
|
|
47
47
|
|
|
@@ -151,7 +151,7 @@ buffer_initialize_copy(VALUE self, VALUE other)
|
|
|
151
151
|
dst->memory.size = src->size;
|
|
152
152
|
dst->memory.typeSize = src->typeSize;
|
|
153
153
|
|
|
154
|
-
|
|
154
|
+
/* finally, copy the actual buffer contents */
|
|
155
155
|
memcpy(dst->memory.address, src->address, src->size);
|
|
156
156
|
|
|
157
157
|
return self;
|
|
@@ -310,12 +310,14 @@ buffer_mark(Buffer* ptr)
|
|
|
310
310
|
void
|
|
311
311
|
rbffi_Buffer_Init(VALUE moduleFFI)
|
|
312
312
|
{
|
|
313
|
+
VALUE ffi_AbstractMemory = rbffi_AbstractMemoryClass;
|
|
314
|
+
|
|
313
315
|
/*
|
|
314
316
|
* Document-class: FFI::Buffer < FFI::AbstractMemory
|
|
315
317
|
*
|
|
316
318
|
* A Buffer is a function argument type. It should be use with functions playing with C arrays.
|
|
317
319
|
*/
|
|
318
|
-
BufferClass = rb_define_class_under(moduleFFI, "Buffer",
|
|
320
|
+
BufferClass = rb_define_class_under(moduleFFI, "Buffer", ffi_AbstractMemory);
|
|
319
321
|
|
|
320
322
|
/*
|
|
321
323
|
* Document-variable: FFI::Buffer
|
data/ext/ffi_c/Call.c
CHANGED
|
@@ -79,7 +79,6 @@ typedef int bool;
|
|
|
79
79
|
|
|
80
80
|
static void* callback_param(VALUE proc, VALUE cbinfo);
|
|
81
81
|
static inline void* getPointer(VALUE value, int type);
|
|
82
|
-
static inline char* getString(VALUE value, int type);
|
|
83
82
|
|
|
84
83
|
static ID id_to_ptr, id_map_symbol, id_to_native;
|
|
85
84
|
|
|
@@ -221,7 +220,18 @@ rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes,
|
|
|
221
220
|
|
|
222
221
|
|
|
223
222
|
case NATIVE_STRING:
|
|
224
|
-
|
|
223
|
+
if (type == T_NIL) {
|
|
224
|
+
param->ptr = NULL;
|
|
225
|
+
|
|
226
|
+
} else {
|
|
227
|
+
if (rb_safe_level() >= 1 && OBJ_TAINTED(argv[argidx])) {
|
|
228
|
+
rb_raise(rb_eSecurityError, "Unsafe string parameter");
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
param->ptr = StringValueCStr(argv[argidx]);
|
|
232
|
+
++argidx;
|
|
233
|
+
}
|
|
234
|
+
|
|
225
235
|
ADJ(param, ADDRESS);
|
|
226
236
|
break;
|
|
227
237
|
|
|
@@ -314,8 +324,10 @@ rbffi_CallFunction(int argc, VALUE* argv, void* function, FunctionType* fnInfo)
|
|
|
314
324
|
if (unlikely(fnInfo->blocking)) {
|
|
315
325
|
BlockingCall* bc;
|
|
316
326
|
|
|
317
|
-
|
|
318
|
-
|
|
327
|
+
/*
|
|
328
|
+
* due to the way thread switching works on older ruby variants, we
|
|
329
|
+
* cannot allocate anything passed to the blocking function on the stack
|
|
330
|
+
*/
|
|
319
331
|
ffiValues = ALLOC_N(void *, fnInfo->parameterCount);
|
|
320
332
|
params = ALLOC_N(FFIStorage, fnInfo->parameterCount);
|
|
321
333
|
bc = ALLOC_N(BlockingCall, 1);
|
|
@@ -375,10 +387,7 @@ getPointer(VALUE value, int type)
|
|
|
375
387
|
return memory != NULL ? memory->address : NULL;
|
|
376
388
|
|
|
377
389
|
} else if (type == T_STRING) {
|
|
378
|
-
|
|
379
|
-
if (rb_safe_level() >= 1 && OBJ_TAINTED(value)) {
|
|
380
|
-
rb_raise(rb_eSecurityError, "Unsafe string parameter");
|
|
381
|
-
}
|
|
390
|
+
|
|
382
391
|
return StringValuePtr(value);
|
|
383
392
|
|
|
384
393
|
} else if (type == T_NIL) {
|
|
@@ -398,25 +407,6 @@ getPointer(VALUE value, int type)
|
|
|
398
407
|
return NULL;
|
|
399
408
|
}
|
|
400
409
|
|
|
401
|
-
static inline char*
|
|
402
|
-
getString(VALUE value, int type)
|
|
403
|
-
{
|
|
404
|
-
if (type == T_STRING) {
|
|
405
|
-
|
|
406
|
-
if (rb_safe_level() >= 1 && OBJ_TAINTED(value)) {
|
|
407
|
-
rb_raise(rb_eSecurityError, "Unsafe string parameter");
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
return StringValueCStr(value);
|
|
411
|
-
|
|
412
|
-
} else if (type == T_NIL) {
|
|
413
|
-
return NULL;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
rb_raise(rb_eArgError, "Invalid String value");
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
|
|
420
410
|
Invoker
|
|
421
411
|
rbffi_GetInvoker(FunctionType *fnInfo)
|
|
422
412
|
{
|
|
@@ -432,14 +422,13 @@ callback_param(VALUE proc, VALUE cbInfo)
|
|
|
432
422
|
return NULL ;
|
|
433
423
|
}
|
|
434
424
|
|
|
435
|
-
|
|
425
|
+
/* Handle Function pointers here */
|
|
436
426
|
if (rb_obj_is_kind_of(proc, rbffi_FunctionClass)) {
|
|
437
427
|
AbstractMemory* ptr;
|
|
438
428
|
Data_Get_Struct(proc, AbstractMemory, ptr);
|
|
439
429
|
return ptr->address;
|
|
440
430
|
}
|
|
441
431
|
|
|
442
|
-
//callback = rbffi_NativeCallback_ForProc(proc, cbInfo);
|
|
443
432
|
callback = rbffi_Function_ForProc(cbInfo, proc);
|
|
444
433
|
RB_GC_GUARD(callback);
|
|
445
434
|
|
data/ext/ffi_c/ClosurePool.c
CHANGED
|
@@ -206,7 +206,7 @@ rbffi_Closure_Free(Closure* closure)
|
|
|
206
206
|
if (closure != NULL) {
|
|
207
207
|
ClosurePool* pool = closure->pool;
|
|
208
208
|
long refcnt;
|
|
209
|
-
|
|
209
|
+
/* Just push it on the front of the free list */
|
|
210
210
|
closure->next = pool->list;
|
|
211
211
|
pool->list = closure;
|
|
212
212
|
refcnt = --(pool->refcnt);
|
data/ext/ffi_c/DynamicLibrary.c
CHANGED
|
@@ -155,7 +155,7 @@ library_dlerror(VALUE self)
|
|
|
155
155
|
static void
|
|
156
156
|
library_free(Library* library)
|
|
157
157
|
{
|
|
158
|
-
|
|
158
|
+
/* dlclose() on MacOS tends to segfault - avoid it */
|
|
159
159
|
#ifndef __APPLE__
|
|
160
160
|
if (library->handle != NULL) {
|
|
161
161
|
dl_close(library->handle);
|
|
@@ -270,7 +270,7 @@ rbffi_DynamicLibrary_Init(VALUE moduleFFI)
|
|
|
270
270
|
* Document-const: FFI::NativeLibrary
|
|
271
271
|
* Backward compatibility for FFI::DynamicLibrary
|
|
272
272
|
*/
|
|
273
|
-
rb_define_const(moduleFFI, "NativeLibrary", LibraryClass);
|
|
273
|
+
rb_define_const(moduleFFI, "NativeLibrary", LibraryClass); /* backwards compat library */
|
|
274
274
|
rb_define_alloc_func(LibraryClass, library_allocate);
|
|
275
275
|
rb_define_singleton_method(LibraryClass, "open", library_open, 2);
|
|
276
276
|
rb_define_singleton_method(LibraryClass, "last_error", library_dlerror, 0);
|