in reply to Re^8: 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?

Under the hood, dTHX relies on Perl_get_context() to retrieve the context, so they are mostly equivalents.

It occurs to me that it may be related to the way thread local storage (TLS) is managed on Windows, maybe it is not shared between DLLs.

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

Replies are listed 'Best First'.
Re^10: 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 14:46 UTC

    Hi,

    The system works under CYGWIN.

    It seemed to me that I should pass the Perl interpreter pointer from the Perl script itself to the C DLL. Can you please hint me about how to do it?


    Many thanks,

    Itamar

      Sure, you start the argument declarations for your C function prototypes with pTHX/pTHX_, and then pass then as the first argument aTHX/aTHX_. For instance:
      /* Your C function declarations */ int foo(pTHX) { ... } int bar(pTHX_ int a) { ... } /* In your XS code */ int foo_result = foo(aTHX); int bar_result = bar(aTHX_ 21);

        Hi,

        Thanks for your responses!

        We use WIN32::API module to load the C DLL functions. I don't understand where should I use the code you have suggested. Please forgive me for trivial questions... I'm a FW guy, and in my first steps of learning the Perl guts.


        Thanks!

        Itamar