From: ts Date: 2006-08-09T19:52:29+09:00 Subject: Re: FOUND was (Re: Init_xxx(with arg ??) in C for ruby ext ???) >>>>> "U" == =?ISO-8859-1?Q?Une b=E9vue?= writes: U> ts wrote: U> /**/ U> struct RAliasFile { U> VALUE alias_path; U> char *orig_path; U> int alias_file; U> int alias_file_broken; U> int folder; U> int data_file; U> char *version; U> }; U> /**/ Useless actually because you use instance variable rather than C struct. If you really want to use C struct, see Data_Make_Struct() and the examples given in README.EXT or ruby-x.x.x/ext/* U> void Init_raliasfile() { U> cRAliasFile = rb_define_class("RAliasFile", rb_cObject); U> rb_define_method(RAliasFile, "initialize", U> m_raliasfile_init, 1); U> rb_define_method(RAliasFile, "new", U> m_raliasfile_new, 1); remove this method #new U> rb_define_method(RAliasFile, "set_alias_path", ^^^^^^^^^^^^^^^ "alias_path=" U> m_set_alias_path, 1); U> rb_define_method(RAliasFile, "alias_path", m_alias_path, U> 0); U> rb_define_method(RAliasFile, "orig_path", m_orig_path, 0); U> rb_define_method(RAliasFile, "is_alias_file", m_is_alias_file, ^^^^^^^^^^^^^^^ "is_alias_file?", U> 0); U> rb_define_method(RAliasFile, "is_alias_file_broken", U> rb_define_method(RAliasFile, "is_folder", m_is_folder, 0); U> rb_define_method(RAliasFile, "is_data_file", m_is_data_file, U> 0); same here U> VALUE m_raliasfile_init(VALUE self, VALUE _alias_path) U> { U> alias_path = _alias_path; remove this variable alias_path U> printf("From C => alias_path : %s\n", alias_path); You have a VALUE not a char *, you must first convert it to (char *) before trying to print it (with, for example, StringValuePtr(), see README.EXT) U> rb_iv_set(self, "@alias_path", alias_path); rb_iv_set(self, "@alias_path", _alias_path); U> return self; U> } U> VALUE m_raliasfile_new(VALUE self, VALUE _alias_path) { U> rb_iv_set(self, "@alias_path", alias_path); U> printf("m_raliasfile_new"); U> alias_path = _alias_path; U> return self; U> } Useless actually : remove it U> VALUE m_set_alias_path(VALUE self, VALUE _alias_path) { U> alias_path = _alias_path; U> rb_iv_set(self, "@alias_path", alias_path); U> // return rb_str_new2((char *) alias_path); U> } U> VALUE m_alias_path(VALUE self) { U> // char *alias_path = "/path/to/something/undefined"; U> return rb_str_new2((char *) alias_path); You have defined an instance variable : retrieve it. *Don't* use a global C variable when you work with instance variable return rb_iv_get(self, "@alias_path"); U> } U> VALUE m_orig_path(VALUE self) { U> char *orig_path = "/Users/yvon/work/Ruby/Native/RubyInline-3.5.0.gem"; U> return rb_str_new2(orig_path); U> } U> VALUE m_is_alias_file(VALUE self) { U> int alias_file = 1; U> return INT2FIX(alias_file); return Qtrue or Qfalse (not a Fixnum) U> } Guy Decoux