[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: rb_require() causes segfault

Bertram Scharpf

9/2/2008 10:36:00 AM

Hi,

Am Dienstag, 02. Sep 2008, 03:42:29 +0900 schrieb Bertram Scharpf:
> 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;
}
----------------------------------------------------------------


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-...

3 Answers

Bertram Scharpf

9/2/2008 8:06:00 PM

0

Hi,

Am Dienstag, 02. Sep 2008, 19:36:05 +0900 schrieb Bertram Scharpf:
> Am Dienstag, 02. Sep 2008, 03:42:29 +0900 schrieb Bertram Scharpf:
> > 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.

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;
}
----------------------------------------------------------------


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-...

Nobuyoshi Nakada

9/3/2008 3:06:00 AM

0

Hi,

At Wed, 3 Sep 2008 05:05:52 +0900,
Bertram Scharpf 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.

--
Nobu Nakada

Bertram Scharpf

9/3/2008 11:18:00 AM

0

Hi,

Am Mittwoch, 03. Sep 2008, 12:05:40 +0900 schrieb Nobuyoshi Nakada:
> At Wed, 3 Sep 2008 05:05:52 +0900,
> Bertram Scharpf 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


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-...