Here is my xs routine
void GenerateSessionID(session_id) SV *session_id PREINIT: char *array = ""; STRLEN len; session_id = NULL; PPCODE: len = 17; session_id = newSVpvn(array,17); //allocating memory 16 + 1 +for null if(!SvPOK(session_id)){ XSRETURN_UNDEF; } sv_setpvn(session_id, "\0",len); //Intializing it to NULL? Don +'t know if this wrks array = SvPV(session_id,len); /*convert the scalar into a c +har*/ if(XSessionID((uuid_t*)array)){ //uuid is unsigned char[16] EXTEND(SP,17); PUSHs(sv_2mortal(newSVpv((char*)array,(int)len))); }
When I call the function in Perl as $result  = GenerateSessionID(\$uuid), I try printing result, and I get garbage. Contents of array in xsub look like [ ea 01 e8 b8 79 ed 11 e1 a7 31 00 0c 29 be c3 da ]. My question, is that how do I access this unsigned char when pushed onto the stack in perl? The memory allocated will be freed in a CloseSession call(). I would really appreciate your help. Thanks

In reply to Need to pass an unsigned char array from an xsub back to Perl by Anonymous Monk

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.