example is better than a long explanation

here goes...

$x = {};
callto_xsub($x)

in the xsub an HV * is created that will be the root for a hash of hashes. i.e.

$x = { key0 => { a => var1, b => var2, }, and so on.
The second level hashs are all created within the xsub with the following code snippet where 'dusr' is the HV for the 'key' for the secondary hash
hv_store(dusr,"C",1,newSVuv(1),0); hv_store(dusr,"B",1,newSVuv(len),0); hv_store(dusr,"E",1,newSVuv(now),0); hv_store(dusr,"T",1,newSVuv(0),0);
subsequently, the key "T" gets updated by a call_sv to a perl routine as follows:
if ((fetch_uv(dusr,"T")) < now) { dSP; PUSHMARK(SP); # trgt.s is the key for HV * dusr XPUSHs(sv_2mortal(newSVpv(trgt.s,4))); PUTBACK; call_sv(myperlsub,G_VOID); } in the perl routine, this instruction is executed $x->{trgt}->{T} = 12345; upon return from the perl call_sv, examination of the contents of the +sub hash vpp = hv_fetch(hp,trgt.s,1,0); value = SvUVX(*vpp); reveals that the contents appear to contain the initalization value ra +ther than 12345. HOWEVER, if the hash is iterated for(itmp = 0; itmp < iend;itmp++) { he = hv_iternext(dusr); ctmp = hv_iterkey(he,&rtmp); ttmp = SvUV(hv_iterval(dusr,he)); fprintf(stderr,"key %s => %d\n",ctmp,ttmp); } The correct value magically appears
So... my question is, how does one get the hash as it appears in the xsub to "update" or whatever is required to see the value that was stored when the call_sv was made to perl space?

please email: Michael@bizsystems.com ############ update Using Devel::Peek, I see what the problem is, but do not know how to fix it.

Upon initializing the sub hash, the values are created as UV's i.e.:

SV = IV(0x8380458) at 0x83b70d8 REFCNT = 1 FLAGS = (IOK,pIOK,IsUV) UV = 0 When the perlsub updates the data it is conveted to an NV SV = PVNV(0x8284298) at 0x83b70d8 REFCNT = 1 FLAGS = (NOK,pNOK) IV = 0 NV = 12345 PV = 0
The question no is how do I coerce perl into storing the value as a UV as I originally intended. The hash of hashes will be large and "doubles" is not what I had in mind ;-)

Michael@bizsystems.com

Edit by GrandFather - replaced pre tags with code tags, to prevent distortion of site layout and allow code extraction.


In reply to updating hash from perl -> xsub by mrobinton

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.