av_store() doesn't return success vs. failure. It returns a pointer to
the SV as it shows up within the array itself.

av_store() can be assumed to be successful, as if it were to fail, it
would die().

mark


On Fri, Mar 02, 2001 at 04:39:34PM -0500, "Kort, Eric" wrote:
> Can someone help me understand how to capture the return value of av_store?
> Here is a short snippet illustrating what I am trying to do (in the context
> of a larger procedure wherein the use of av_store actually makes sense):
> 
> void update(SV* svArray)
> {
>   AV* avArray;
>   SV* svNewVal;
>   int iNewVal;
> 
>   avArray = (AV*)SvRV(svArray);
>   iNewVal = 3;
>   svNewVal = newSViv(iNewVal);
>   av_store(avArray, 2, svNewVal);
> }
> 
> This works, but want I want to do is check the return value of av_store, an
> SV**, to make sure it suceeded, and then increment the reference count of
> svNewVal if it did.  I tried something like:
> 
>   SV* *svReturnVal
> 
> and then
> 
>   svReturnVal = av_store(avArray, 2, svNewVal);
> 
> but that produces the error "assignment from incompatible pointer type".
> What is the proper way to capture the return and ensure it is not NULL?
> 
> Thanks,
> Eric
> 
> 
> 
> > -----Original Message-----
> > From: Brian Ingerson [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, January 03, 2001 11:28 AM
> > To: Jeff Walker
> > Cc: '[EMAIL PROTECTED]'; [EMAIL PROTECTED]
> > Subject: Re: make a hash from .xs file
> > 
> > 
> > Jeff Walker wrote:
> > > 
> > > 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:
> > 
> > 8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<
> > 
> > > 
> > > 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} ))
> > 
> > Jeff,
> > Here is script using Inline.pm that does what you want. 
> > 
> > --------------------------8<----------------------------
> > use Inline C => DATA;
> > 
> > $hash_ref = my_new_hash(100);
> > foreach $key (keys %$hash_ref) {
> >     print "$key => $hash_ref->{$key}\n";
> > }
> > 
> > __END__
> > 
> > __C__
> > 
> > SV* my_new_hash(int size) {
> >     int i;
> >     HV* hash = newHV();
> >     for (i = 0; i < size; i++) {
> >         hv_store_ent(hash, newSVpvf("string #%d", i), 
> >                      newSViv(i), 0);
> >     }
> >     return newRV_noinc((SV*) hash);
> > }
> > --------------------------8<----------------------------
> > 
> > You'll need Inline.pm version 0.30. Just run the script. No compiling
> > needed.
> > 
> > If you have any Inline related questions/problems, please post them to
> > [EMAIL PROTECTED]
> > 
> > Brian
> > 
> > -- 
> > perl -le 'use Inline C=>q{SV*JAxH(char*x){return newSVpvf
> > ("Just Another %s Hacker",x);}};print JAxH+Perl'
> > 

-- 
[EMAIL PROTECTED][EMAIL PROTECTED][EMAIL PROTECTED] __________________________
.  .  _  ._  . .   .__    .  . ._. .__ .   . . .__  | SIR Tools          (7H12)
|\/| |_| |_| |/    |_     |\/|  |  |_  |   |/  |_   | Nortel Networks
|  | | | | \ | \   |__ .  |  | .|. |__ |__ | \ |__  | Ottawa, Ontario, Canada

  One ring to rule them all, one ring to find them, one ring to bring them all
                       and in the darkness bind them...

                           http://mark.mielke.cc/

Reply via email to