ffi 0.6.3 → 0.6.4
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/README.md +109 -0
- data/Rakefile +84 -56
- data/ext/ffi_c/Ffi_c.iml +12 -0
- data/ext/ffi_c/StructLayout.c +2 -1
- data/ffi.gemspec +18 -0
- data/gen/log +1 -0
- data/lib/Lib.iml +21 -0
- data/lib/ffi/platform.rb +5 -3
- data/libtest/Benchmark.c +73 -0
- data/libtest/BoolTest.c +52 -0
- data/libtest/BufferTest.c +52 -0
- data/libtest/ClosureTest.c +173 -0
- data/libtest/EnumTest.c +55 -0
- data/libtest/FunctionTest.c +50 -0
- data/libtest/GNUmakefile +141 -0
- data/libtest/GlobalVariable.c +56 -0
- data/libtest/LastErrorTest.c +41 -0
- data/libtest/NumberTest.c +145 -0
- data/libtest/PointerTest.c +84 -0
- data/libtest/ReferenceTest.c +44 -0
- data/libtest/StringTest.c +55 -0
- data/libtest/StructTest.c +247 -0
- data/libtest/UnionTest.c +64 -0
- data/libtest/VariadicTest.c +57 -0
- data/spec/ffi/Ffi.iml +12 -0
- metadata +137 -106
- data/README.rdoc +0 -69
- data/tasks/ann.rake +0 -80
- data/tasks/extension.rake +0 -25
- data/tasks/gem.rake +0 -200
- 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 -300
- data/tasks/spec.rake +0 -54
- data/tasks/svn.rake +0 -47
- data/tasks/test.rake +0 -40
data/README.md
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# ruby-ffi http://wiki.github.com/ffi/ffi [![Build Status](https://travis-ci.org/ffi/ffi.png?branch=master)](https://travis-ci.org/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,32 +1,31 @@
|
|
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
|
5
6
|
if USE_RAKE_COMPILER
|
6
7
|
gem 'rake-compiler', '>=0.6.0'
|
7
8
|
require 'rake/extensiontask'
|
8
|
-
ENV['RUBY_CC_VERSION'] = '1.8.6:1.9.1'
|
9
9
|
end
|
10
10
|
|
11
11
|
require 'date'
|
12
12
|
require 'fileutils'
|
13
13
|
require 'rbconfig'
|
14
14
|
|
15
|
-
load 'tasks/setup.rb'
|
16
15
|
|
17
|
-
LIBEXT = case
|
16
|
+
LIBEXT = case RbConfig::CONFIG['host_os'].downcase
|
18
17
|
when /darwin/
|
19
18
|
"dylib"
|
20
19
|
when /mswin|mingw/
|
21
20
|
"dll"
|
22
21
|
else
|
23
|
-
|
22
|
+
RbConfig::CONFIG['DLEXT']
|
24
23
|
end
|
25
24
|
|
26
|
-
CPU = case
|
25
|
+
CPU = case RbConfig::CONFIG['host_cpu'].downcase
|
27
26
|
when /i[3456]86/
|
28
27
|
# Darwin always reports i686, even when running in 64bit mode
|
29
|
-
if
|
28
|
+
if RbConfig::CONFIG['host_os'] =~ /darwin/ && 0xfee1deadbeef.is_a?(Fixnum)
|
30
29
|
"x86_64"
|
31
30
|
else
|
32
31
|
"i386"
|
@@ -41,11 +40,14 @@ CPU = case Config::CONFIG['host_cpu'].downcase
|
|
41
40
|
when /ppc|powerpc/
|
42
41
|
"powerpc"
|
43
42
|
|
43
|
+
when /^arm/
|
44
|
+
"arm"
|
45
|
+
|
44
46
|
else
|
45
|
-
|
47
|
+
RbConfig::CONFIG['host_cpu']
|
46
48
|
end
|
47
49
|
|
48
|
-
OS = case
|
50
|
+
OS = case RbConfig::CONFIG['host_os'].downcase
|
49
51
|
when /linux/
|
50
52
|
"linux"
|
51
53
|
when /darwin/
|
@@ -59,78 +61,48 @@ OS = case Config::CONFIG['host_os'].downcase
|
|
59
61
|
when /mswin|mingw/
|
60
62
|
"win32"
|
61
63
|
else
|
62
|
-
|
64
|
+
RbConfig::CONFIG['host_os'].downcase
|
63
65
|
end
|
64
66
|
|
65
|
-
CC=ENV['CC'] ||
|
67
|
+
CC = ENV['CC'] || RbConfig::CONFIG['CC'] || "gcc"
|
66
68
|
|
67
|
-
GMAKE =
|
69
|
+
GMAKE = system('which gmake >/dev/null') && 'gmake' || 'make'
|
68
70
|
|
69
71
|
LIBTEST = "build/libtest.#{LIBEXT}"
|
70
72
|
BUILD_DIR = "build"
|
71
|
-
BUILD_EXT_DIR = File.join(BUILD_DIR, "#{
|
72
|
-
|
73
|
-
# Project general information
|
74
|
-
PROJ.name = 'ffi'
|
75
|
-
PROJ.authors = 'Wayne Meissner'
|
76
|
-
PROJ.email = 'wmeissner@gmail.com'
|
77
|
-
PROJ.url = 'http://wiki.github.com/ffi/ffi'
|
78
|
-
PROJ.version = '0.6.3'
|
79
|
-
PROJ.rubyforge.name = 'ffi'
|
80
|
-
PROJ.readme_file = 'README.rdoc'
|
81
|
-
|
82
|
-
# Annoucement
|
83
|
-
PROJ.ann.paragraphs << 'FEATURES' << 'SYNOPSIS' << 'REQUIREMENTS' << 'DOWNLOAD/INSTALL' << 'CREDITS' << 'LICENSE'
|
84
|
-
|
85
|
-
PROJ.ann.email[:from] = 'andrea.fazzi@alcacoop.it'
|
86
|
-
PROJ.ann.email[:to] = ['ruby-ffi@googlegroups.com']
|
87
|
-
PROJ.ann.email[:server] = 'smtp.gmail.com'
|
88
|
-
|
89
|
-
# Gem specifications
|
90
|
-
PROJ.gem.need_tar = false
|
91
|
-
PROJ.gem.files = %w(History.txt LICENSE README.rdoc Rakefile) + Dir.glob("{ext,gen,lib,spec,tasks}/**/*")
|
92
|
-
PROJ.gem.platform = Gem::Platform::RUBY
|
93
|
-
|
94
|
-
# Override Mr. Bones autogenerated extensions and force ours in
|
95
|
-
PROJ.gem.extras['extensions'] = %w(ext/ffi_c/extconf.rb gen/Rakefile)
|
96
|
-
|
97
|
-
# RDoc
|
98
|
-
PROJ.rdoc.exclude << '^ext\/'
|
99
|
-
PROJ.rdoc.opts << '-x' << 'ext'
|
100
|
-
|
101
|
-
# Ruby
|
102
|
-
PROJ.ruby_opts = []
|
103
|
-
PROJ.ruby_opts << '-I' << BUILD_EXT_DIR unless RUBY_PLATFORM == "java"
|
73
|
+
BUILD_EXT_DIR = File.join(BUILD_DIR, "#{RbConfig::CONFIG['arch']}", 'ffi_c', RUBY_VERSION)
|
104
74
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
# Dependencies
|
75
|
+
def gem_spec
|
76
|
+
@gem_spec ||= Gem::Specification.load('ffi.gemspec')
|
77
|
+
end
|
110
78
|
|
111
|
-
|
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
|
112
84
|
|
113
85
|
TEST_DEPS = [ LIBTEST ]
|
114
86
|
if RUBY_PLATFORM == "java"
|
115
87
|
desc "Run all specs"
|
116
88
|
task :specs => TEST_DEPS do
|
117
|
-
sh %{#{Gem.ruby} -S
|
89
|
+
sh %{#{Gem.ruby} -w -S rspec #{Dir["spec/ffi/*_spec.rb"].join(" ")} -fs --color}
|
118
90
|
end
|
119
91
|
desc "Run rubinius specs"
|
120
92
|
task :rbxspecs => TEST_DEPS do
|
121
|
-
sh %{#{Gem.ruby} -S
|
93
|
+
sh %{#{Gem.ruby} -w -S rspec #{Dir["spec/ffi/rbx/*_spec.rb"].join(" ")} -fs --color}
|
122
94
|
end
|
123
95
|
else
|
124
96
|
TEST_DEPS.unshift :compile
|
125
97
|
desc "Run all specs"
|
126
98
|
task :specs => TEST_DEPS do
|
127
99
|
ENV["MRI_FFI"] = "1"
|
128
|
-
sh %{#{Gem.ruby} -Ilib -I#{BUILD_EXT_DIR} -S
|
100
|
+
sh %{#{Gem.ruby} -w -Ilib -I#{BUILD_EXT_DIR} -S rspec #{Dir["spec/ffi/*_spec.rb"].join(" ")} -fs --color}
|
129
101
|
end
|
130
102
|
desc "Run rubinius specs"
|
131
103
|
task :rbxspecs => TEST_DEPS do
|
132
104
|
ENV["MRI_FFI"] = "1"
|
133
|
-
sh %{#{Gem.ruby} -Ilib -I#{BUILD_EXT_DIR} -S
|
105
|
+
sh %{#{Gem.ruby} -w -Ilib -I#{BUILD_EXT_DIR} -S rspec #{Dir["spec/ffi/rbx/*_spec.rb"].join(" ")} -fs --color}
|
134
106
|
end
|
135
107
|
end
|
136
108
|
|
@@ -140,11 +112,16 @@ task :package => 'gem:package'
|
|
140
112
|
desc "Install the gem locally"
|
141
113
|
task :install => 'gem:install'
|
142
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
|
143
120
|
|
144
121
|
desc "Clean all built files"
|
145
122
|
task :distclean => :clobber do
|
146
123
|
FileUtils.rm_rf('build')
|
147
|
-
FileUtils.rm_rf(Dir["lib/**/ffi_c.#{
|
124
|
+
FileUtils.rm_rf(Dir["lib/**/ffi_c.#{RbConfig::CONFIG['DLEXT']}"])
|
148
125
|
FileUtils.rm_rf('lib/1.8')
|
149
126
|
FileUtils.rm_rf('lib/1.9')
|
150
127
|
FileUtils.rm_rf('lib/ffi/types.conf')
|
@@ -154,7 +131,7 @@ end
|
|
154
131
|
|
155
132
|
|
156
133
|
desc "Build the native test lib"
|
157
|
-
|
134
|
+
file "build/libtest.#{LIBEXT}" => FileList['libtest/**/*.[ch]'] do
|
158
135
|
sh %{#{GMAKE} -f libtest/GNUmakefile CPU=#{CPU} OS=#{OS} }
|
159
136
|
end
|
160
137
|
|
@@ -187,3 +164,54 @@ task 'spec:specdoc' => TEST_DEPS
|
|
187
164
|
|
188
165
|
task :default => :specs
|
189
166
|
|
167
|
+
task 'gem:win32' do
|
168
|
+
sh("rake cross native gem RUBY_CC_VERSION='1.8.7:1.9.3'") || raise("win32 build failed!")
|
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/Ffi_c.iml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
4
|
+
<exclude-output />
|
5
|
+
<content url="file://$MODULE_DIR$">
|
6
|
+
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
7
|
+
</content>
|
8
|
+
<orderEntry type="inheritedJdk" />
|
9
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
10
|
+
</component>
|
11
|
+
</module>
|
12
|
+
|
data/ext/ffi_c/StructLayout.c
CHANGED
@@ -360,7 +360,8 @@ struct_layout_initialize(VALUE self, VALUE field_names, VALUE fields, VALUE size
|
|
360
360
|
rb_raise(rb_eTypeError, "wrong type for field %d.", i);
|
361
361
|
}
|
362
362
|
|
363
|
-
|
363
|
+
field = layout->fields[i];
|
364
|
+
Data_Get_Struct(rbField, StructField, field);
|
364
365
|
|
365
366
|
if (field->type == NULL || field->type->ffiType == NULL) {
|
366
367
|
rb_raise(rb_eRuntimeError, "type of field %d not supported", i);
|
data/ffi.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'ffi'
|
3
|
+
s.version = '0.6.4'
|
4
|
+
s.author = 'Wayne Meissner'
|
5
|
+
s.email = 'wmeissner@gmail.com'
|
6
|
+
s.homepage = 'http://wiki.github.com/ffi/ffi'
|
7
|
+
s.summary = 'Ruby FFI'
|
8
|
+
s.description = 'Ruby FFI library'
|
9
|
+
s.files = %w(ffi.gemspec History.txt LICENSE README.md Rakefile) + Dir.glob("{ext,gen,lib,spec,libtest}/**/*").reject { |f| f =~ /lib\/1\.[89]/}
|
10
|
+
s.extensions << 'ext/ffi_c/extconf.rb'
|
11
|
+
s.has_rdoc = false
|
12
|
+
s.license = 'LGPL-3'
|
13
|
+
s.require_paths << 'ext/ffi_c' << 'lib/ffi'
|
14
|
+
s.required_ruby_version = '>= 1.8.7'
|
15
|
+
s.add_development_dependency 'rake'
|
16
|
+
s.add_development_dependency 'rake-compiler', '>=0.6.0'
|
17
|
+
s.add_development_dependency 'rspec'
|
18
|
+
end
|
data/gen/log
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/Users/wayne/src/ruby-ffi/lib/ffi/platform/x86_64-darwin/types.conf
|
data/lib/Lib.iml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="FacetManager">
|
4
|
+
<facet type="gem" name="Gem">
|
5
|
+
<configuration>
|
6
|
+
<option name="GEM_APP_ROOT_PATH" value="" />
|
7
|
+
<option name="GEM_APP_TEST_PATH" value="" />
|
8
|
+
<option name="GEM_APP_LIB_PATH" value="" />
|
9
|
+
</configuration>
|
10
|
+
</facet>
|
11
|
+
</component>
|
12
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
13
|
+
<exclude-output />
|
14
|
+
<content url="file://$MODULE_DIR$">
|
15
|
+
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
16
|
+
</content>
|
17
|
+
<orderEntry type="inheritedJdk" />
|
18
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
19
|
+
</component>
|
20
|
+
</module>
|
21
|
+
|
data/lib/ffi/platform.rb
CHANGED
@@ -25,12 +25,14 @@
|
|
25
25
|
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
26
26
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27
27
|
|
28
|
+
require 'ffi_c'
|
28
29
|
require 'rbconfig'
|
30
|
+
|
29
31
|
module FFI
|
30
32
|
class PlatformError < FFI::NativeError; end
|
31
33
|
|
32
34
|
module Platform
|
33
|
-
OS = case
|
35
|
+
OS = case RbConfig::CONFIG['host_os'].downcase
|
34
36
|
when /linux/
|
35
37
|
"linux"
|
36
38
|
when /darwin/
|
@@ -44,7 +46,7 @@ module FFI
|
|
44
46
|
when /win|mingw/
|
45
47
|
"windows"
|
46
48
|
else
|
47
|
-
|
49
|
+
RbConfig::CONFIG['host_os'].downcase
|
48
50
|
end
|
49
51
|
|
50
52
|
ARCH = case CPU.downcase
|
@@ -55,7 +57,7 @@ module FFI
|
|
55
57
|
when /ppc|powerpc/
|
56
58
|
"powerpc"
|
57
59
|
else
|
58
|
-
|
60
|
+
RbConfig::CONFIG['host_cpu']
|
59
61
|
end
|
60
62
|
|
61
63
|
private
|
data/libtest/Benchmark.c
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2007 Wayne Meissner. All rights reserved.
|
3
|
+
*
|
4
|
+
* Redistribution and use in source and binary forms, with or without
|
5
|
+
* modification, are permitted provided that the following conditions are met:
|
6
|
+
*
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
8
|
+
* list of conditions and the following disclaimer.
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice
|
10
|
+
* this list of conditions and the following disclaimer in the documentation
|
11
|
+
* and/or other materials provided with the distribution.
|
12
|
+
* Neither the name of the project nor the names of its contributors
|
13
|
+
* may be used to endorse or promote products derived from this software
|
14
|
+
* without specific prior written permission.
|
15
|
+
*
|
16
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
20
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
21
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
22
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
23
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
24
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
25
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
26
|
+
*/
|
27
|
+
#include <sys/types.h>
|
28
|
+
#include <stdint.h>
|
29
|
+
|
30
|
+
void returnVoid() {
|
31
|
+
|
32
|
+
}
|
33
|
+
|
34
|
+
void returnVoidI(int arg) {
|
35
|
+
|
36
|
+
}
|
37
|
+
int returnInt() {
|
38
|
+
return 0;
|
39
|
+
}
|
40
|
+
|
41
|
+
int returnIntI(int arg) {
|
42
|
+
return arg;
|
43
|
+
}
|
44
|
+
|
45
|
+
typedef int8_t s8;
|
46
|
+
typedef uint8_t u8;
|
47
|
+
typedef int16_t s16;
|
48
|
+
typedef uint16_t u16;
|
49
|
+
typedef int32_t s32;
|
50
|
+
typedef uint32_t u32;
|
51
|
+
typedef int64_t s64;
|
52
|
+
typedef uint64_t u64;
|
53
|
+
typedef float f32;
|
54
|
+
typedef double f64;
|
55
|
+
typedef void v;
|
56
|
+
typedef char* S;
|
57
|
+
typedef void* P;
|
58
|
+
|
59
|
+
#define B6(R, T1, T2, T3, T4, T5, T6) R bench_##T1##T2##T3##T4##T5##T6##_##R(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6) {}
|
60
|
+
#define B5(R, T1, T2, T3, T4, T5) R bench_##T1##T2##T3##T4##T5##_##R(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) {}
|
61
|
+
#define B4(R, T1, T2, T3, T4) R bench_##T1##T2##T3##T4##_##R(T1 a1, T2 a2, T3 a3, T4 a4) {}
|
62
|
+
#define B3(R, T1, T2, T3) R bench_##T1##T2##T3##_##R(T1 a1, T2 a2, T3 a3) {}
|
63
|
+
#define B2(R, T1, T2) R bench_##T1##T2##_##R(T1 a1, T2 a2) {}
|
64
|
+
#define B1(R, T1) R bench_##T1##_##R(T1 a1) {}
|
65
|
+
#define BrV(T) B1(v, T); B2(v, T, T); B3(v, T, T, T); B4(v, T, T, T, T); B5(v, T, T, T, T, T); B6(v, T, T, T, T, T, T);
|
66
|
+
BrV(u32);
|
67
|
+
BrV(s32);
|
68
|
+
BrV(s64);
|
69
|
+
BrV(u64);
|
70
|
+
BrV(f32);
|
71
|
+
BrV(f64);
|
72
|
+
BrV(S);
|
73
|
+
BrV(P);
|