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

Re: [PATCH] sort/multicall patch

Thread Previous | Thread Next
From:
Robin Houston
Date:
November 5, 2005 04:32
Subject:
Re: [PATCH] sort/multicall patch
Message ID:
20051105123143.GB27743@rpc142.cs.man.ac.uk
On Sat, Nov 05, 2005 at 11:58:16AM +0000, Robin Houston wrote:
> I know GCC is cool with it, but is it *guaranteed* to be all right
> to have two variables with the same name defined in the same function?

Well, a quick google doesn't turn up any suggestion that this might
be a problem, so I guess it's fine.

Patch below.

Graham Barr was planning to make a new release of the CPAN
Scalar-List-Utils this weekend, with the MULTICALL changes in.
If he's already done that (with the implicit-cv interface)
then that is a definite complication.

Robin

--- cop.h.orig	2005-11-05 12:05:18.000000000 +0000
+++ cop.h	2005-11-05 12:14:59.000000000 +0000
@@ -729,13 +729,15 @@
 #define dMULTICALL \
     SV **newsp;			/* set by POPBLOCK */			\
     PERL_CONTEXT *cx;							\
-    CV *cv;								\
+    CV *multicall_cv;							\
     OP *multicall_cop;							\
     bool multicall_oldcatch; 						\
     U8 hasargs = 0		/* used by PUSHSUB */
 
-#define PUSH_MULTICALL \
+#define PUSH_MULTICALL(the_cv) \
     STMT_START {							\
+	CV *_nOnclAshIngNamE_ = the_cv;					\
+	CV *cv = _nOnclAshIngNamE_;					\
 	AV* padlist = CvPADLIST(cv);					\
 	ENTER;								\
  	multicall_oldcatch = CATCH_GET;					\
@@ -749,6 +751,7 @@
 	}								\
 	SAVECOMPPAD();							\
 	PAD_SET_CUR_NOSAVE(padlist, CvDEPTH(cv));			\
+	multicall_cv = cv;						\
 	multicall_cop = CvSTART(cv);					\
     } STMT_END
 
