Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hello, all

I have a problem with memory reallocation when using a Perl interpreter embeded in my application. (I use few interpreters in few threads. For each interpreter exists its own thread.)

It seems that if we create more than one interpreter we must delete them all at one place.

Flat example:
0: 1: int main(int argc, char **argv) 2: { 3: PerlInterpreter *one_perl, *two_perl; 4: char *one_args[] = { "one_perl", "-e", "print qq(Hi, I'm $^X\n +)" }; 5: char *two_args[] = { "two_perl", "-e", "print qq(Hi, I'm $^X\n +)" }; 6: 7: PERL_SYS_INIT3(&argc,&argv,&env); 8: one_perl = perl_alloc(); 9: 10: PERL_SET_CONTEXT(one_perl); 11: perl_construct(one_perl); 12: 13: PERL_SET_CONTEXT(one_perl); 14: perl_parse(one_perl, NULL, 3, one_args, (char **)NULL); 15: 16: PERL_SET_CONTEXT(one_perl); 17: perl_run(one_perl); 18: 19: PERL_SET_CONTEXT(one_perl); 20: perl_destruct(one_perl); 21: 22: PERL_SET_CONTEXT(one_perl); 23: perl_free(one_perl); 24: 25: two_perl = perl_alloc(); 26: PERL_SET_CONTEXT(two_perl); 27: perl_construct(two_perl); 28: PERL_SET_CONTEXT(two_perl); 29: perl_parse(two_perl, NULL, 3, two_args, (char **)NULL); 30: PERL_SET_CONTEXT(two_perl); 31: perl_run(two_perl); 32: //PERL_SET_CONTEXT(one_perl); 33: //perl_free(one_perl); 34: PERL_SET_CONTEXT(two_perl); 35: perl_destruct(two_perl); 36: PERL_SET_CONTEXT(two_perl); 37: perl_free(two_perl); 38: 39: PERL_SYS_TERM(); 40: 41: return 0; 42:}

Exception is thrown in 29 line. If we comment 22, 23 line and uncomment 32 and 33 lines, then all will be OK.

Questions: Please, point me to error in the code or propose method to delete interpreters separately.

In reply to perl_free problem by iladyko_vision

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (5)
    As of 2021-03-08 19:44 GMT
    Find Nodes?
      Voting Booth?
      My favorite kind of desktop background is:

      Results (127 votes). Check out past polls.