T
thierry wilmot
hello,
I have experiencing a quite strange thing when I tried to
convert my ruby embedded prog from 1.6.8 to 1.8.0
in 1.6.8, all my structs/classes where wrapped this way:
rb_define_method(rb_foo, "create", (RUBY_FUN_REF)foo_create, 0);
static VALUE foo_create(VALUE self)
{
foo *ptr = new foo(self);
rb_iv_set(self, "ruby2cpp__", INT2FIX(ptr));
VALUE obj = Data_Wrap_Struct(self, 0, cb_destroy_foo, ptr);
}
when I link my prog with the new 1.8.0 lib, cb_destroy_foo()
is called even when the Ruby wrapped object is still valid !!!!
(too many changes in gc.c from 1.6.8...)
after many seek, my code should be this way to works fine in 1.8.0 :
// add two methods
rb_define_singleton_method(rb_foo, "new", (RUBY_FUN_REF)foo_new, 0);
rb_define_method(rb_foo, "initialize", (RUBY_FUN_REF)foo_initialize, 1);
static VALUE foo_new(VALUE self)
{
VALUE argv[1];
foo *ptr = new foo(self);
VALUE obj = Data_Wrap_Struct(self, 0, cb_destroy_foo, ptr);
argv[0] = INT2FIX(ptr);
rb_obj_call_init(obj, 1, argv);
return obj;
}
static VALUE foo_initialize(VALUE self, VALUE init)
{
rb_iv_set(self, "ruby2cpp__", init);
return self;
}
why should I 'overload' new and initialize in 1.8.0, and expand
my 3 code lignes to so much lines !!
thanks,
Thierry
I have experiencing a quite strange thing when I tried to
convert my ruby embedded prog from 1.6.8 to 1.8.0
in 1.6.8, all my structs/classes where wrapped this way:
rb_define_method(rb_foo, "create", (RUBY_FUN_REF)foo_create, 0);
static VALUE foo_create(VALUE self)
{
foo *ptr = new foo(self);
rb_iv_set(self, "ruby2cpp__", INT2FIX(ptr));
VALUE obj = Data_Wrap_Struct(self, 0, cb_destroy_foo, ptr);
}
when I link my prog with the new 1.8.0 lib, cb_destroy_foo()
is called even when the Ruby wrapped object is still valid !!!!
(too many changes in gc.c from 1.6.8...)
after many seek, my code should be this way to works fine in 1.8.0 :
// add two methods
rb_define_singleton_method(rb_foo, "new", (RUBY_FUN_REF)foo_new, 0);
rb_define_method(rb_foo, "initialize", (RUBY_FUN_REF)foo_initialize, 1);
static VALUE foo_new(VALUE self)
{
VALUE argv[1];
foo *ptr = new foo(self);
VALUE obj = Data_Wrap_Struct(self, 0, cb_destroy_foo, ptr);
argv[0] = INT2FIX(ptr);
rb_obj_call_init(obj, 1, argv);
return obj;
}
static VALUE foo_initialize(VALUE self, VALUE init)
{
rb_iv_set(self, "ruby2cpp__", init);
return self;
}
why should I 'overload' new and initialize in 1.8.0, and expand
my 3 code lignes to so much lines !!
thanks,
Thierry