Ruby-dl problem: calling func with param

Hello Robert,

I think maybe there is a problem with your installation of ruby or gcc?

I just built ruby from sources on RedHat 8.0, gcc version 3.2 20020903 then copy and pasted your code.

I had to change test.rb
dlload ‘test.so’
to
dlload ‘/home/machine/test/test.so’

but once I’d done that it compiled and ran fine:

[user@machine test]$ ruby test.rb
Hello!
1
3
[user@machine test]$ echo $?
0
[user@machine test]$

I have just noticed that you are using cygwin - maybe the problem is there?

Hope this helps,

Jon

···

-----Original Message-----
From: Robert Feldt [mailto:feldt@ce.chalmers.se]
Sent: 08 September 2003 09:50
To: ruby-talk ML
Subject: Ruby-dl problem: calling func with param

Hi,

I’m trying out ruby-dl and it looks great. However,
I get a seg fault when calling funcs that take parameters.
Anyone can spot the problem?

Here’s a transcript showing what I did:

$ cat test.c
#include <stdio.h>

extern void hello()
{
printf(“Hello!\n”);
}

extern int one()
{
return 1;
}

extern int inc(int n)
{
return (n+1);
}

feldt@novomundo1 /tmp/using_ruby_dl/test
$ gcc -shared -o test.so test.c

feldt@novomundo1 /tmp/using_ruby_dl/test
$ cat test.rb
require ‘dl/import’
module Test
extend DL::Importable
dlload ‘test.so’

extern “void hello()”
extern “int one()”
extern “int inc(int)”
end
Test.hello
p Test.one
p Test.inc(2)

feldt@novomundo1 /tmp/using_ruby_dl/test
$ ruby test.rb
Hello!
1
(eval):5: [BUG] Segmentation fault
ruby 1.8.0 (2003-09-06) [i386-cygwin]

Segmentation fault (core dumped)

Regards,

Robert Feldt


This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:



This message has been checked for all known viruses by Star Internet delivered
through the MessageLabs Virus Control Centre. For further information visit


Any views or personal opinions expressed within this email may not be those of Talis Information Ltd.
The content of this email message and any files that may be attached are confidential, and for the usage of the intended recipient only. If you are not the intended recipient, then please return this message to the sender and delete it. Any use of this e-mail by an unauthorised recipient is prohibited.

J.Hawkesworth J.Hawkesworth@talis.com skrev den Mon, 8 Sep 2003 19:31:26 +0900:

Hello Robert,

Hi,

I think maybe there is a problem with your installation of ruby or gcc?

I just built ruby from sources on RedHat 8.0, gcc version 3.2 20020903 then copy and pasted your code.

I have just noticed that you are using cygwin - maybe the problem is there?

Yeah, you’re probably right. It works on my linux machine here also.
Problem is I have a recent cygwin and fresh Ruby build.

$ gcc --version
gcc (GCC) 3.2 20020927 (prerelease)

$ ruby -v
ruby 1.8.0 (2003-09-06) [i386-cygwin]

Any ideas welcome.

Regards,

Robert

わたなべです。

Robert Feldt feldt@ce.chalmers.se writes:

$ gcc --version
gcc (GCC) 3.2 20020927 (prerelease)

$ ruby -v
ruby 1.8.0 (2003-09-06) [i386-cygwin]

Any ideas welcome.

I can’t reproduce it.

porter:~/0309 % ruby -v
ruby 1.8.0 (2003-09-08) [i386-cygwin]
porter:~/0309 % ruby test.rb
Hello!
1
3

But Cygwin’s ruby has the same problem.

porter:~/0309 % /usr/bin/ruby test.rb
Hello!
1
(eval):5: [BUG] Segmentation fault
ruby 1.8.0 (2003-08-04) [i386-cygwin]

zsh: segmentation fault (core dumped) /usr/bin/ruby test.rb

···


eban

WATANABE Hirofumi eban@os.rim.or.jp skrev den Mon, 8 Sep 2003 20:07:48 +0900:

I can’t reproduce it.

Thanks for trying it out.

porter:~/0309 % ruby -v
ruby 1.8.0 (2003-09-08) [i386-cygwin]
porter:~/0309 % ruby test.rb
Hello!
1
3

But Cygwin’s ruby has the same problem.

porter:~/0309 % /usr/bin/ruby test.rb
Hello!
1
(eval):5: [BUG] Segmentation fault
ruby 1.8.0 (2003-08-04) [i386-cygwin]

zsh: segmentation fault (core dumped) /usr/bin/ruby test.rb

Which Ruby version is the working one above? It says its also
a cygwin ruby. Sorry I don’t understand what you mean here.

I rebuilt from cvs sources but still get the same problem:

$ ruby -v
ruby 1.8.0 (2003-09-08) [i386-cygwin]

$ ruby test.rb
Hello!
1
(eval):5: [BUG] Segmentation fault
ruby 1.8.0 (2003-09-08) [i386-cygwin]

Regards,

···


Robert Feldt

Hi,

Robert Feldt feldt@ce.chalmers.se writes:

Which Ruby version is the working one above? It says its also
a cygwin ruby. Sorry I don’t understand what you mean
here.

Sorry for confusing you.
I mean:

% /usr/local/bin/ruby -v
ruby 1.8.0 (2003-09-08) [i386-cygwin]
% /usr/bin/ruby -v
ruby 1.8.0 (2003-08-04) [i386-cygwin]

I rebuilt from cvs sources but still get the same problem:

$ ruby -v
ruby 1.8.0 (2003-09-08) [i386-cygwin]

$ ruby test.rb
Hello!
1
(eval):5: [BUG] Segmentation fault
ruby 1.8.0 (2003-09-08) [i386-cygwin]

Hmm, dl.so is updated?

···


eban

WATANABE Hirofumi eban@os.rim.or.jp skrev den Mon, 8 Sep 2003 20:31:15 +0900:

I rebuilt from cvs sources but still get the same problem:

$ ruby -v
ruby 1.8.0 (2003-09-08) [i386-cygwin]

$ ruby test.rb
Hello!
1
(eval):5: [BUG] Segmentation fault
ruby 1.8.0 (2003-09-08) [i386-cygwin]

Hmm, dl.so is updated?

Yes, as far as I can see:

$ ls -al /usr/local/lib/ruby/1.8/i386-cygwin/dl.so
-rwxr-xr-x 1 root mkpasswd 80384 Sep 8 13:17 /usr/local/lib/ruby/1.8/
i386-cygwin/dl.so

$ md5sum /tmp/ruby/ext/dl/dl.so
7bd746620e49bdf3aed77bc86669e8c7 */tmp/ruby/ext/dl/dl.so

$ md5sum /usr/local/lib/ruby/1.8/i386-cygwin/dl.so
7bd746620e49bdf3aed77bc86669e8c7 */usr/local/lib/ruby/1.8/i386-cygwin/dl.so

and I rebooted just to be sure. The problem remains.

Regards,

Robert