in reply to Re^2: XS callback to mpv_set_wakeup_callback
in thread XS callback to mpv_set_wakeup_callback
The callback data and the reference to the perl function was saved in a global perl variable in Simple.pm, before the xs function is called (this was similarly effectiv as the complex MY_CTX stuff). The XS function is:void callp( ) { int new_perl = 0; dTHX; if ( my_perl != NULL ) printf ("my_perl == %ul\n", my_perl); else { printf ("my_perl was NULL\n"); PERL_SET_CONTEXT(mine); perl_for_cb = perl_clone(mine, CLONEf_KEEP_PTR_TABLE); PERL_SET_CONTEXT(perl_for_cb); // The following seems not necessary //CLONE_PARAMS clone_param; clone_param.stashes = NULL; clone +_param.flags = 0; clone_param.proto_perl = perl_for_cb; new_perl = 1; } dSP; SV* callback = get_sv("MPV::Simple::callback",0); SV* data = get_sv("MPV::Simple::callback_data",0); ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP,1); PUSHs(sv_2mortal(newSVsv(data))); PUTBACK; perl_call_sv(callback,G_DISCARD); SPAGAIN; PUTBACK;FREETMPS;LEAVE; // I don't know whether this is important if ( new_perl ) { perl_free(my_perl); PERL_SET_CONTEXT(mine); } }
Unfortunately in more complex examples there are sometimes new segfaults, sometimes it works smoothly. I think the problem is the complex structure of the thread for event handling in mpv. If someone has a further idea to implement this all in perl, it would be great. I am still interested in learning and understanding XS more... Thanks all, Maxvoid _xs_set_wakeup_callback(MPV::Simple ctx, SV* callback) CODE: { void (*callp_ptr)(void*); callp_ptr = callp; mpv_set_wakeup_callback(ctx,callp_ptr,NULL); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: XS callback to mpv_set_wakeup_callback
by dave_the_m (Monsignor) on Jan 09, 2019 at 14:30 UTC | |
by MaxPerl (Acolyte) on Jan 18, 2019 at 12:05 UTC | |
by MaxPerl (Acolyte) on Jan 09, 2019 at 19:15 UTC |