From: Park Heesob Date: 2002-09-13T12:01:57+09:00 Subject: Re: RubyInline and CrossPlatform concerns (was: Windows XP : RubyInline 1.0.4 Released!) Hi, "Ryan Davis" wrote in message news:6320424A-C676-11D6-9FF2-0003939161E2@zenspider.com... > > On Wednesday, Sep 11, 2002, at 23:19 US/Pacific, Park Heesob wrote: > > > tmpdir = ENV['TMP'] + "/.ruby_inline" > > I've left /tmp in favor of the home directory. Is there something like > ENV['HOME'] on win? > > Further, this change of yours doesn't reflect the option of using > ENV['INLINEDIR']. Any reason why? > > > # Compiling > > cmd = "#{cc} -o #{so_name} #{src_name} #{libs}".gsub('/','\\') + > > " -link /INCREMENTAL:no /EXPORT:Init_#{mod_name}" > > `#{cmd}` > > end > > Why didn't rbconfig add the -link line that you have above? I'm not > willing or able to accept this change as-is, because that _should_ be > part of your rbconfig setup, if it isn't, then that wasn't the way ruby > was built and it is suspect. This change makes this section no longer > platform independent. This is further tangled by the gsub, as if the > -link section did come from rbconfig, then the gsub would mess it up. > > Finally, the ".gsub('/', '\\')" is also not platform independent. I'm > frustrated that it's even necessary. As I understand it, perl just > automatically changes things like that (at least on open and other > obvious file references). Python has the very useful 'os' module. Is > this something that we need? How should I deal with this? > > Suggestions? > Here is another version using mkmf. ================================================================= #!/usr/local/bin/ruby -w require 'mkmf' def caller_method_name() /\`([^\']+)\'/.match(caller(2).first)[1] end public :caller_method_name module Inline VERSION = '1.0.5' def inline(args, src) if /mswin32/ =~ RUBY_PLATFORM tmpdir = ENV['INLINEDIR'] || ENV['HOMEDRIVE'] + ENV['HOMEPATH'] + "/.ruby_inline" else tmpdir = ENV['INLINEDIR'] || ENV['HOME'] + "/.ruby_inline" end unless File.directory? tmpdir then $stderr.puts "NOTE: creating #{tmpdir} for RubyInline" Dir.mkdir(tmpdir, 0700) end myclass = self.class mymethod = self.caller_method_name mod_name = "Mod_#{myclass}_#{mymethod}" so_name = "#{tmpdir}/#{mod_name}.so" unless File.file? so_name and File.mtime($0) < File.mtime(so_name) then src_name = "#{tmpdir}/#{mod_name}.c" $stderr.puts "Building #{so_name}" s = %Q{ #include "ruby.h" static VALUE t_#{mymethod}(int argc, VALUE *argv, VALUE self) { #{src} } VALUE c#{mod_name}; void Init_#{mod_name}() { c#{mod_name} = rb_define_module("#{mod_name}"); rb_define_method(c#{mod_name}, "_#{mymethod}", t_#{mymethod}, -1); } } # Generating code f = File.new(src_name, "w") f.puts s f.close # Compiling cwd = Dir.pwd Dir.chdir(tmpdir) create_makefile(mod_name) make = with_config("make-prog", ENV["MAKE"] || "make") `#{make}` Dir.chdir(cwd) end # Loading & Replacing w/ new method require "#{so_name}" myclass.class_eval("include #{mod_name}") myclass.class_eval("alias_method :old_#{mymethod}, :#{mymethod}") myclass.class_eval("alias_method :#{mymethod}, :_#{mymethod}") # Calling return method("_#{mymethod}").call(*args) end end ============================================================================ == Park Heesob