Rb_require() causes segfault

Hi,

calling rb_require() with a file name that will not be found,
causes a segmentation fault to be raised:

ruby: [BUG] Segmentation fault
ruby 1.8.6 (2008-08-11) [i386-freebsd7]

Abort trap: 6 (core dumped)

It’s the same with Linux (both gcc). I googled and found some
answers that say: “Link with the -rdynamic flag.” That did not
help.

Could anyone give me a hint what is going on here? At least a
point to a working example should suffice.

Thanks in advance,

Bertram

                       Here's my code:

#include <ruby.h>

VALUE call_require( VALUE name)
{
if (0) rb_raise( rb_eStandardError, “don’t do it”);
return rb_require( (char *) name);
}

VALUE rescue_require( VALUE data, VALUE err)
{
printf(“Error: [[[%s]]]\n”, RSTRING(rb_obj_as_string(err))->ptr);
return Qnil;
}

void sure_require( char *name)
{
rb_rescue( &call_require, (VALUE) name, &rescue_require, Qnil);
}

int main( int argc, char *argv)
{
ruby_init();
ruby_init_loadpath();
sure_require( “nonexistent”);
return 0;
}

Hi,

Am Dienstag, 02. Sep 2008, 03:42:29 +0900 schrieb Bertram S.:

calling rb_require() with a file name that will not be found,
causes a segmentation fault to be raised:

I’m still about to convince my colleagues that Ruby is the
programming language of concern. Failing in this subject would
spoil this whole project.

Probably I could compile Ruby with debugging information and
search the cause on my own. This is exactly the subject I
unlearned since I use Ruby.

So please, if somebody could give me a slight hint. It would save
me so much time and tension.

Thanks in advance.

Bertram

Hi,

Am Dienstag, 02. Sep 2008, 03:42:29 +0900 schrieb Bertram S.:

calling rb_require() with a file name that will not be found,
causes a segmentation fault to be raised:

ruby: [BUG] Segmentation fault
ruby 1.8.6 (2008-08-11) [i386-freebsd7]

Abort trap: 6 (core dumped)

OK, I start to debug it.

The segfault happens in rb_rescue2()/eval.c, line 5501 at a
JUMP_TAG() statement. This is when the LoadError exception is
being handled, not in the actual rb_require() itself.

When I comment in the rb_raise() call below, the segfault won’t
happen.

Would this information help somebody enlighten me what is going on
here?

Thanks in advance.

Bertram

                       Here's my code:

#include <ruby.h>

VALUE call_require( VALUE name)
{
if (0) rb_raise( rb_eStandardError, “don’t do it”);
return rb_require( (char *) name);
}

VALUE rescue_require( VALUE data, VALUE err)
{
printf(“Error: [[[%s]]]\n”, RSTRING(rb_obj_as_string(err))->ptr);
return Qnil;
}

void sure_require( char *name)
{
rb_rescue( &call_require, (VALUE) name, &rescue_require, Qnil);
}

int main( int argc, char *argv)
{
ruby_init();
ruby_init_loadpath();
sure_require( “nonexistent”);
return 0;
}

Hi,

Am Dienstag, 02. Sep 2008, 19:36:05 +0900 schrieb Bertram S.:

The segfault happens in rb_rescue2()/eval.c, line 5501 at a
JUMP_TAG() statement. This is when the LoadError exception is
being handled, not in the actual rb_require() itself.

I just debugged into the JUMP_TAG() macro. Indeed the `prot_tag’
pointer is NULL. Is this a bug to be reported?

I tried 1.8.6-p114 and 1.8.6-p287 versions.

Thanks in advance.

Bertram

                       Here's my code:

#include <ruby.h>

VALUE call_require( VALUE name)
{
if (0) rb_raise( rb_eStandardError, “don’t do it”);
return rb_require( (char *) name);
}

VALUE rescue_require( VALUE data, VALUE err)
{
printf(“Error: [[[%s]]]\n”, RSTRING(rb_obj_as_string(err))->ptr);
return Qnil;
}

void sure_require( char *name)
{
rb_rescue( &call_require, (VALUE) name, &rescue_require, Qnil);
}

int main( int argc, char *argv)
{
ruby_init();
ruby_init_loadpath();
sure_require( “nonexistent”);
return 0;
}

Hi,

Am Mittwoch, 03. Sep 2008, 12:05:40 +0900 schrieb Nobuyoshi N.:

At Wed, 3 Sep 2008 05:05:52 +0900,
Bertram S. wrote in [ruby-talk:313696]:

I just debugged into the JUMP_TAG() macro. Indeed the `prot_tag’
pointer is NULL. Is this a bug to be reported?

No thank you.

Sorry. I was just irritated about getting absolutely no answer on
such a simple question.

void sure_require( char *name)
{
rb_rescue( &call_require, (VALUE) name, &rescue_require, Qnil);

use rb_protect() instead of rb_rescue(), the latter catches
only StandardError and its subclasses.

I didn’t realize that LoadError is not a subclass of
StandardError. Now it is obvious to me.

rb_rescue2( &call_require, (VALUE) name, &rescue_require, Qnil,
                    rb_eLoadError, (VALUE) 0);

T-h-a-n-k y-o-u!

Bertram

Hi,

At Wed, 3 Sep 2008 05:05:52 +0900,
Bertram S. wrote in [ruby-talk:313696]:

I just debugged into the JUMP_TAG() macro. Indeed the `prot_tag’
pointer is NULL. Is this a bug to be reported?

No thank you.

void sure_require( char *name)
{
rb_rescue( &call_require, (VALUE) name, &rescue_require, Qnil);

use rb_protect() instead of rb_rescue(), the latter catches
only StandardError and its subclasses.