Ok, I found https://www.perlmonks.org/?node_id=867652 and without studying the thread in depth, I tried the following and it seems to work so far:
first ein deleteted
#define PERL_NO_GET_CONTEXT in the beginning of my Simple.xs file.
then I created a set_ctx function
void set_ctx()
{
dTHX;
mine = Perl_get_context;
}
(...)
MODULE = MPV::Simple PACKAGE = MPV::Simple
(...)
void
_set_context(ctx)
MPV::Simple ctx
CODE:
set_ctx();
and called it in the constructor in Simple.pm
sub new {
my ($class) = shift;
my $obj = $class->xs_create();
bless $obj;
$obj->_set_context();
return $obj;
}
Last I set Perl_Context in callp instead of dTHX:
void callp( SV* data)
{
//dTHX;
PERL_SET_CONTEXT(mine);
{
dMY_CXT;
dSP;
ENTER; SAVETMPS;
PUSHMARK(SP);
PUTBACK;
perl_call_sv(MY_CXT.callback,G_DISCARD|G_NOARGS);
SPAGAIN;
PUTBACK;FREETMPS;LEAVE;
}
}
Does that make any sense? Or is it ugly and bad? To be honest, I don't really understand the linked thread :-) And I am a little bit worried because of deleting PERL_NO_GET_CONTEXT..
I have to do further tests, whether the binding now works as expected..
Max
UPDATE:
Unfortunately this doesn't work, too. Sometimes it seems to work and the video is shown. But in other cases there is again the segfault or the thread is closed too early.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.