Forum: Ruby segfault when calling rb_eval_string_protect with a non-null

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F885676e2784d2e14bce332b0397aca3?d=identicon&s=25 Mark Aufflick (Guest)
on 2006-05-21 16:51
(Received via mailing list)
Hi All,

I'm beginning to work on a ruby module for aolserver, and I have the
following basic issue.

If I call:

rb_eval_string_protect(string, NULL);

Well, it does nothing yet, but it is presumably executing the ruby and
carrying on (not capturing output yet).

If I call it like:

int rb_state = 0;
rb_eval_string_protect(string, &rb_state);

My binary dies a segfault.

Before I dig out gdb, I was wondering if there was a likely simple
cause.

Cheers,

Mark.
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 Yukihiro Matsumoto (Guest)
on 2006-05-22 01:13
(Received via mailing list)
Hi,

In message "Re: segfault when calling rb_eval_string_protect with a
non-null state pointer"
    on Sun, 21 May 2006 23:49:43 +0900, "Mark Aufflick"
<mark-ruby@aufflick.com> writes:

|I'm beginning to work on a ruby module for aolserver, and I have the
|following basic issue.

Without the source code to reproduce the problem, we cannot help
much.  Did you initialize the interpreter properly before calling
rb_eval_string_protect()?

							matz.
F885676e2784d2e14bce332b0397aca3?d=identicon&s=25 Mark Aufflick (Guest)
on 2006-05-22 02:44
(Received via mailing list)
Hi Matz,

Thanks for the reply. It turns out that at 10am I am thinking more
clearly than I was at 1am!

On your prompting I went back to look at my initialisation code I
realised that I had in fact missed initialising a naviserver string -
so nothing to do with ruby at all.

It's now working fine - I can't believe it's so easy! Where should I
be looking for information on embedding ruby with respect to things
like thread safety etc.?

Another quick question - to log ruby evaluation errors I'm doing:

rb_eval_string_protect(rb_code_string, &rb_state);
if (rb_state) {
   Ns_Log(Debug, "ruby eval failed : %d", rb_state);
   Ns_Log(Debug, "ruby $! : %s", STR2CSTR(rb_inspect(rb_gv_get("$!"))));
}

Do you think that's the best way? I've seen code that extracts the
message directy, but I figure that this is the most future proof way.

Cheers,

Mark.
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 Yukihiro Matsumoto (Guest)
on 2006-05-22 06:05
(Received via mailing list)
Hi,

In message "Re: segfault when calling rb_eval_string_protect with a
non-null state pointer"
    on Mon, 22 May 2006 09:42:30 +0900, "Mark Aufflick"
<mark-ruby@aufflick.com> writes:

|It's now working fine - I can't believe it's so easy! Where should I
|be looking for information on embedding ruby with respect to things
|like thread safety etc.?

README.EXT in the distribution and the Pickaxe book.  Note that Ruby
interpreter is not thread safe at all (yet).  Only one thread can
access Ruby interpreter at a time.

							matz.
This topic is locked and can not be replied to.