From: Friedrich Dominicus Date: 2003-10-10T01:15:26+09:00 Subject: Re: I'm stuck ts writes: > >>>>> "F" == Friedrich Dominicus writes: > > F> ts writes: > >> >>>>> "F" == Friedrich Dominicus writes: > >> > F> int main (void){ > F> int i; > F> VALUE obj; > F> VALUE klass; > F> ruby_init(); /* embed Ruby into this program! */ > >> > >> /* 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. > > You have also rb_load_protect() if you want to load a file and catch the > errors > > rb_load_protect(VALUE path, int wrap, int *state); Ok, thanks I'll try it with the Windows progrm. Regards Friedrich