develooper Front page | perl.perl5.porters | Postings from November 2005

Re: [PATCH] sort/multicall patch

Thread Previous | Thread Next
From:
Robin Houston
Date:
November 4, 2005 07:22
Subject:
Re: [PATCH] sort/multicall patch
Message ID:
20051104152029.GA17169@rpc142.cs.man.ac.uk
On Fri, Nov 04, 2005 at 02:37:27PM -0000, Paul Marquess wrote:
> Regarding the patch - sorry, no joy. It doesn't print the 
> 
>    Sort subroutine didn't return single value
> 
> message anymore, but it still fails. The order of the array elements is
> almost inverted from what was expected.

Oh dear, what an embarrassing mistake! I forgot to copy the result
down to the new top of the stack, and then wrote a test which happened
to pass anyway. Try this patch instead.

Robin

--- pp_ctl.c.orig	2005-11-04 13:31:15.000000000 +0000
+++ pp_ctl.c	2005-11-04 15:15:11.000000000 +0000
@@ -1949,6 +1949,8 @@
 				     * sort block, which is a CXt_NULL
 				     * not a CXt_SUB */
 	    dounwind(0);
+	    PL_stack_base[1] = *PL_stack_sp;
+	    PL_stack_sp = PL_stack_base + 1;
 	    return 0;
 	}
 	else
@@ -1957,8 +1959,16 @@
     if (cxix < cxstack_ix)
 	dounwind(cxix);
 
-    if (CxMULTICALL(&cxstack[cxix]))
+    if (CxMULTICALL(&cxstack[cxix])) {
+	gimme = cxstack[cxix].blk_gimme;
+	if (gimme == G_VOID)
+	    PL_stack_sp = PL_stack_base;
+	else if (gimme == G_SCALAR) {
+	    PL_stack_base[1] = *PL_stack_sp;
+	    PL_stack_sp = PL_stack_base + 1;
+	}
 	return 0;
+    }
 
     POPBLOCK(cx,newpm);
     switch (CxTYPE(cx)) {
--- t/op/sort.t.orig	2005-11-04 13:36:39.000000000 +0000
+++ t/op/sort.t	2005-11-04 15:06:37.000000000 +0000
@@ -5,7 +5,7 @@
     @INC = '../lib';
 }
 use warnings;
-print "1..141\n";
+print "1..143\n";
 
 # these shouldn't hang
 {
@@ -790,3 +790,13 @@
 # Using return() should be okay even in a deeper context
 @b = sort {while (1) {return ($a <=> $b)} } 1..10;
 ok("@b", "1 2 3 4 5 6 7 8 9 10", "return within loop");
+
+# Using return() should be okay even if there are other items
+# on the stack at the time.
+@b = sort {$_ = ($a<=>$b) + do{return $b<=> $a}} 1..10;
+ok("@b", "10 9 8 7 6 5 4 3 2 1", "return with SVs on stack");
+
+# As above, but with a sort sub rather than a sort block.
+sub ret_with_stacked { $_ = ($a<=>$b) + do {return $b <=> $a} }
+@b = sort ret_with_stacked 1..10;
+ok("@b", "10 9 8 7 6 5 4 3 2 1", "return with SVs on stack");

Thread Previous | Thread Next


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