From: ts Date: 2003-04-03T23:29:08+09:00 Subject: Re: Strange behavior in C-declared global variable? >>>>> "J" == =?iso-8859-1?Q?Jos=E9?= Augusto writes: J> static VALUE newvar(int argc, VALUE *argv, VALUE self) { J> VALUE temp; J> temp = rb_ary_new(); J> rb_ary_push(temp, rb_float_new(3.3)); J> rb_define_variable("$tempor", &temp); J> rb_global_variable(&temp); J> return Qnil; J> } Don't do this rb_define_variable() and rb_global_variable() must be used *only* with "global" variables, like for example in /* see the declaration of temp0 and temp1 outside the function */ static VALUE temp0, temp1; void Init_tt() { temp0 = rb_ary_new(); temp1 = rb_ary_new(); /* this variable can be accessed from ruby and C */ rb_define_variable("$tempor", &temp0); /* this variable can be accessed only from C this is to protect it against the GC */ rb_global_variable(&temp1); } In your case you want rb_gv_set(), rb_gv_get() (see p. 197 of the pickaxe) Something like this (not tested) static VALUE newvar(int argc, VALUE *argv, VALUE self) { VALUE temp; temp = rb_ary_new(); rb_ary_push(temp, rb_float_new(3.3)); rb_gv_set("$tempor", temp); return Qnil; } Guy Decoux