From: Matthew Bloch Date: 2002-07-26T06:09:35+09:00 Subject: A couple of questions on writing extensions *) what does 'Died with exception wrong argument type Object (expected Data)' mean? Isn't everything an object? Since converting a Ruby class to C for performance reasons, while debugging, I've this exception raised at random points in my program, e.g. reported as being thrown from the fairly innocuous: key.gsub!(/\//, File::SEPARATOR) which is nothing to do with my converted class, but the error implies 'key' is somehow corrupt or of the wrong type, where the same code worked before. This exception seems to be thrown from different points depending on timing (though more often than not in a simple call to a logger), which is pretty difficult to track down. *) Is this kind of construct safe as the end of a bog-standard native accessor method? : static VALUE rb_Overlay_pos_read(VALUE self) { Overlay *ov; Data_Get_Struct(self, Overlay, ov); return rb_Rect_new(Overlay_Rect_class, INT2NUM(ov->position.tl.x), INT2NUM(ov->position.tl.y), INT2NUM(ov->position.br.x), INT2NUM(ov->position.br.y)); } i.e. constructing a temporary object with the same value as the one inquired about? Might it be garbage collected before being read by the Ruby caller? Will it be garbage-collected when the result goes out of context in the calling Ruby method? *) is this a correct way to call back a method implemented in class derived from a C extension class? : static void rb_paint_callback(Overlay *ov, void *arg, Rect *r) { VALUE rubyrect = rb_Rect_new(Overlay_Rect_class, INT2NUM(r->tl.x), INT2NUM(r->tl.y), INT2NUM(r->br.x), INT2NUM(r->br.y)); rb_funcall(ov->ruby, rb_intern("paint"), 2, (VALUE) arg, rubyrect); } thanks, -- Matthew > http://www.soup-kitchen.net/ > ICQ 19482073