From: Shashank Date Date: 2002-09-13T12:42:07+09:00 Subject: Re: RubyInline and CrossPlatform concerns (was: Windows XP : RubyInline 1.0.4 Released!) Park, I tried your new version and here are the results: ---------------------------------------------------------------------------- ----- C:\>ruby example.rb RubyInline 1.0.5 NOTE: creating C:\Documents and Settings\default/.ruby_inline for RubyInline Building C:\Documents and Settings\default/.ruby_inline/Mod_MyTest_fastfact.so creating Makefile c:/ruby/lib/ruby/1.7/mkmf.rb:588: warning: global variable `$INSTALLFILES' not initialized c:/ruby/lib/ruby/1.7/mkmf.rb:592: warning: global variable `$INSTALLFILES' not initialized Microsoft (R) Program Maintenance Utility Version 7.00.9466 Copyright (C) Microsoft Corporation. All rights reserved. Type = Inline, Iter = 1000000, time = 8.50200000 sec, 0.00000850 sec / iter C:\> cd ruby C:\ruby>findstr /S INSTALLFILES *.rb lib\ruby\1.7\mkmf.rb: install_files(mfile, $INSTALLFILES, INSTALL_DIRS, srcprefix) lib\ruby\1.7\mkmf.rb: install_files(mfile, $INSTALLFILES, SITEINSTALL_DIRS, srcprefix) rubysrc\ext\dl\extconf.rb:$INSTALLFILES = [ rubysrc\lib\mkmf.rb: install_files(mfile, $INSTALLFILES, INSTALL_DIRS, srcprefix) rubysrc\lib\mkmf.rb: install_files(mfile, $INSTALLFILES, SITEINSTALL_DIRS, srcprefix) C:\ruby> ---------------------------------------------------------------------------- ---- Notice how $INSTALLFILES is not initialized in any files coming with the standard install ... the initialization is found only in extconf.rb which comes only with the source code. What do you think? Thanks, -- Shanko "Park Heesob" wrote in message news:ipcg9.287$GH5.1430@news.hananet.net... > 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 > > >