RubyInline 1.0.4 Released! (fwd)

… especially if “legacy Perl code” includes CPAN :wink:

Mike

(Yes, yes, lots of legacy perl code would benefit from a ground-up
rewrite.)

···

In article alls6501s0h@enews3.newsguy.com, Phil Tomson wrote:

Perl has Inline modules available for several languages including Ruby (as
shown above by Pat). Now it might be nice to have a RubyInline::Perl
module so people can make use of legacy Perl code in their Ruby apps.


mike@stok.co.uk | The “`Stok’ disclaimers” apply.
http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA
mike@exegenix.com | Fingerprint 0570 71CD 6790 7C28 3D60
http://www.exegenix.com/ | 75D2 9EC4 C1C0 0599 13DA

Hi,

tmpdir = ENV['TMP'] + "/.ruby_inline"

I’ve left /tmp in favor of the home directory. Is there something like
ENV[‘HOME’] on win?

As to NT series, HOMEDRIVE and HOMEPATH are set. It may be
better to set HOME to %HOMEDRIVE%%HOMEPATH%, %USERPROFILE%, or
“My Documents” directory, in NtInitialize().

  # 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.

Extension library may have exported symbols other than
initializer. So mkmf.rb uses .def file rather than linker
option. You could do:

system(Config::CONFIG[“ruby_install_name”], “-rmkmf”, “-e”, “create_makefile(‘#{mod_name}’)”)

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?

This isn’t open' nor obvious file references’.

How about this?

class << File
if File::ALT_SEPARATOR
def extern_path(f)
f.gsub(SEPARATOR, ALT_SEPARATOR)
end
else
alias extern_path dup
end
end
cmd = “#{cc} -o #{so_name} #{src_name} #{File.extern_path(libs)}”

···

At Fri, 13 Sep 2002 02:40:47 +0900, Ryan Davis wrote:


Nobu Nakada

Hi,

“Ryan Davis” ryand-ruby@zenspider.com wrote in message
news:6320424A-C676-11D6-9FF2-0003939161E2@zenspider.com

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.

···

On Wednesday, Sep 11, 2002, at 23:19 US/Pacific, Park Heesob wrote:

=================================================================
#!/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

Ryan Davis wrote:

tmpdir = ENV['TMP'] + "/.ruby_inline"

I’ve left /tmp in favor of the home directory. Is there something like
ENV[‘HOME’] on win?

NT/2K/XP has HOMEPATH and HOMEDIR. Some users (me, for example :))
also have HOME. Also, TEMP is more commonly used than TMP in
DOS/Win32 environment.

···

On Wednesday, Sep 11, 2002, at 23:19 US/Pacific, Park Heesob wrote:


Giuseppe “Oblomov” Bilotta

“E la storia dell’umanità, babbo?”
“Ma niente: prima si fanno delle cazzate,
poi si studia che cazzate si sono fatte”
(Altan)
(“And what about the history of the human race, dad?”
“Oh, nothing special: first they make some foolish things,
then you study which foolish things have been made”)

Well, the current RubyInline is ~50x smaller than the code involved for
Inline::C (and family–the parts that come with it) in perl (72 lines
compared to 3314). I’d really like to keep this as small and clean as
possible. I don’t know if extending this for every language under the
sun will allow this effort to stay small and clean.

···

On Wednesday, Sep 11, 2002, at 05:16 US/Pacific, Mike Stok wrote:

In article alls6501s0h@enews3.newsguy.com, Phil Tomson wrote:

Perl has Inline modules available for several languages including
Ruby (as
shown above by Pat). Now it might be nice to have a RubyInline::Perl
module so people can make use of legacy Perl code in their Ruby apps.

… especially if “legacy Perl code” includes CPAN :wink:

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” phasis@kornet.net wrote in message
news:ipcg9.287$GH5.1430@news.hananet.net

Hi,

“Ryan Davis” ryand-ruby@zenspider.com 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

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” phasis@kornet.net wrote in message
news:ipcg9.287$GH5.1430@news.hananet.net

Hi,

“Ryan Davis” ryand-ruby@zenspider.com 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

Here is another version using mkmf.

I don’t mean to be a total bother, but does windoze have diff? diff
would be much more workable in this context. I’m having a hard time
dealing w/ your changes because they aren’t file attachments, nor are
they diffs. As a result, I have to deal with all sorts of whitespace
issues and the like.

Mike Stok mike@stok.co.uk writes:

… Especially if “legacy Perl code” includes CPAN :wink:

Heretic! Don’t you know that every wheel must be completely
reinvented in every new language? To do otherwise wouldn’t be
“pure”. And everyone knows that “reuse” is just a meaningless
buzzword those addled OO-zealots like to throw around.

(yes, I’m a little annoyed. There seems to be a popular attitude that
it’s better to put energy towards rewriting every useful library in
Ruby, rather than towards making Ruby more inter-operable. Those who
suggest this apparently have an infinite amount of time, and are
infallible to the point of never making the same mistakes the original
implementors made. ::grumble::slight_smile:

I say Ruby::Inline is a great idea, and I hope it is extended to other
languages. As a matter of fact, IIRC the original writer of
Perl::Inline commented that having a Perl::Inline::Ruby module was a bit
bass-ackward, since it made more sense to be able to include legacy
Perl code in Ruby! :slight_smile:

~Avdi

nobu.nokada@softhome.net wrote in message news:200209130216.g8D2GDf13545@sharui.nakada.kanuma.tochigi.jp

Hi,

tmpdir = ENV['TMP'] + "/.ruby_inline"

I’ve left /tmp in favor of the home directory. Is there something like
ENV[‘HOME’] on win?

As to NT series, HOMEDRIVE and HOMEPATH are set. It may be
better to set HOME to %HOMEDRIVE%%HOMEPATH%, %USERPROFILE%, or
“My Documents” directory, in NtInitialize().

%USERPROFILE% sounds like the most sensible one to me.

~ Patrick

···

At Fri, 13 Sep 2002 02:40:47 +0900, > Ryan Davis wrote:

Hi,
“Shashank Date” ADATE@kc.rr.com wrote in message
news:c%cg9.135362$27.2204597@twister.rdc-kc.rr.com…

···

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

There is no warning on
ruby 1.6.6 (2001-12-26) [i686-linux]
ruby 1.6.7 (2002-03-01) [i686-linux]

In order to prevent warning
insert
$INSTALLFILES = ‘’
before
create_makefile(mod_name)

Park Heesob

Hi,
“Ryan Davis” ryand-ruby@zenspider.com wrote in message
news:AABCBCCE-C6CC-11D6-95F8-0030657CEB62@zenspider.com

Here is another version using mkmf.

I don’t mean to be a total bother, but does windoze have diff? diff
would be much more workable in this context. I’m having a hard time
dealing w/ your changes because they aren’t file attachments, nor are
they diffs. As a result, I have to deal with all sorts of whitespace
issues and the like.

OK, Here is diff of original and my first version.

···

=================================================
@@ -13,20 +13,13 @@

def inline(args, src)

  • tmpdir = ENV[‘INLINEDIR’] || ENV[‘HOME’] + “/.ruby_inline”
  • tmpdir = ENV[‘TMP’] + “/.ruby_inline”

    unless File.directory? tmpdir then
    $stderr.puts “NOTE: creating #{tmpdir} for RubyInline”
    Dir.mkdir(tmpdir, 0700)
    end

  • mode = File.stat(tmpdir).mode

  • unless (mode % 01000) == 0700 then # FIX: not platform independent.

  •  $stderr.printf "mode = %o\n", mode
    
  •  $stderr.puts "#{tmpdir} is insecure, needs 0700 for perms"
    
  •  exit 1
    
  • end

  • myclass = self.class
    mymethod = self.caller_method_name
    mod_name = “Mod_#{myclass}_#{mymethod}”
    @@ -46,6 +39,7 @@
    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}'"
    

@@ -70,7 +64,9 @@
f.close

   # Compiling
  •  `#{cc} -o #{so_name} #{src_name}`
    
  •  cmd = "#{cc} -o #{so_name} #{src_name} #{libs}".gsub('/','\\') +
    
  •    " -link /INCREMENTAL:no /EXPORT:Init_#{mod_name}"
    
  •  `#{cmd}`
    
    end
    ========================================

