From: Edwin Van leeuwen Date: 2007-11-06T05:08:17+09:00 Subject: Re: Pulseaudio c extension callback function Paul Brannan wrote: > 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; > Thanks, it worked when I changed it to: VALUE obj = (VALUE) klass; Otherwise I got a compile error. I really should refresh my c, because clearly my approach of changing the code until it stops segvaulting is not the best :) Although it seems to give me decent progress :) > 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. Yes, I am already using the unref function for the context itself. I am not sure if that also unregisters the callback. I guess I should be testing that later. Edwin -- Posted via http://www.ruby-forum.com/.