ffi-inline 0.0.4 → 0.0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,57 +11,59 @@
11
11
  module FFI; module Inline
12
12
 
13
13
  Compiler.define :gcc do
14
- def exists?
15
- `gcc -v 2>&1'`; $?.success?
16
- end
14
+ def exists?
15
+ `gcc -v 2>&1'`; $?.success?
16
+ end
17
17
 
18
- def compile (code, libraries = [])
19
- @code = code
20
- @libraries = libraries
18
+ def compile (code, libraries = [])
19
+ @code = code
20
+ @libraries = libraries
21
21
 
22
- return output if File.exists?(output)
22
+ return output if File.exists?(output)
23
23
 
24
- unless system(if RbConfig::CONFIG['target_os'] =~ /mswin|mingw/
25
- "sh -c '#{ldshared} #{ENV['CFLAGS']} -o #{output.shellescape} #{input.shellescape} #{libs}' 2>#{log.shellescape}"
26
- else
27
- "#{ldshared} #{ENV['CFLAGS']} -o #{output.shellescape} #{input.shellescape} #{libs} 2>#{log.shellescape}"
28
- end)
29
- raise CompilationError.new(log)
30
- end
24
+ cmd = if RbConfig::CONFIG['target_os'] =~ /mswin|mingw/
25
+ "sh -c '#{ldshared} #{ENV['CFLAGS']} -o #{output.shellescape} #{input.shellescape} #{libs}' 2>>#{log.shellescape}"
26
+ else
27
+ "#{ldshared} #{ENV['CFLAGS']} -o #{output.shellescape} #{input.shellescape} #{libs} 2>>#{log.shellescape}"
28
+ end
29
+ File.write(log, cmd + "\n")
30
+ unless system(cmd)
31
+ raise CompilationError.new(log)
32
+ end
31
33
 
32
- output
33
- end
34
+ output
35
+ end
34
36
 
35
37
  private
36
- def digest
37
- Digest::SHA1.hexdigest(@code + @libraries.to_s + @options.to_s)
38
- end
38
+ def digest
39
+ Digest::SHA1.hexdigest(@code + @libraries.to_s + @options.to_s)
40
+ end
39
41
 
40
- def input
41
- File.join(Inline.directory, "#{digest}.c").tap {|path|
42
- File.open(path, 'w') { |f| f.write(@code) } unless File.exists?(path)
43
- }
44
- end
42
+ def input
43
+ File.join(Inliner.directory, "#{digest}.c").tap {|path|
44
+ File.open(path, 'w') { |f| f.write(@code) } unless File.exists?(path)
45
+ }
46
+ end
45
47
 
46
- def output
47
- File.join(Inline.directory, "#{digest}.#{Compiler::Extension}")
48
- end
48
+ def output
49
+ File.join(Inliner.directory, "#{digest}.#{Compiler::Extension}")
50
+ end
49
51
 
50
- def log
51
- File.join(Inline.directory, "#{digest}.log")
52
- end
52
+ def log
53
+ File.join(Inliner.directory, "#{digest}.log")
54
+ end
53
55
 
54
- def ldshared
55
- if RbConfig::CONFIG['target_os'] =~ /darwin/
56
- "gcc -dynamic -bundle -fPIC #{options} #{ENV['LDFLAGS']}"
57
- else
58
- "gcc -shared -fPIC #{options} #{ENV['LDFLAGS']}"
59
- end
60
- end
56
+ def ldshared
57
+ if RbConfig::CONFIG['target_os'] =~ /darwin/
58
+ "gcc -dynamic -bundle -fPIC #{options} #{ENV['LDFLAGS']}"
59
+ else
60
+ "gcc -shared -fPIC #{options} #{ENV['LDFLAGS']}"
61
+ end
62
+ end
61
63
 
62
- def libs
63
- @libraries.map { |lib| "-l#{lib}".shellescape }.join(' ')
64
- end
64
+ def libs
65
+ @libraries.map { |lib| "-l#{lib}".shellescape }.join(' ')
66
+ end
65
67
  end
66
68
 
67
69
  end; end
@@ -11,57 +11,60 @@
11
11
  module FFI; module Inline
12
12
 
13
13
  Compiler.define :tcc do
14
- def exists?
15
- `tcc -v 2>&1'`; $?.success?
16
- end
14
+ def exists?
15
+ `tcc -v 2>&1'`; $?.success?
16
+ end
17
17
 
18
- def compile (code, libraries = [])
19
- @code = code
20
- @libraries = libraries
18
+ def compile (code, libraries = [])
19
+ @code = code
20
+ @libraries = libraries
21
21
 
22
- return output if File.exists?(output)
22
+ return output if File.exists?(output)
23
23
 
