mrobinton has asked for the wisdom of the Perl Monks concerning the following question:
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.
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$x = { key0 => { a => var1, b => var2, }, and so on.
subsequently, the key "T" gets updated by a call_sv to a perl routine as follows: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);
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?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
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.:
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 ;-)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
Michael@bizsystems.com
Edit by GrandFather - replaced pre tags with code tags, to prevent distortion of site layout and allow code extraction.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: updating hash from perl -> xsub
by davidrw (Prior) on May 21, 2006 at 04:59 UTC | |
|
Re: updating hash from perl -> xsub
by borisz (Canon) on May 21, 2006 at 09:57 UTC | |
|
Re: updating hash from perl -> xsub
by GrandFather (Saint) on May 21, 2006 at 03:56 UTC | |
by gellyfish (Monsignor) on May 21, 2006 at 08:41 UTC | |
by GrandFather (Saint) on May 21, 2006 at 10:40 UTC |