Running a delegate inside a C function

Chris Cain via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jun 7 13:37:47 PDT 2014


On Saturday, 7 June 2014 at 20:21:26 UTC, Chris Cain wrote:
> On Saturday, 7 June 2014 at 20:04:41 UTC, Denis Martinez via 
> Digitalmars-d-learn wrote:
>>     int ret = jack_set_process_callback(handle_, f, &dg);
>
> &dg here is giving you a pointer to the dg variable sitting on 
> the stack. The stack is almost certainly getting overwritten at 
> some point.

I'll add that to fix the problem, you're going to have to write 
it so that your process_callback function takes either a pointer:

     void process_callback(JackProcessDelegate* dg)

or make it by reference:

     void process_callback(in JackProcessDelegate dg)
     //... or
     void process_callback(ref JackProcessDelegate dg)

But do note that the same problem may apply to the person calling 
it... if they're storing the delegate "structure" on the stack, 
it might also be clobbered in much the same way.

Take care


More information about the Digitalmars-d-learn mailing list