Hi,

Appreciate your response!

In general the flow of my current code is divided to 5 stages(as seen bellow):
1. Create an interpreter (my_perl)
2. Push parameters to the Perl stack (XPUSHs)
3. Call Perl function (call_pv)
4. POP return value (POPi)
5. Destruct the interpreter

Code wise, stages 2 and 4 depends on the existance of 'my_perl' interpreter pointer (XPUSHs and POPi macros are using it).

How can I get a pointer to the interpreter of the Perl function that called the C code? Should I use other macros?


Thanks a lot for your help :)


Itamar


HV* my_hash; AV* my_arr; int retVal = 0; char* my_argv[] = { "", cb->cbFunc.perlCbFunc.fileName }; // PERL interpreter creation my_perl = perl_alloc(); perl_construct( my_perl ); // PERL interpreter initiation perl_parse( my_perl, // The interpreter NULL, // XSINIT value - Should be NULL if no + external modules are being used 2, // Number of entries in 'my_argv' my_argv, // PERL 'command line'. (char **)NULL); // ENV, not relevant for our usage // Run the PERL interpreter perl_run(my_perl); // Call a PERL function dSP; /* Ini +tialize stack pointer */ ENTER; /* Eve +rything created after here */ SAVETMPS; /* ... +is a temporary variable. */ PUSHMARK(SP); /* Rem +ember the stack pointer */ XPUSHs(sv_2mortal(newSViv((unsigned int)cbCtx))); /* Pus +h callback context onto stack */ my_hash = newHV(); my_arr = newAV(); hv_store( my_hash, "aaaaaa", 6, newSViv(1), 0 ); hv_store( my_hash, "bbb", 3, newSViv(2), 0 ); hv_store( my_hash, "cccccccccc", 10, newSViv(3), 0 ); hv_store( my_hash, "ddddddddd", 9, newSViv(4), 0 ); hv_store( my_hash, "eeeeeee", 7, newSViv(5), 0 ); hv_store( my_hash, "ffff", 4, newSViv(6), 0 ); hv_store( my_hash, "gggggg", 6, newSViv(7), 0 ); hv_store( my_hash, "hhhhhhh", 7, newSViv(8), 0 ); for ( int i = 0; i < 50; i++ ) { av_push( my_arr, newSViv((unsigned int)arr[i]) ); } // Store reference to parameters on the HASH hv_store( my_hash, "arr", 6, newRV((SV*)my_arr), 0 ); XPUSHs( sv_2mortal(newRV((SV*)my_hash)) ); PUTBACK; /* Mak +e local stack pointer global */ call_pv( funcName, G_SCALAR ); /* Cal +l the function */ retVal = POPi; /* POP + the return of the PERL function */ SPAGAIN; /* Ref +resh stack pointer */ PUTBACK; FREETMPS; /* fre +e that return value */ LEAVE; /* ... +and the XPUSHed "mortal" args */ // Destruct PERL interpreter perl_destruct(my_perl); perl_free(my_perl);

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.