On Tue, Nov 06, 2007 at 02:25:29AM +0900, Edwin Van leeuwen wrote: > static void > callback( pa_context *c, void *klass ) > { > VALUE obj; > obj = * (VALUE *) klass; > rb_funcall( obj, rb_intern( "status=" ), 1, INT2NUM(2) ); > } > > static VALUE > cContext_connect( VALUE klass ) > { > pa_context_set_state_callback( DATA_PTR( klass ), callback, &klass ); klass is a temporary variable; you probably don't want to take its address. Instead you can cast klass to a pointer: pa_context_set_state_callback( DATA_PTR( klass ), callback, (void *)klass ); then in your callback function, write: VALUE obj = (VALUE *) klass; > pa_context_connect(DATA_PTR( klass ), NULL, 0, NULL); > return klass; > } > > but then I got the following error: > NoMethodError: undefined method `status=' for > PulseAudio::Mainloop:0xb79ac9ac> > (I have no clue where this mainloop object comes from, except that it is > ofcourse the mainloop that will call the callback function) > > Also I have the feeling this could introduce problems with the GC > cleaning up my context object, because officialy it's not referenced > anymore (but I'm reasonably clueless about memory management and > pointers etc). If I understand your question, when the context object is destroyed, you need to unregister the callback. That will ensure that the library doesn't keep a reference to the freed object. You can do this by passing a `free' function to Data_Wrap_Struct. > Does anyone have any pointers for me :) ? Other than the pointers to object you've already created? :) Paul