From: Shashank Date Date: 2002-09-12T22:40:17+09:00 Subject: Re: Windows XP : RubyInline 1.0.4 Released! (fwd) Experts, After a couple of wrong starts (forgot to set the .NET settings ;-)) I was able to get RubyInline working on my Windows XP (Home Edition). See results below: C:\>ruby example.rb RubyInline 1.0.5 Type = Inline, Iter = 1000000, time = 4.33600000 sec, 0.00000434 sec / iter Thanks a lot Park, nobu and Ryan for your attention. My final request is that these changes (see Park's version below) be refactored into the new 1.0.5 release (enhanced security) that Ryan came out with. TIA, -- Shanko "Park Heesob" wrote in message news:h9Wf9.254$GH5.1246@news.hananet.net... > Hi, > > "Shashank Date" wrote in message > news:hGTf9.130052$27.2149343@twister.rdc-kc.rr.com... > > Ryan, > > > > I was able to make some progress by modifying inline.rb to read the > correct > > ENV variables and got to the point where it did: > > > > C:\> > > > cl -LD -nologo -MD -DNT=1 -Zi -O2b2xg- -G5 -Ic:\ruby\lib\ruby\1.7\i386-mswin > > 32 C:\WINDOWS\TEMP\Mod_MyTest_fastfact.c > > Mod_MyTest_fastfact.c > > Mod_MyTest_fastfact.obj : error LNK2019: unresolved external symbol > > _rb_define_method referenced in function _Init_Mod_MyTest_fastfact > > Mod_MyTest_fastfact.obj : error LNK2019: unresolved external symbol > > _rb_define_module referenced in function _Init_Mod_MyTest_fastfact > > Mod_MyTest_fastfact.dll : fatal error LNK1120: 2 unresolved externals > > > > But then I did not know how to proceed ... any suggestions ? > > > > Thanks ... > > -- Shanko > > Here is my modified version of inline.rb for Windows XP > > ------------------------------------------------- > #!/usr/local/bin/ruby -w > > require "rbconfig" > > def caller_method_name() > /\`([^\']+)\'/.match(caller(2).first)[1] > end > public :caller_method_name > > module Inline > > VERSION = '1.0.5' > > def inline(args, src) > > tmpdir = ENV['TMP'] + "/.ruby_inline" > > 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 > # extracted from mkmf.rb > srcdir = Config::CONFIG["srcdir"] > archdir = Config::CONFIG["archdir"] > if File.exist? archdir + "/ruby.h" > hdrdir = archdir > elsif File.exist? srcdir + "/ruby.h" > hdrdir = srcdir > else > $stderr.puts "ERROR: Can't find header files for ruby. Exiting..." > exit 1 > end > > cc = "#{Config::CONFIG['LDSHARED']} #{Config::CONFIG['CFLAGS']} -I > #{hdrdir}" > libs = " #{Config::CONFIG["libdir"]}/#{Config::CONFIG['LIBRUBYARG']}" > src_name = "#{tmpdir}/#{mod_name}.c" > $stderr.puts "Building #{so_name} with '#{cc}'" > > 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 > cmd = "#{cc} -o #{so_name} #{src_name} #{libs}".gsub('/','\\') + > " -link /INCREMENTAL:no /EXPORT:Init_#{mod_name}" > `#{cmd}` > 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 > > >