I am trying to build a hash from an .xs file, then return a ref to that hash
to the perl code. I figured out how pass the hash back using a reference,
but when I get the hash back, all the keys exist, but all the values are
undefined. Here is some stripped down code that illustrates this:
SV *
Blah()
PREINIT:
HV * h;
int i;
char name[100];
SV **ssv;
SV *svval;
CODE:
h = newHV(); /* allocate new hash */
RETVAL = newRV_inc( (SV *) h ); /* return a ref to the hash */
SvREFCNT_dec( h ); /* free the hash whenever the ref is gone */
for ( i = 0 ; i < 100 ; i++ ) {
/* make the new scalar value which will be the value */
svval = newSViv( i );
/* make the string that will be the key */
sprintf( name, "%d", i );
ssv = hv_store( h, name, strlen( name ), svval, 0 );
if ( ssv == NULL ) {
croak( "oops: key %s not stored", name );
}
}
OUTPUT:
RETVAL
The perl program (which of course uses the module) get the ref returned by
Blah. I then print the keys of this hash and everything is okay. Then I
try to see the values (foreach $thing ( keys( %$hash ) ) ) but they are all
not defined (via ! defined($hash{$thing} ))
I tried incrementing the ref count of svval (I thought maybe adding it to
the hash didn't increase the ref count for the scalar).
I also have a different problem that isn't exposed in this example. I am
making a module from a c++ object, so am having to statically link a new
perl. When I do this, stuff like the above happens (undefined hash values)
but then perl never exits at the end of the script. and perfmeter tells me
that CPU usage goes to 100% on a CPU. I kill perl with SIGINT and
everything is fine. I assume that this has something to do with garbage
collection, maybe some bad ref counts? I can't reproduce it with a small
program (although it happens every time with the big one), so I don't expect
too much, but maybe someone else has heard of that?
Thanks in advance.
--
Jeff Walker MatchLogic, Inc.
[EMAIL PROTECTED] 7233 Church Ranch Blvd.
Voice 1 (303) 222-2105 Westminster, CO 80021
Fax 1 (303) 222-2001 www.matchlogic.com