Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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. Thanksvoid 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))); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Need to pass an unsigned char array from an xsub back to Perl
by Eliya (Vicar) on Mar 30, 2012 at 16:30 UTC | |
by Anonymous Monk on Mar 30, 2012 at 17:19 UTC | |
by bulk88 (Priest) on Apr 01, 2012 at 16:57 UTC | |
|
Re: Need to pass an unsigned char array from an xsub back to Perl
by BrowserUk (Patriarch) on Mar 30, 2012 at 16:52 UTC |