Segfault when calling rb_eval_string_protect with a non-null

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.

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”
[email protected] 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.

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.

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”
[email protected] 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.