I greatly appreciate the feedback to try, AnonyMonk!

With the last code, static didn't work, so I removed that. I also initialized a and b. This very slightly modified declaration (yep, I corrected the def as well):

void callback(){ int a = 10; int b = 20; dSP; ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(sv_2mortal(newSViv(a))); XPUSHs(sv_2mortal(newSViv(b))); PUTBACK; call_pv("p_callback", G_DISCARD|G_NOARGS); SPAGAIN; printf("%d to the %dth power is %d.\n", a, b, POPi); PUTBACK; FREETMPS; LEAVE; }

...with the exact same otherwise all around, produces:

in init in perl callback Use of uninitialized value in subroutine entry at c_extern_call_perl.p +l line 11. 10 to the 20th power is -474476032. Segmentation fault

So, callback() is working perfectly on the direct call from the perl code, it still registers ok in the external function, but as soon as the callback is triggered from extern, it breaks, from my estimation, at or before the call to call_pv().

Update: I moved around some comments, and it segfaults on anything following the call to dSP().

Perhaps I'm XY Problem-ing this. Here's what I want...

Am I making sense here? Perhaps I'm thinking this totally wrong. I'm going to keep pounding on this because I know there's got to be a way :) I'm just not experienced enough in all of the cross-language comms, and using XS. I'm having fun though


In reply to Re^4: XS: Passing an external library's function a Perl XS callback by stevieb
in thread SOLVED: XS: Passing an external library's function a Perl XS callback by stevieb

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.