Bill Moseley <[EMAIL PROTECTED]> writes:
>On Fri, 23 Aug 2002, Nick Ing-Simmons wrote:
>> >  XPUSHs(sv_2mortal(newSVpv(StopWords[i],0)));
>> >  XPUSHs(sv_2mortal(newSViv(pv->value.v_int)));
>> 
>> Which is correct. The mortal ness arranges for the values to be free'd 
>> when scope exits.
>
>Trying to understand in simple terms.  I guess I don't understand "mortal"
>very well.
>
>So newSVpv allocates memory for the data, 

Yes.

>and copies it from the source.

Yes.

>Then the sv_2mortal sets the ref count?

No.

A sv_2mortal does two things:
  A. Pushes address of SV onto a "temp stack" of things to be freed.
  B. Sets the SvTEMP flag to allow certain parts of perl core to "cheat".

When you hit a LEAVE macro (exit scope) the temp stack is popped 
until its stack pointer matches the value saved by the matching ENTER.
Each thing popped has SvREFCNT_dec() done on it.

>
>> >  hv_store(indexheader,"IndexFile",9, newSVpv(indexf->line,0),0);
>> >  hv_store(indexheader,"TotalFiles",10,newSViv(indexf->header.totalfiles),0);
>> 
>> Which is also correct - values will be free'd when HV no longer wants 
>> them - but should not be free'd till then.
>
>does hv_store call sv_2mortal on the scalar created?

No. The SV is created with a SvREFCNT of 1. hv_store does not change 
it. However if new values if stored in that slot the _old_ value 
has SvREFCNT_dec called on it.

>
>Clearly, I need to do some reading -- any suggestions?

perlguts.pod is a place to start.

>
>> What is "swish" ?
>
>A search engine first written about '96.  http://swish-e.org
>
>Thanks for your time, Nick.
-- 
Nick Ing-Simmons
http://www.ni-s.u-net.com/

Reply via email to