Browse files

update for mingw 1.9 stuff

  • Loading branch information...
2 parents 4190233 + 3ef7071 commit 5809f03e261056339c0cee58dfc7914337362e41 @rdp committed Sep 27, 2011
Showing with 104 additions and 67 deletions.
  1. +36 −0 History.txt
  2. +18 −19 README.txt
  3. +3 −1 Rakefile
  4. +2 −3 example2.rb
  5. +30 −30 lib/inline.rb
  6. +9 −8 test/test_inline.rb
  7. +6 −6 tutorial/example2.rb
View
36 History.txt
@@ -1,3 +1,39 @@
+=== 3.10.1 / 2011-09-13
+
+* 1 bug fix:
+
+ * Fix crap_for_windoze to use RbConfig for RUBY_SO_NAME. (jasonrickman)
+
+=== 3.10.0 / 2011-08-30
+
+* 2 minor enhancements:
+
+ * Added engined/versioned subdir to .ruby_inline to help with multiple-ruby usage. (valodzka)
+ * Extended file/module naming to avoid hash collisions. (apohllo)
+
+* 2 bug fixes:
+
+ * Fixed examples for 1.9 compatibility.
+ * Use RbConfig instead of Config. (apohllo)
+
+=== 3.9.0 / 2011-02-18
+
+* 1 minor enhancement:
+
+ * Added arity override option for all C builder methods.
+
+=== 3.8.6 / 2010-09-03
+
+* 1 bug fix:
+
+ * Had to fix the ZenTest dependency to work with the whole 4.x series
+
+=== 3.8.5 / 2010-09-01
+
+* 1 bug fix:
+
+ * Added DLDFLAGS to compiler flags to fix OSX linking on 1.9.2
+
=== 3.8.4 / 2009-12-09
* 1 bug fix:
View
37 README.txt
@@ -1,9 +1,8 @@
= Ruby Inline
-* http://rubyforge.org/projects/rubyinline/
-* http://rubyinline.rubyforge.org/RubyInline/
-* http://www.zenspider.com/ZSS/Products/RubyInline/
-* mailto:ryand-ruby@zenspider.com
+rdoc :: http://docs.seattlerb.org/RubyInline/
+home :: http://www.zenspider.com/ZSS/Products/RubyInline/
+repo :: https://github.com/seattlerb/rubyinline
== DESCRIPTION:
@@ -33,14 +32,14 @@ See hoe for more details.
== FEATURES/PROBLEMS:
-+ Quick and easy inlining of your C or C++ code embedded in your ruby script.
-+ Extendable to work with other languages.
-+ Automatic conversion between ruby and C basic types
- + char, unsigned, unsigned int, char *, int, long, unsigned long
-+ inline_c_raw exists for when the automatic conversion isn't sufficient.
-+ Only recompiles if the inlined code has changed.
-+ Pretends to be secure.
-+ Only requires standard ruby libraries, nothing extra to download.
+* Quick and easy inlining of your C or C++ code embedded in your ruby script.
+* Extendable to work with other languages.
+* Automatic conversion between ruby and C basic types
+ * char, unsigned, unsigned int, char *, int, long, unsigned long
+* inline_c_raw exists for when the automatic conversion isn't sufficient.
+* Only recompiles if the inlined code has changed.
+* Pretends to be secure.
+* Only requires standard ruby libraries, nothing extra to download.
== SYNOPSYS:
@@ -103,21 +102,21 @@ See hoe for more details.
== REQUIREMENTS:
-+ Ruby - 1.8.2 has been used on FreeBSD 4.6+ and MacOSX.
-+ POSIX compliant system (ie pretty much any UNIX, or Cygwin on MS platforms).
-+ A C/C++ compiler (the same one that compiled your ruby interpreter).
-+ test::unit for running tests ( http://testunit.talbott.ws/ ).
+* Ruby - 1.8.2 has been used on FreeBSD 4.6+ and MacOSX.
+* POSIX compliant system (ie pretty much any UNIX, or Cygwin on MS platforms).
+* A C/C++ compiler (the same one that compiled your ruby interpreter).
+* test::unit for running tests ( http://testunit.talbott.ws/ ).
== INSTALL:
-+ make test (optional)
-+ make install
+* make test (optional)
+* make install
== LICENSE:
(The MIT License)
-Copyright (c) 2001-2007 Ryan Davis, Zen Spider Software
+Copyright (c) Ryan Davis, seattle.rb
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
4 Rakefile
@@ -7,14 +7,16 @@ Hoe.add_include_dirs "../../ZenTest/dev/lib"
Hoe.add_include_dirs "lib"
Hoe.plugin :seattlerb
+Hoe.plugin :isolate
Hoe.spec "RubyInline" do
developer 'Ryan Davis', 'ryand-ruby@zenspider.com'
clean_globs << File.expand_path("~/.ruby_inline")
spec_extras[:requirements] =
"A POSIX environment and a compiler for your language."
- extra_deps << 'ZenTest' # ZenTest mapping
+
+ dependency "ZenTest", "~> 4.3" # for ZenTest mapping
end
task :test => :clean
View
5 example2.rb
@@ -14,10 +14,9 @@ class MyTest
builder.add_compile_flags %q(-x c++)
builder.add_link_flags %q(-lstdc++)
+ builder.include "<iostream>"
+
builder.c "
-// stupid c++ comment
-#include <iostream>
-/* stupid c comment */
static
void
hello(int i) {
View
60 lib/inline.rb
@@ -65,7 +65,7 @@ class CompilationError < RuntimeError; end
# the current namespace.
module Inline
- VERSION = '3.8.4'
+ VERSION = '3.10.1'
WINDOZE = /mswin|mingw/ =~ RUBY_PLATFORM
RUBINIUS = defined? RUBY_ENGINE
@@ -134,11 +134,14 @@ def self.rootdir
end
def self.directory
- directory = File.join(rootdir, ".ruby_inline")
- unless defined? @@directory and directory == @@directory
- @@directory = File.join(self.rootdir, ".ruby_inline")
+ unless defined? @@directory then
+ version = "#{Gem.ruby_engine}-#{RbConfig::CONFIG['ruby_version']}"
+
+ @@directory = File.join(self.rootdir, ".ruby_inline", version)
end
- Dir.assert_secure directory
+
+ Dir.assert_secure @@directory
+
@@directory
end
@@ -247,13 +250,13 @@ def generate(src, options={})
method_name = options[:method_name]
method_name ||= test_to_normal function_name
return_type = signature['return']
- arity = signature['arity']
+ arity = options[:arity] || signature['arity']
raise ArgumentError, "too many arguments" if arity > MAGIC_ARITY_THRESHOLD
if expand_types then
prefix = "static VALUE #{function_name}("
- if arity == MAGIC_ARITY then
+ if arity <= MAGIC_ARITY then
prefix += "int argc, VALUE *argv, VALUE self"
else
prefix += "VALUE self"
@@ -285,12 +288,14 @@ def generate(src, options={})
delta = if result =~ /\A(static.*?\{)/m then
$1.split(/\n/).size
else
- warn "WAR\NING: Can't find signature in #{result.inspect}\n" unless $TESTING
+ msg = "WAR\NING: Can't find signature in #{result.inspect}\n"
+ warn msg unless $TESTING
0
end
file, line = caller[1].split(/:/)
- result = "# line #{line.to_i + delta} \"#{file}\"\n" + result unless $DEBUG and not $TESTING
+ result = "# line #{line.to_i + delta} \"#{file}\"\n" + result unless
+ $DEBUG and not $TESTING
@src << result
@sig[function_name] = [arity,singleton,method_name]
@@ -365,14 +370,14 @@ def module_name
module_name = @mod.name.gsub('::','__')
md5 = Digest::MD5.new
@sig.keys.sort_by { |x| x.to_s }.each { |m| md5 << m.to_s }
- @module_name = "Inline_#{module_name}_#{md5.to_s[0,4]}"
+ @module_name = "Inline_#{module_name}_#{md5}"
end
@module_name
end
def so_name
unless defined? @so_name then
- @so_name = "#{Inline.directory}/#{module_name}.#{Config::CONFIG["DLEXT"]}"
+ @so_name = "#{Inline.directory}/#{module_name}.#{RbConfig::CONFIG["DLEXT"]}"
end
@so_name
end
@@ -523,7 +528,7 @@ def build
unless File.directory? Inline.directory then
warn "NOTE: creating #{Inline.directory} for RubyInline" if $DEBUG
- Dir.mkdir Inline.directory, 0700
+ FileUtils.mkdir_p Inline.directory, :mode => 0700
end
src_name = "#{Inline.directory}/#{module_name}.c"
@@ -548,7 +553,7 @@ def build
if recompile then
hdrdir = %w(srcdir archdir rubyhdrdir).map { |name|
- Config::CONFIG[name]
+ RbConfig::CONFIG[name]
}.find { |dir|
dir and File.exist? File.join(dir, "/ruby.h")
} or abort "ERROR: Can't find header dir for ruby. Exiting..."
@@ -563,17 +568,19 @@ def build
end
ldshared = Config::CONFIG['LDSHARED']
- # strip off some extra gunk in 1.9
+ # strip off some extra gunk in mingw 1.9
ldshared = ldshared.gsub(/\$\(.*\)/, '') if RUBY_PLATFORM =~ /mingw/
-
+ dldflags = RbConfig::CONFIG['DLDFLAGS']
+ dldflags = dldflags.gsub(/\$\(.*\)/, '') if RUBY_PLATFORM =~ /mingw/
cmd = [ ldshared,
flags,
- Config::CONFIG['CCDLFLAGS'],
- Config::CONFIG['CFLAGS'],
+ dldflags,
+ RbConfig::CONFIG['CCDLFLAGS'],
+ RbConfig::CONFIG['CFLAGS'],
'-I', hdrdir,
config_hdrdir,
- '-I', Config::CONFIG['includedir'],
- "-L#{Config::CONFIG['libdir']}",
+ '-I', RbConfig::CONFIG['includedir'],
+ "-L#{RbConfig::CONFIG['libdir']}",
'-o', so_name.inspect,
File.expand_path(src_name).inspect,
libs,
@@ -596,7 +603,7 @@ def build
# NOTE: manifest embedding is only required when using VC8 ruby
# build or compiler.
- # Errors from this point should be ignored if Config::CONFIG['arch']
+ # Errors from this point should be ignored if RbConfig::CONFIG['arch']
# (RUBY_PLATFORM) matches 'i386-mswin32_80'
if WINDOZE and RUBY_PLATFORM =~ /_80$/ then
Dir.chdir Inline.directory do
@@ -625,9 +632,10 @@ def crap_for_windoze
# gawd windoze land sucks
case RUBY_PLATFORM
when /mswin32/ then
- " -link /LIBPATH:\"#{Config::CONFIG['libdir']}\" /DEFAULTLIB:\"#{Config::CONFIG['LIBRUBY']}\" /INCREMENTAL:no /EXPORT:Init_#{module_name}"
+ " -link /LIBPATH:\"#{RbConfig::CONFIG['libdir']}\" /DEFAULTLIB:\"#{RbConfig::CONFIG['LIBRUBY']}\" /INCREMENTAL:no /EXPORT:Init_#{module_name}"
when /mingw32/ then
- " -Wl,--enable-auto-import -L#{Config::CONFIG['libdir']} #{Config::CONFIG['LIBRUBYARG_SHARED']}"
+ c = RbConfig::CONFIG
+ " -Wl,--enable-auto-import -L#{c['libdir']} -l#{c['RUBY_SO_NAME']} #{c['LIBRUBYARG_SHARED']}"
when /i386-cygwin/ then
' -L/usr/local/lib -lruby.dll'
else
@@ -790,13 +798,6 @@ def c_raw_singleton src, options = {}
end # module Inline
class Module
-
- ##
- # options is a hash that allows you to pass extra data to your
- # builder. The only key that is guaranteed to exist is :testing.
-
- attr_reader :options
-
##
# Extends the Module class to have an inline method. The default
# language/builder used is C, but can be specified with the +lang+
@@ -822,7 +823,6 @@ def inline(lang = :C, options={})
Inline.const_get(lang)
end
- @options = options
builder = builder_class.new self
yield builder
View
17 test/test_inline.rb
@@ -5,9 +5,10 @@
require 'inline'
require 'tempfile'
require 'tmpdir'
-require 'test/unit'
require 'fileutils' unless defined?(::FileUtils)
+require 'minitest/autorun'
+
File.umask(0)
require 'pathname'
@@ -21,7 +22,7 @@
$test_inline_path = File.expand_path $test_inline_path
end
-class InlineTestCase < Test::Unit::TestCase
+class InlineTestCase < MiniTest::Unit::TestCase
def setup
super
@rootdir = File.join(Dir.tmpdir, "test_inline.#{$$}")
@@ -79,7 +80,8 @@ def test_rootdir
end
def test_directory
- inlinedir = File.join(@rootdir, ".ruby_inline")
+ version = "#{Gem.ruby_engine}-#{RbConfig::CONFIG['ruby_version']}"
+ inlinedir = File.join(@rootdir, ".ruby_inline", version)
assert_equal(inlinedir, Inline.directory)
end
@@ -411,8 +413,7 @@ def util_module_name(*signatures)
md5 << signature.to_s
end
- assert_equal("Inline_TestInline__TestC_#{md5.to_s[0,4]}",
- @builder.module_name)
+ assert_equal("Inline_TestInline__TestC_#{md5}", @builder.module_name)
end
def test_module_name_0_methods
@@ -773,7 +774,7 @@ def test_generate_ext
#ifdef __cplusplus
extern \"C\" {
#endif#{windoze}
- void Init_Inline_TestInline__TestC_eba5() {
+ void Init_Inline_TestInline__TestC_eba5e5454322e22fe2310198ef14e43f() {
VALUE c = rb_cObject;
c = rb_const_get(c, rb_intern("TestInline"));
c = rb_const_get(c, rb_intern("TestC"));
@@ -793,7 +794,7 @@ def test_generate_ext
def test_generate_ext_bad_allocate
@builder.c_singleton "VALUE allocate(VALUE bad) { return Qnil; }"
- e = assert_raise RuntimeError do
+ e = assert_raises RuntimeError do
@builder.generate_ext
end
@@ -1032,7 +1033,7 @@ def test_inline
"inline dir should have been created")
matches = Dir[File.join(Inline.directory, "Inline_TestModule_*.c")]
assert_equal(1, matches.length, "Source should have been created")
- library_file = matches.first.gsub(/\.c$/) { "." + Config::CONFIG["DLEXT"] }
+ library_file = matches.first.gsub(/\.c$/) { "." + RbConfig::CONFIG["DLEXT"] }
assert(test(?f, library_file),
"Library file should have been created")
end
View
12 tutorial/example2.rb
@@ -7,15 +7,15 @@ class Array
inline do |builder|
builder.c_raw "
static VALUE average(int argc, VALUE *argv, VALUE self) {
- double result;
+ double result = 0;
long i, len;
- VALUE *arr = RARRAY(self)->ptr;
- len = RARRAY(self)->len;
-
+ VALUE *arr = RARRAY_PTR(self);
+ len = RARRAY_LEN(self);
+
for(i=0; i<len; i++) {
result += NUM2DBL(arr[i]);
}
-
+
return rb_float_new(result/(double)len);
}
"
@@ -70,7 +70,7 @@ class Array
# & time ruby ./example2.rb 5 100000
# .....
-#
+#
# real 0m1.403s
# user 0m1.120s
# sys 0m0.070s

0 comments on commit 5809f03

Please sign in to comment.