summaryrefslogtreecommitdiff
path: root/spec/rubyspec/optional/capi
diff options
context:
space:
mode:
Diffstat (limited to 'spec/rubyspec/optional/capi')
-rw-r--r--spec/rubyspec/optional/capi/ext/jruby.h10
-rw-r--r--spec/rubyspec/optional/capi/ext/rubinius.h8
-rw-r--r--spec/rubyspec/optional/capi/ext/rubyspec.h15
-rw-r--r--spec/rubyspec/optional/capi/ext/truffleruby.h6
-rw-r--r--spec/rubyspec/optional/capi/module_spec.rb8
-rw-r--r--spec/rubyspec/optional/capi/spec_helper.rb147
-rw-r--r--spec/rubyspec/optional/capi/string_spec.rb2
-rw-r--r--spec/rubyspec/optional/capi/time_spec.rb84
8 files changed, 89 insertions, 191 deletions
diff --git a/spec/rubyspec/optional/capi/ext/jruby.h b/spec/rubyspec/optional/capi/ext/jruby.h
deleted file mode 100644
index 00a9789f14..0000000000
--- a/spec/rubyspec/optional/capi/ext/jruby.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifndef RUBYSPEC_CAPI_JRUBY_H
-#define RUBYSPEC_CAPI_JRUBY_H
-
-/* #undef any HAVE_ defines that JRuby does not have. */
-#undef HAVE_RB_DEFINE_HOOKED_VARIABLE
-#undef HAVE_RB_DEFINE_VARIABLE
-
-#undef HAVE_RB_EXEC_RECURSIVE
-
-#endif
diff --git a/spec/rubyspec/optional/capi/ext/rubinius.h b/spec/rubyspec/optional/capi/ext/rubinius.h
deleted file mode 100644
index 7ddf73790d..0000000000
--- a/spec/rubyspec/optional/capi/ext/rubinius.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef RUBYSPEC_CAPI_RUBINIUS_H
-#define RUBYSPEC_CAPI_RUBINIUS_H
-
-/* #undef any HAVE_ defines that Rubinius does not have. */
-#undef HAVE_RB_DEFINE_HOOKED_VARIABLE
-#undef HAVE_RB_DEFINE_VARIABLE
-
-#endif
diff --git a/spec/rubyspec/optional/capi/ext/rubyspec.h b/spec/rubyspec/optional/capi/ext/rubyspec.h
index aa0f4def19..9cba34b888 100644
--- a/spec/rubyspec/optional/capi/ext/rubyspec.h
+++ b/spec/rubyspec/optional/capi/ext/rubyspec.h
@@ -595,19 +595,4 @@
/* Util */
#define HAVE_RB_SCAN_ARGS 1
-/* Now, create the differential set. The format of the preprocessor directives
- * is significant. The alternative implementations should define RUBY because
- * some extensions depend on that. But only one alternative implementation
- * macro should be defined at a time. The conditional is structured so that if
- * no alternative implementation is defined then MRI is assumed.
- */
-
-#if defined(RUBINIUS)
-#include "rubinius.h"
-#elif defined(JRUBY)
-#include "jruby.h"
-#elif defined(TRUFFLERUBY)
-#include "truffleruby.h"
-#endif
-
#endif
diff --git a/spec/rubyspec/optional/capi/ext/truffleruby.h b/spec/rubyspec/optional/capi/ext/truffleruby.h
deleted file mode 100644
index 99976a18a4..0000000000
--- a/spec/rubyspec/optional/capi/ext/truffleruby.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef RUBYSPEC_CAPI_TRUFFLERUBY_H
-#undef RUBYSPEC_CAPI_TRUFFLERUBY_H
-
-// All features are available
-
-#endif
diff --git a/spec/rubyspec/optional/capi/module_spec.rb b/spec/rubyspec/optional/capi/module_spec.rb
index 1c21ad2e7c..23fb674f0e 100644
--- a/spec/rubyspec/optional/capi/module_spec.rb
+++ b/spec/rubyspec/optional/capi/module_spec.rb
@@ -62,16 +62,18 @@ describe "CApiModule" do
mod = @m.rb_define_module_under(CApiModuleSpecs, "ModuleSpecsModuleUnder2")
mod.name.should == "CApiModuleSpecs::ModuleSpecsModuleUnder2"
end
+ end
- it "defines a module for an existing Autoload with an extension" do
+ describe "rb_define_module_under" do
+ before :each do
compile_extension("module_under_autoload")
+ end
+ it "defines a module for an existing Autoload with an extension" do
CApiModuleSpecs::ModuleUnderAutoload.name.should == "CApiModuleSpecs::ModuleUnderAutoload"
end
it "defines a module for an existing Autoload with a ruby object" do
- compile_extension("module_under_autoload")
-
CApiModuleSpecs::RubyUnderAutoload.name.should == "CApiModuleSpecs::RubyUnderAutoload"
end
end
diff --git a/spec/rubyspec/optional/capi/spec_helper.rb b/spec/rubyspec/optional/capi/spec_helper.rb
index 2a0c515306..71b765de07 100644
--- a/spec/rubyspec/optional/capi/spec_helper.rb
+++ b/spec/rubyspec/optional/capi/spec_helper.rb
@@ -1,9 +1,11 @@
require File.expand_path('../../../spec_helper', __FILE__)
+
+# MRI magic to use built but not installed ruby
$extmk = false
require 'rbconfig'
-OBJDIR ||= File.expand_path("../../../ext/#{RUBY_NAME}/#{RUBY_VERSION}", __FILE__)
+OBJDIR ||= File.expand_path("../../../ext/#{RUBY_ENGINE}/#{RUBY_VERSION}", __FILE__)
mkdir_p(OBJDIR)
def extension_path
@@ -15,130 +17,59 @@ def object_path
end
def compile_extension(name)
- preloadenv = RbConfig::CONFIG["PRELOADENV"] || "LD_PRELOAD"
- preload, ENV[preloadenv] = ENV[preloadenv], nil if preloadenv
-
- path = extension_path
- objdir = object_path
-
- # TODO use rakelib/ext_helper.rb?
- arch_hdrdir = nil
-
- if RUBY_NAME == 'rbx'
- hdrdir = RbConfig::CONFIG["rubyhdrdir"]
- elsif RUBY_NAME =~ /^ruby/
- hdrdir = RbConfig::CONFIG["rubyhdrdir"]
- arch_hdrdir = RbConfig::CONFIG["rubyarchhdrdir"]
- elsif RUBY_NAME == 'jruby'
- require 'mkmf'
- hdrdir = $hdrdir
- elsif RUBY_NAME == "maglev"
- require 'mkmf'
- hdrdir = $hdrdir
- elsif RUBY_NAME == 'truffleruby'
- return compile_truffleruby_extconf_make(name, path, objdir)
- else
- raise "Don't know how to build C extensions with #{RUBY_NAME}"
- end
-
- ext = "#{name}_spec"
- source = File.join(path, "#{ext}.c")
- obj = File.join(objdir, "#{ext}.#{RbConfig::CONFIG['OBJEXT']}")
- lib = File.join(objdir, "#{ext}.#{RbConfig::CONFIG['DLEXT']}")
+ debug = false
+ run_mkmf_in_process = RUBY_ENGINE == 'truffleruby'
- ruby_header = File.join(hdrdir, "ruby.h")
- rubyspec_header = File.join(path, "rubyspec.h")
+ ext = "#{name}_spec"
+ lib = "#{object_path}/#{ext}.#{RbConfig::CONFIG['DLEXT']}"
+ ruby_header = "#{RbConfig::CONFIG['rubyhdrdir']}/ruby.h"
- return lib if File.exist?(lib) and File.mtime(lib) > File.mtime(source) and
+ return lib if File.exist?(lib) and
+ File.mtime(lib) > File.mtime("#{extension_path}/rubyspec.h") and
+ File.mtime(lib) > File.mtime("#{extension_path}/#{ext}.c") and
File.mtime(lib) > File.mtime(ruby_header) and
- File.mtime(lib) > File.mtime(rubyspec_header) and
true # sentinel
- # avoid problems where compilation failed but previous shlib exists
- File.delete lib if File.exist? lib
-
- cc = RbConfig::CONFIG["CC"]
- cflags = (ENV["CFLAGS"] || RbConfig::CONFIG["CFLAGS"]).dup
- cflags += " #{RbConfig::CONFIG["ARCH_FLAG"]}" if RbConfig::CONFIG["ARCH_FLAG"]
- cflags += " #{RbConfig::CONFIG["CCDLFLAGS"]}" if RbConfig::CONFIG["CCDLFLAGS"]
- cppflags = (ENV["CPPFLAGS"] || RbConfig::CONFIG["CPPFLAGS"]).dup
- incflags = "-I#{path}"
- incflags << " -I#{arch_hdrdir}" if arch_hdrdir
- incflags << " -I#{hdrdir}"
- csrcflag = RbConfig::CONFIG["CSRCFLAG"]
- coutflag = RbConfig::CONFIG["COUTFLAG"]
-
- compile_cmd = "#{cc} #{incflags} #{cflags} #{cppflags} #{coutflag}#{obj} -c #{csrcflag}#{source}"
- output = `#{compile_cmd}`
-
- unless $?.success? and File.exist?(obj)
- puts "\nERROR:\n#{compile_cmd}\n#{output}"
- puts "incflags=#{incflags}"
- puts "cflags=#{cflags}"
- puts "cppflags=#{cppflags}"
- raise "Unable to compile \"#{source}\""
- end
-
- ldshared = RbConfig::CONFIG["LDSHARED"]
- ldshared += " #{RbConfig::CONFIG["ARCH_FLAG"]}" if RbConfig::CONFIG["ARCH_FLAG"]
- libs = RbConfig::CONFIG["LIBS"]
- dldflags = "#{RbConfig::CONFIG["LDFLAGS"]} #{RbConfig::CONFIG["DLDFLAGS"]} #{RbConfig::CONFIG["EXTDLDFLAGS"]}"
- dldflags.sub!(/-Wl,-soname,\S+/, '')
-
- if /mswin/ =~ RUBY_PLATFORM
- dldflags.sub!("$(LIBPATH)", RbConfig::CONFIG["LIBPATHFLAG"] % path)
- libs += RbConfig::CONFIG["LIBRUBY"]
- outflag = RbConfig::CONFIG["OUTFLAG"]
-
- link_cmd = "#{ldshared} #{outflag}#{lib} #{obj} #{libs} -link #{dldflags} /export:Init_#{ext}"
- else
- libpath = "-L#{path}"
- dldflags.sub!("$(TARGET_ENTRY)", "Init_#{ext}")
-
- link_cmd = "#{ldshared} #{obj} #{libpath} #{dldflags} #{libs} -o #{lib}"
- end
- output = `#{link_cmd}`
-
- unless $?.success?
- puts "\nERROR:\n#{link_cmd}\n#{output}"
- raise "Unable to link \"#{source}\""
- end
-
- lib
-ensure
- ENV[preloadenv] = preload if preloadenv
-end
-
-def compile_truffleruby_extconf_make(name, path, objdir)
- ext = "#{name}_spec"
- file = "#{ext}.c"
- source = "#{path}/#{ext}.c"
- lib = "#{objdir}/#{ext}.#{RbConfig::CONFIG['DLEXT']}"
-
# Copy needed source files to tmpdir
tmpdir = tmp("cext_#{name}")
- Dir.mkdir tmpdir
+ Dir.mkdir(tmpdir)
begin
- ["rubyspec.h", "truffleruby.h", "#{ext}.c"].each do |file|
- cp "#{path}/#{file}", "#{tmpdir}/#{file}"
+ ["rubyspec.h", "#{ext}.c"].each do |file|
+ cp "#{extension_path}/#{file}", "#{tmpdir}/#{file}"
end
Dir.chdir(tmpdir) do
- required = require 'mkmf'
- # Reinitialize mkmf if already required
- init_mkmf unless required
- create_makefile(ext, tmpdir)
- system "make"
-
- copy_exts = RbConfig::CONFIG.values_at('OBJEXT', 'DLEXT')
- Dir.glob("*.{#{copy_exts.join(',')}}") do |file|
- cp file, "#{objdir}/#{file}"
+ if run_mkmf_in_process
+ required = require 'mkmf'
+ # Reinitialize mkmf if already required
+ init_mkmf unless required
+ create_makefile(ext, tmpdir)
+ else
+ File.write("extconf.rb", "require 'mkmf'\n" +
+ "$ruby = ENV.values_at('RUBY_EXE', 'RUBY_FLAGS').join(' ')\n" +
+ # MRI magic to consider building non-bundled extensions
+ "$extout = nil\n" +
+ "create_makefile(#{ext.inspect})\n")
+ output = ruby_exe("extconf.rb")
+ raise "extconf failed:\n#{output}" unless $?.success?
+ $stderr.puts output if debug
end
+
+ make = RbConfig::CONFIG['host_os'].include?("mswin") ? "nmake" : "make"
+ ENV.delete "MAKEFLAGS" # Fix make warning when invoked with -j in MRI
+
+ # Do not capture stderr as we want to show compiler warnings
+ output = `#{make} V=1`
+ raise "#{make} failed:\n#{output}" unless $?.success?
+ $stderr.puts output if debug
+
+ cp File.basename(lib), lib
end
ensure
rm_r tmpdir
end
+ File.chmod(0755, lib)
lib
end
diff --git a/spec/rubyspec/optional/capi/string_spec.rb b/spec/rubyspec/optional/capi/string_spec.rb
index ce0485e8af..7528a71682 100644
--- a/spec/rubyspec/optional/capi/string_spec.rb
+++ b/spec/rubyspec/optional/capi/string_spec.rb
@@ -501,7 +501,7 @@ describe "C-API String function" do
describe "rb_str_hash" do
it "hashes the string into a number" do
s = "hello"
- @s.rb_str_hash(s).should == s.hash
+ @s.rb_str_hash(s).should be_kind_of(Integer)
end
end
diff --git a/spec/rubyspec/optional/capi/time_spec.rb b/spec/rubyspec/optional/capi/time_spec.rb
index 98b609e83e..c8f0d9d4e0 100644
--- a/spec/rubyspec/optional/capi/time_spec.rb
+++ b/spec/rubyspec/optional/capi/time_spec.rb
@@ -165,28 +165,30 @@ describe "CApiTimeSpecs" do
usec.should == 500000
end
- it "creates a timeval for a negative Fixnum" do
- sec, usec = @s.rb_time_timeval(-1232141421)
- sec.should be_kind_of(Integer)
- sec.should == -1232141421
- usec.should be_kind_of(Integer)
- usec.should == 0
- end
+ platform_is_not :mingw32 do
+ it "creates a timeval for a negative Fixnum" do
+ sec, usec = @s.rb_time_timeval(-1232141421)
+ sec.should be_kind_of(Integer)
+ sec.should == -1232141421
+ usec.should be_kind_of(Integer)
+ usec.should == 0
+ end
- it "creates a timeval for a negative Float" do
- sec, usec = @s.rb_time_timeval(-1.5)
- sec.should be_kind_of(Integer)
- sec.should == -2
- usec.should be_kind_of(Integer)
- usec.should == 500000
- end
+ it "creates a timeval for a negative Float" do
+ sec, usec = @s.rb_time_timeval(-1.5)
+ sec.should be_kind_of(Integer)
+ sec.should == -2
+ usec.should be_kind_of(Integer)
+ usec.should == 500000
+ end
- it "creates a timeval for a negative Rational" do
- sec, usec = @s.rb_time_timeval(Rational(-3, 2))
- sec.should be_kind_of(Integer)
- sec.should == -2
- usec.should be_kind_of(Integer)
- usec.should == 500000
+ it "creates a timeval for a negative Rational" do
+ sec, usec = @s.rb_time_timeval(Rational(-3, 2))
+ sec.should be_kind_of(Integer)
+ sec.should == -2
+ usec.should be_kind_of(Integer)
+ usec.should == 500000
+ end
end
it "creates a timeval from a Time object" do
@@ -222,28 +224,30 @@ describe "CApiTimeSpecs" do
nsec.should == 500000000
end
- it "creates a timespec for a negative Fixnum" do
- sec, nsec = @s.rb_time_timespec(-1232141421)
- sec.should be_kind_of(Integer)
- sec.should == -1232141421
- nsec.should be_kind_of(Integer)
- nsec.should == 0
- end
+ platform_is_not :mingw32 do
+ it "creates a timespec for a negative Fixnum" do
+ sec, nsec = @s.rb_time_timespec(-1232141421)
+ sec.should be_kind_of(Integer)
+ sec.should == -1232141421
+ nsec.should be_kind_of(Integer)
+ nsec.should == 0
+ end
- it "creates a timespec for a negative Float" do
- sec, nsec = @s.rb_time_timespec(-1.5)
- sec.should be_kind_of(Integer)
- sec.should == -2
- nsec.should be_kind_of(Integer)
- nsec.should == 500000000
- end
+ it "creates a timespec for a negative Float" do
+ sec, nsec = @s.rb_time_timespec(-1.5)
+ sec.should be_kind_of(Integer)
+ sec.should == -2
+ nsec.should be_kind_of(Integer)
+ nsec.should == 500000000
+ end
- it "creates a timespec for a negative Rational" do
- sec, nsec = @s.rb_time_timespec(Rational(-3, 2))
- sec.should be_kind_of(Integer)
- sec.should == -2
- nsec.should be_kind_of(Integer)
- nsec.should == 500000000
+ it "creates a timespec for a negative Rational" do
+ sec, nsec = @s.rb_time_timespec(Rational(-3, 2))
+ sec.should be_kind_of(Integer)
+ sec.should == -2
+ nsec.should be_kind_of(Integer)
+ nsec.should == 500000000
+ end
end
it "creates a timespec from a Time object" do