24
- unless system(if RbConfig::CONFIG['target_os'] =~ /mswin|mingw/
25
- "sh -c '#{ldshared} #{ENV['CFLAGS']} #{libs} -o #{output.shellescape} #{input.shellescape}' 2>#{log.shellescape}"
26
- else
27
- "#{ldshared} #{ENV['CFLAGS']} #{libs} -o #{output.shellescape} #{input.shellescape} 2>#{log.shellescape}"
28
- end)
29
- raise CompilationError.new(log)
30
- end
24
+ cmd = if RbConfig::CONFIG['target_os'] =~ /mswin|mingw/
25
+ "sh -c '#{ldshared} #{ENV['CFLAGS']} #{libs} -o #{output.shellescape} #{input.shellescape}' 2>>#{log.shellescape}"
26
+ else
27
+ "#{ldshared} #{ENV['CFLAGS']} #{libs} -o #{output.shellescape} #{input.shellescape} 2>>#{log.shellescape}"
28
+ end
29
+ File.write(log, cmd + "\n")
30
+ unless system(cmd)
31
+ raise CompilationError.new(log)
32
+ end
31
33
 
32
- output
33
- end
34
+ output
35
+ end
34
36
 
35
37
  private
36
- def digest
37
- Digest::SHA1.hexdigest(@code + @libraries.to_s + @options.to_s)
38
- end
38
+ def digest
39
+ Digest::SHA1.hexdigest(@code + @libraries.to_s + @options.to_s)
40
+ end
39
41
 
40
- def input
41
- File.join(Inline.directory, "#{digest}.c").tap {|path|
42
- File.open(path, 'w') { |f| f.write(@code) } unless File.exists?(path)
43
- }
44
- end
42
+ def input
43
+ File.join(Inliner.directory, "#{digest}.c").tap {|path|
44
+ File.open(path, 'w') { |f| f.write(@code) } unless File.exists?(path)
45
+ }
46
+ end
45
47
 
46
- def output
47
- File.join(Inline.directory, "#{digest}.#{Compiler::Extension}")
48
- end
48
+ def output
49
+ File.join(Inliner.directory, "#{digest}.#{Compiler::Extension}")
50
+ end
49
51
 
50
- def log
51
- File.join(Inline.directory, "#{digest}.log")
52
- end
52
+ def log
53
+ File.join(Inliner.directory, "#{digest}.log")
54
+ end
53
55
 
54
- def ldshared
55
- if RbConfig::CONFIG['target_os'] =~ /mswin|mingw/
56
- "tcc -rdynamic -shared -fPIC #{options} #{ENV['LDFLAGS']}"
57
- else
58
- "tcc -shared #{options} #{ENV['LDFLAGS']}"
59
- end
60
- end
56
+ def ldshared
57
+ if RbConfig::CONFIG['target_os'] =~ /mswin|mingw/
58
+ "tcc -rdynamic -shared -fPIC #{options} #{ENV['LDFLAGS']}"
59
+ else
60
+ "tcc -shared #{options} #{ENV['LDFLAGS']}"
61
+ end
62
+ end
63
+
64
+ def libs
65
+ @libraries.map { |lib| "-l#{lib}".shellescape }.join(' ')
66
+ end
61
67
 
62
- def libs
63
- @libraries.map { |lib| "-l#{lib}".shellescape }.join(' ')
64
- end
65
68
  end
66
69
 
67
70
  end; end
@@ -11,7 +11,7 @@
11
11
  module FFI
12
12
 
13
13
  module Inline
14
- VERSION = '0.0.4'
14
+ VERSION = '0.0.4.1'
15
15
  end
16
16
 
17
17
  end
data/spec/inliner_spec.rb CHANGED
@@ -115,7 +115,7 @@ describe FFI::Inliner do
115
115
  end
116
116
  module Foo
117
117
  inline do |builder|
118
- builder.map 'my_struct_t *' => 'pointer'
118
+ builder.map 'my_struct_t *' => :pointer
119
119
 
120
120
  builder.raw %q{
121
121
  typedef struct {
@@ -258,20 +258,15 @@ EOC
258
258
  module Foo
259
259
  inline :cpp do |builder|
260
260
  builder.raw %{
261
- #include <iostream>
262
- #include <string>
263
-
264
- using namespace std;
265
-
266
261
  class Greeter
267
262
  {
268
263
  public:
269
264
  Greeter();
270
- string say_hello();
265
+ const char *say_hello();
271
266
  };
272
267
 
273
268
  Greeter::Greeter () { };
274
- string Greeter::say_hello ()
269
+ const char *Greeter::say_hello ()
275
270
  {
276
271
  return "Hello foos!";
277
272
  };
@@ -281,7 +276,7 @@ EOC
281
276
  const char* say_hello () {
282
277
  Greeter greeter;
283
278
 
284
- return greeter.say_hello().c_str();
279
+ return greeter.say_hello();
285
280
  }
286
281
  }, return: :string
287
282
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-inline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-29 00:00:00.000000000 Z
12
+ date: 2012-11-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  version: '0'
101
101
  requirements: []
102
102
  rubyforge_project:
103
- rubygems_version: 1.8.23
103
+ rubygems_version: 1.8.24
104
104
  signing_key:
105
105
  specification_version: 3
106
106
  summary: Inline C/C++ in Ruby easily and cleanly.