Sean O'Dell <sean / celsoft.com> [2004-07-30 16:42]:
> On Friday 30 July 2004 07:06, Tilman Sauerbeck wrote:
> > [C code]
> > It's pretty straight-forward and the comment should explain it all :)
> 
> Show me a couple more things.  Show me the Ruby code you call, and tell me 
> what object is getting collected and where it happens.  Your original Ruby 
> code example was pseudocode and I can't tell what maps to what.

Anyway, here's the script:

class Basic
	def initialize
		@xc = XmmsClient::XmmsClient::new
		@xc.connect
		@xc.setup_with_ecore # attach to the main loop, see below

		@xc.playlist_current_id.notifier do |r|
			puts "now playing #{r.uint}" # gets the ID from a result
			r.restart # call the block the next time the event gets
			          # fired
			GC.start
		end

		@xc.playback_playtime.notifier do |r|
			r.restart
			GC.start
		end
	end
end

x = Basic::new
Ecore::main_loop_begin

The 2nd block is continously prints the current playtime of a track.
The first block prints the ID of the current track on track changes.

The segfault occurs when the first block is executed for the 2nd time 
(at this point, the 2nd block has been executed several times already).

Here's the valgrind log:

CREATED result: 0x1bc194e0 /* result for the playlist_current_id */
CREATED result: 0x1bc1b178 /* result for playback_playtime */
now playing: 5
FREED result: 0x1bc1b178
FREED result: 0x1bc194e0
==2096== Invalid read of size 4
==2096==    at 0x1B9A6D94: st_lookup (st.c:258)
==2096==    by 0x1B93510F: search_method (eval.c:378)
==2096==    by 0x1B935185: rb_get_method_body (eval.c:399)
==2096==    by 0x1B94167F: rb_call (eval.c:5263)
==2096==    by 0x1B941A05: rb_funcall (eval.c:5352)
==2096==    by 0x1B909BE6: on_signal (rb_result.c:107)

So both objects are freed and thus, res->callback is claimed too.

-- 
Regards,
Tilman