in reply to Re^2: Perl calls C calls Perl CallBack: How Perl callback use the same interpreter/context as Perl caller?
in thread Perl calls C calls Perl CallBack: How Perl callback use the same interpreter/context as Perl caller?

I think that basically you will have to make my_perl a global variable so that it is available everywhere. You could also pass the information through Perl as an integer (SvIV), but that makes for a horribly brittle design.

  • Comment on Re^3: Perl calls C calls Perl CallBack: How Perl callback use the same interpreter/context as Perl caller?
  • Download Code

Replies are listed 'Best First'.
Re^4: Perl calls C calls Perl CallBack: How Perl callback use the same interpreter/context as Perl caller?
by itamarat (Acolyte) on Jul 08, 2014 at 10:56 UTC

    Hi,

    Is there a Perl syntax for getting interpreter pointer?

    Making my_perl global will require a new compilation of the Perl LIB (perl514.lib).


    Thanks,

    Itamar

      Is there a Perl syntax for getting interpreter pointer?

      You can pass it around from XS to C using the pTHX and aTHX (and pTHX_ and pTHX_) macros. Another option is to retrieve the current Perl interpreter calling Perl_get_context(). It is more or less explained on perlguts.

      Also, search CPAN for code containing call_sv and see how others have done it!

        Hi,

        Perl_get_context() is returning NULL.

        That leaves me with passing Perl interpreter pointer directly from Perl to C and then use it when calling the Perl callback, right?

        Can you please give a hint of how should it be done?


        Many thanks,

        Itamar

      I thought that my_perl was a variable in your C code, but I now realize that your C code gets called from Perl. I don't find a convenient way in perlguts, perlapi or perlcall, but maybe you don't even need special things like passing the Perl interpreter around as the current Perl interpreter already is a global variable.