develooper Front page | perl.perl5.porters | Postings from August 2001

Re: [PATCH List::Util] Take 2

Thread Previous
From:
Graham Barr
Date:
August 22, 2001 06:43
Subject:
Re: [PATCH List::Util] Take 2
Message ID:
20010822144228.Z7667@pobox.com
On Wed, Aug 22, 2001 at 02:17:25PM +0100, Robin Houston wrote:
> On Wed, Aug 22, 2001 at 01:30:29PM +0100, Graham Barr wrote:
> > Well it costs if it is a 200MB string.
> 
> True. And I don't _think_ it's necessary. I'll take it out.
> 
> > It certaily seems more reasonable to me.
> 
> Gremlins! There are gremlins!
> 
> > > +        SP = newsp;

This is not needed as we are only calling PUSH/POPBLOCK once

> What's that doing there?
> 
> > > +	SvREFCNT_inc(ST(0));
> 
> And that's downright stupid!

Yes, thats a memory leak.

> Okay... *deep breath*
> Without gremlins, without probably-futile mortal_copy'ing.
> Below.

Yes, this looks much better.

Graham.

> --- perl@11626/ext/List/Util/Util.xs	Mon Jul  9 15:10:08 2001
> +++ perl@11660/ext/List/Util/Util.xs	Wed Aug 22 14:02:24 2001
> @@ -163,6 +163,9 @@
>      HV *stash;
>      CV *cv;
>      OP *reducecop;
> +    PERL_CONTEXT *cx;
> +    SV** newsp;
> +    I32 gimme = G_SCALAR;
>      if(items <= 1) {
>  	XSRETURN_UNDEF;
>      }
> @@ -179,6 +182,7 @@
>      SAVETMPS;
>      SAVESPTR(PL_op);
>      ret = ST(1);
> +    PUSHBLOCK(cx, CXt_SUB, SP);
>      for(index = 2 ; index < items ; index++) {
>  	GvSV(agv) = ret;
>  	GvSV(bgv) = ST(index);
> @@ -186,7 +190,8 @@
>  	CALLRUNOPS(aTHX);
>  	ret = *PL_stack_sp;
>      }
> -    ST(0) = ret;
> +    ST(0) = sv_mortalcopy(ret);
> +    POPBLOCK(cx,PL_curpm);
>      XSRETURN(1);
>  }
>  
> @@ -201,6 +206,10 @@
>      HV *stash;
>      CV *cv;
>      OP *reducecop;
> +    PERL_CONTEXT *cx;
> +    SV** newsp;
> +    I32 gimme = G_SCALAR;
> +
>      if(items <= 1) {
>  	XSRETURN_UNDEF;
>      }
> @@ -213,15 +222,18 @@
>      PL_curpad = AvARRAY((AV*)AvARRAY(CvPADLIST(cv))[1]);
>      SAVETMPS;
>      SAVESPTR(PL_op);
> +    PUSHBLOCK(cx, CXt_SUB, SP);
>      for(index = 1 ; index < items ; index++) {
>  	GvSV(PL_defgv) = ST(index);
>  	PL_op = reducecop;
>  	CALLRUNOPS(aTHX);
>  	if (SvTRUE(*PL_stack_sp)) {
>  	  ST(0) = ST(index);
> +          POPBLOCK(cx,PL_curpm);
>  	  XSRETURN(1);
>  	}
>      }
> +    POPBLOCK(cx,PL_curpm);
>      XSRETURN_UNDEF;
>  }
>  
> 

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About