@@ -760,8 +763,8 @@
 
 #define POP_MULTICALL \
     STMT_START {							\
-	LEAVESUB(cv);							\
-	CvDEPTH(cv)--;							\
+	LEAVESUB(multicall_cv);						\
+	CvDEPTH(multicall_cv)--;					\
 	POPBLOCK(cx,PL_curpm);						\
 	CATCH_SET(multicall_oldcatch);					\
 	LEAVE;								\
--- pod/perlcall.pod.orig	2005-11-05 12:15:13.000000000 +0000
+++ pod/perlcall.pod	2005-11-05 12:16:32.000000000 +0000
@@ -1899,14 +1899,12 @@
 
 The pattern of macro calls is like this:
 
-    dMULTICALL;			/* Declare variables (including 'CV* cv') */
+    dMULTICALL;			/* Declare local variables */
     I32 gimme = G_SCALAR;	/* context of the call: G_SCALAR,
 				 * G_LIST, or G_VOID */
 
-    /* Here you must arrange for 'cv' to be set to the CV of
-     * the sub you want to call. */
-
-    PUSH_MULTICALL;		/* Set up the calling context */
+    PUSH_MULTICALL(cv);		/* Set up the context for calling cv,
+				   and set local vars appropriately */
 
     /* loop */ {
         /* set the value(s) af your parameter variables */
--- ext/List/Util/Util.xs.orig	2005-11-05 12:07:29.000000000 +0000
+++ ext/List/Util/Util.xs	2005-11-05 12:17:27.000000000 +0000
@@ -243,12 +243,13 @@
     HV *stash;
     I32 gimme = G_SCALAR;
     SV **args = &PL_stack_base[ax];
+    CV *cv;
 
     if(items <= 1) {
 	XSRETURN_UNDEF;
     }
     cv = sv_2cv(block, &stash, &gv, 0);
-    PUSH_MULTICALL;
+    PUSH_MULTICALL(cv);
     agv = gv_fetchpv("a", TRUE, SVt_PV);
     bgv = gv_fetchpv("b", TRUE, SVt_PV);
     SAVESPTR(GvSV(agv));
@@ -277,12 +278,13 @@
     HV *stash;
     I32 gimme = G_SCALAR;
     SV **args = &PL_stack_base[ax];
+    CV *cv;
 
     if(items <= 1) {
 	XSRETURN_UNDEF;
     }
     cv = sv_2cv(block, &stash, &gv, 0);
-    PUSH_MULTICALL;
+    PUSH_MULTICALL(cv);
     SAVESPTR(GvSV(PL_defgv));
 
     for(index = 1 ; index < items ; index++) {
--- ext/List/Util/multicall.h.orig	2005-11-05 12:17:38.000000000 +0000
+++ ext/List/Util/multicall.h	2005-11-05 12:24:41.000000000 +0000
@@ -86,7 +86,7 @@
 #define dMULTICALL \
     SV **newsp;			/* set by POPBLOCK */			\
     PERL_CONTEXT *cx;							\
-    CV *cv;								\
+    CV *multicall_cv;							\
     OP *multicall_cop;							\
     bool multicall_oldcatch;						\
     U8 hasargs = 0
@@ -109,40 +109,41 @@
 #else
 #  define PUSHSUB_RETSTACK(cx) cx->blk_sub.retop = Nullop;
 #endif
-#undef PUSHSUB
-#define PUSHSUB(cx)                                                     \
-        cx->blk_sub.cv = cv;                                            \
-        cx->blk_sub.olddepth = CvDEPTH(cv);                             \
-        cx->blk_sub.hasargs = hasargs;                                  \
-        cx->blk_sub.lval = PL_op->op_private &                          \
+#define MULTICALL_PUSHSUB(cx, cv)							\
+        cx->blk_sub.cv = cv;						\
+        cx->blk_sub.olddepth = CvDEPTH(cv);				\
+        cx->blk_sub.hasargs = hasargs;					\
+        cx->blk_sub.lval = PL_op->op_private &				\
                               (OPpLVAL_INTRO|OPpENTERSUB_INARGS);	\
 	PUSHSUB_RETSTACK(cx)						\
-        if (!CvDEPTH(cv)) {                                             \
-            (void)SvREFCNT_inc(cv);                                     \
-            (void)SvREFCNT_inc(cv);                                     \
-            SAVEFREESV(cv);                                             \
+        if (!CvDEPTH(cv)) {						\
+            (void)SvREFCNT_inc(cv);					\
+            (void)SvREFCNT_inc(cv);					\
+            SAVEFREESV(cv);						\
         }
 
-#define PUSH_MULTICALL \
+#define PUSH_MULTICALL(the_cv) \
     STMT_START {							\
-	AV* padlist = CvPADLIST(cv);					\
+	CV *_nOnclAshIngNamE_ = the_cv;					\
+	AV* padlist = CvPADLIST(_nOnclAshIngNamE_);			\
+	multicall_cv = _nOnclAshIngNamE_;				\
 	ENTER;								\
  	multicall_oldcatch = CATCH_GET;					\
-	SAVESPTR(CvROOT(cv)->op_ppaddr);				\
-	CvROOT(cv)->op_ppaddr = PL_ppaddr[OP_NULL];			\
+	SAVESPTR(CvROOT(multicall_cv)->op_ppaddr);			\
+	CvROOT(multicall_cv)->op_ppaddr = PL_ppaddr[OP_NULL];		\
 	SAVETMPS; SAVEVPTR(PL_op);					\
 	CATCH_SET(TRUE);						\
 	PUSHSTACKi(PERLSI_SORT);					\
 	PUSHBLOCK(cx, CXt_SUB, PL_stack_sp);				\
-	PUSHSUB(cx);							\
-	if (++CvDEPTH(cv) >= 2) {					\
+	MULTICALL_PUSHSUB(cx, multicall_cv);				\
+	if (++CvDEPTH(multicall_cv) >= 2) {				\
 	    PERL_STACK_OVERFLOW_CHECK();				\
-	    multicall_pad_push(aTHX_ padlist, CvDEPTH(cv));		\
+	    multicall_pad_push(aTHX_ padlist, CvDEPTH(multicall_cv));	\
 	}								\
 	SAVECOMPPAD();							\
-	PL_comppad = (AV*) (AvARRAY(padlist)[CvDEPTH(cv)]);		\
+	PL_comppad = (AV*) (AvARRAY(padlist)[CvDEPTH(multicall_cv)]);	\
 	PL_curpad = AvARRAY(PL_comppad);				\
-	multicall_cop = CvSTART(cv);					\
+	multicall_cop = CvSTART(multicall_cv);				\
     } STMT_END
 
 #define MULTICALL \
@@ -153,8 +154,8 @@
 
 #define POP_MULTICALL \
     STMT_START {							\
-	CvDEPTH(cv)--;							\
-	LEAVESUB(cv);							\
+	CvDEPTH(multicall_cv)--;					\
+	LEAVESUB(multicall_cv);						\
 	POPBLOCK(cx,PL_curpm);						\
 	POPSTACK;							\
 	CATCH_SET(multicall_oldcatch);					\

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