From: "Mauricio Fernández" Date: 2003-10-10T02:14:59+09:00 Subject: Re: I'm stuck On Fri, Oct 10, 2003 at 01:15:26AM +0900, Friedrich Dominicus wrote: > > >> /* At this step you are playing a dangerous game with the GC */ > > F> what you you mean which this step ? > > F> ruby_init? How should I know what else to set up or use? > > > > Here a stupid example : > > > > int main(void) > > { > > char i; > > VALUE obj; > > VALUE klass; > > > > ruby_init(); > > obj = rb_str_new2("a string"); > > > > /* call some ruby functions which call the GC */ > > > > i = RSTRING(obj)->ptr[0]; > > > > /* there are many chances than the String referenced by obj > > was removed by the GC, and you have a segfault when you try > > to access RSTRING(obj)->ptr[0] */ > Ok I understand that now, what do I have to do that it does not > happen? > > What's the simplest but too safe way to solve my simple problem. I > just want the C side access the Ruby side as partly pointed out here. void do_stuff() { char i; VALUE obj; VALUE klass; obj = rb_str_new2("a string"); /* call some ruby functions which call the GC */ i = RSTRING(obj)->ptr[0]; ... } int main(void) { ruby_init(); do_stuff(); } -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com We apologize for the inconvenience, but we'd still like yout to test out this kernel. -- Linus Torvalds, announcing another kernel patch