From: "Nicolas Desprès" Date: 2006-03-24T19:41:02+09:00 Subject: Re: require 'tk' SEGV with Ruby embedded in C On 3/24/06, Nicolas Despr�s wrote: > On 3/24/06, Nicolas Despr�s wrote: > > I'm having trouble trying to embed Ruby in a C program. > > > > Patching the program this way, solve the problem: > > > $ cat test.c > > #include > > > > EXTERN VALUE rb_progname; > EXTERN VALUE rb_argv0; > > > int main() > > { > > ruby_init(); > > ruby_script("test"); > rb_argv0 = rb_progname; > > ruby_init_loadpath(); > > rb_eval_string("require 'tk'"); > > return 0; > > } > > I'm looking for a cleaner solution. > Indeed the problem comes from the tcltklib.c line 7932 and the program fails since rb_argv0 is not initialized. I think the ruby_script function should have initialized it since this function initializes rb_progname and ruby_sourcefile. Using ruby_options also solves the problem but ruby_options reads stdin if no arguments are given and in fact I don't want to give arguments since I just want to use ruby as a library. Finally, when I look at ruby_process_options (called by ruby_options) I saw these two lines at the beginning: ruby_script(argv[0]); /* for the time being */ rb_argv0 = rb_progname; I'm wondering why the second statements is not included in the ruby_script function. If it were, it may have saved me a lot of time by avoiding me the problem I mentioned above. Any further commentaries about this issue is welcome, Best regards, -- Nicolas Despr�s