original and second version

@@ -1,6 +1,6 @@
#!/usr/local/bin/ruby -w

-require “rbconfig”
+require ‘mkmf’

def caller_method_name()
/`([^']+)'/.match(caller(2).first)[1]
@@ -13,41 +13,25 @@

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

  • mode = File.stat(tmpdir).mode

  • unless (mode % 01000) == 0700 then # FIX: not platform independent.

  •  $stderr.printf "mode = %o\n", mode
    
  •  $stderr.puts "#{tmpdir} is insecure, needs 0700 for perms"
    
  •  exit 1
    
  • 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}"
src_name = “#{tmpdir}/#{mod_name}.c”

  •  $stderr.puts "Building #{so_name} with '#{cc}'"
    
  •  $stderr.puts "Building #{so_name}"
    
     s = %Q{
    

#include “ruby.h”
@@ -70,7 +54,13 @@
f.close

   # Compiling
  •  `#{cc} -o #{so_name} #{src_name}`
    
  •  cwd = Dir.pwd
    
  •  Dir.chdir(tmpdir)
    
  •  $INSTALLFILES = ''
    
  •  create_makefile(mod_name)
    
  •  make = with_config("make-prog", ENV["MAKE"] || "make")
    
  •  `#{make}`
    
  •  Dir.chdir(cwd)
    
    end
    ===============================================================

Park Hee sob

Hmmmm, I think you basically have the right idea.

Now, how about Ruby::Inline::Python? Anyone dares to do that? :slight_smile:

Cheers,

Bill

···

===========================================================================
Avdi B. Grimm avdi@avdi.org wrote:

I say Ruby::Inline is a great idea, and I hope it is extended to other
languages. As a matter of fact, IIRC the original writer of
Perl::Inline commented that having a Perl::Inline::Ruby module was a bit
bass-ackward, since it made more sense to be able to include legacy
Perl code in Ruby! :slight_smile:

~Avdi

Thank you. I’ll use this one.

···

On Friday, Sep 13, 2002, at 07:23 US/Pacific, Patrick May wrote:

%USERPROFILE% sounds like the most sensible one to me.