* A couple of questions on writing extensions
@ 2002-07-25 21:09 Matthew Bloch
2002-07-25 22:38 ` Matthew Bloch
2002-07-26 0:56 ` nobu.nokada
0 siblings, 2 replies; 4+ messages in thread
From: Matthew Bloch @ 2002-07-25 21:09 UTC (permalink / raw
To: ruby-core
*) 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: A couple of questions on writing extensions
2002-07-25 21:09 A couple of questions on writing extensions Matthew Bloch
@ 2002-07-25 22:38 ` Matthew Bloch
2002-07-26 0:56 ` nobu.nokada
1 sibling, 0 replies; 4+ messages in thread
From: Matthew Bloch @ 2002-07-25 22:38 UTC (permalink / raw
To: ruby-core
On Thursday 25 July 2002 22:09, Matthew Bloch wrote:
> *) 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.
A bit more information: if I put a "print key.type" statement before & after
this line, I see "String" twice, as expected, and the bug disappears and pops
up at another point in the program, later on in the execution. I realise
you've got to be careful writing native language extensions, but this is
pretty weird :)
--
Matthew > http://www.soup-kitchen.net/
> ICQ 19482073
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: A couple of questions on writing extensions
2002-07-25 21:09 A couple of questions on writing extensions Matthew Bloch
2002-07-25 22:38 ` Matthew Bloch
@ 2002-07-26 0:56 ` nobu.nokada
2002-07-26 3:22 ` Matthew Bloch
1 sibling, 1 reply; 4+ messages in thread
From: nobu.nokada @ 2002-07-26 0:56 UTC (permalink / raw
To: ruby-core
Hi,
At Fri, 26 Jul 2002 06:09:35 +0900,
Matthew Bloch wrote:
> *) what does 'Died with exception wrong argument type Object (expected Data)'
> mean?
Literally, you passed something else to the method expecting
Data.
> 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.
I vote GC issue. How do you define mark/free functions for
Data_{Make,Wrap}_Struct? Could you show us the source?
> *) Is this kind of construct safe as the end of a bog-standard native accessor
> method? :
Yes.
> 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?
While it is referred by `self', never collected.
> *) is this a correct way to call back a method implemented in class derived
> from a C extension class? :
Yes.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: A couple of questions on writing extensions
2002-07-26 0:56 ` nobu.nokada
@ 2002-07-26 3:22 ` Matthew Bloch
0 siblings, 0 replies; 4+ messages in thread
From: Matthew Bloch @ 2002-07-26 3:22 UTC (permalink / raw
To: ruby-core
On Friday 26 July 2002 01:56, nobu.nokada@softhome.net wrote:
> > 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.
>
> I vote GC issue. How do you define mark/free functions for
> Data_{Make,Wrap}_Struct? Could you show us the source?
You're right, I think it was a misunderstanding with the mark/free functions
specified by Data_Wrap_Struct. I assumed they were passed VALUEs whereas in
fact they're passed pointers to your data structure (you have to look at one
of the examples in the source, ext/stringio to find this out; it's not
explicit in README.EXT nor the pickaxe book). As it happened, the program
continued as normal for a while but presumably a piece of memory got doubly
allocated to cause these weird effects. Anyhow, it's all sorted now; thanks
for the push in the right direction.
--
Matthew > http://www.soup-kitchen.net/
> ICQ 19482073
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-07-26 3:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-07-25 21:09 A couple of questions on writing extensions Matthew Bloch
2002-07-25 22:38 ` Matthew Bloch
2002-07-26 0:56 ` nobu.nokada
2002-07-26 3:22 ` Matthew Bloch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).