develooper Front page | perl.perl5.porters | Postings from May 2004

Re: [PATCH] Document limitations in PUSHi et al macros and add newmPUSHi et al macros

Thread Previous | Thread Next
From:
Marcus Holland-Moritz
Date:
May 3, 2004 11:05
Subject:
Re: [PATCH] Document limitations in PUSHi et al macros and add newmPUSHi et al macros
Message ID:
20040503200328.24efcda5@r2d2
On 2004-04-30, at 12:21:53 +0100, Steve Hay wrote:

> Rafael Garcia-Suarez wrote:
> 
> >Steve Hay wrote:
> >  
> >
> >>The attached patch adds the new macros and documents the limitations of 
> >>the existing macros in perlapi (which therefore needs regenerating).
> >>    
> >>
> >
> >Thanks, applied as #22756.
> >
> >  
> >
> >>One question: Should the new m(X)PUSH[iunp] macros handle 'set' magic?  
> >>Of the existing macros, (X)PUSHs do not, while (X)PUSH[iunp] do.
> >>    
> >>
> >
> >I think that they should mimic the behaviour of the existing macros.
> >
> In that case, what you've just applied isn't quite right!
> 
> As they stand, the new m(X)PUSH[iunp] macros do not handle 'set' magic.  
> The attached patch (against what you just applied) fixes it.

I doubt that _any_ of your macros work. Have you tested them?

[sv.c]

> #define PUSHmortal(s)	PUSHs(sv_newmortal())
> #define mPUSHp(p,l)	STMT_START { sv_setpvn_mg(PUSHmortal, (p), (l)); } STMT_END
> #define mPUSHn(n)	STMT_START { sv_setnv_mg(PUSHmortal, (NV)(n)); } STMT_END
> #define mPUSHi(i)	STMT_START { sv_setiv_mg(PUSHmortal, (IV)(i)); } STMT_END
> #define mPUSHu(u)	STMT_START { sv_setuv_mg(PUSHmortal, (UV)(u)); } STMT_END

The PUSHmortal macro has an argument, but it is called without.
Furthermore, the argument is useless.

> #define XPUSHmortal(s)	STMT_START { EXTEND(sp,1); PUSHmortal; } STMT_END
> #define mXPUSHp(p,l)	STMT_START { sv_setpvn_mg(XPUSHmortal, (p), (l)); } STMT_END
> #define mXPUSHn(n)	STMT_START { sv_setnv_mg(XPUSHmortal, (NV)(n)); } STMT_END
> #define mXPUSHi(i)	STMT_START { sv_setiv_mg(XPUSHmortal, (IV)(i)); } STMT_END
> #define mXPUSHu(u)	STMT_START { sv_setuv_mg(XPUSHmortal, (UV)(u)); } STMT_END

XPUSHmortal, again, has a useless argument. But it's even worse. 
The macro is called as if it had a return value. But since the
code is wrapped in STMT_START/STMT_END, it cannot return anything.

I guess what you wanted to implement is more likely to be something
like this:

--- pp.h.orig   2004-05-03 19:49:13.000000000 +0200
+++ pp.h        2004-05-03 19:56:59.000000000 +0200
@@ -303,17 +303,17 @@
 #define XPUSHu(u)      STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END
 #define XPUSHundef     STMT_START { SvOK_off(TARG); XPUSHs(TARG); } STMT_END
 
-#define PUSHmortal(s)  PUSHs(sv_newmortal())
-#define mPUSHp(p,l)    STMT_START { sv_setpvn_mg(PUSHmortal, (p), (l)); } STMT_END
-#define mPUSHn(n)      STMT_START { sv_setnv_mg(PUSHmortal, (NV)(n)); } STMT_END
-#define mPUSHi(i)      STMT_START { sv_setiv_mg(PUSHmortal, (IV)(i)); } STMT_END
-#define mPUSHu(u)      STMT_START { sv_setuv_mg(PUSHmortal, (UV)(u)); } STMT_END
-
-#define XPUSHmortal(s) STMT_START { EXTEND(sp,1); PUSHmortal; } STMT_END
-#define mXPUSHp(p,l)   STMT_START { sv_setpvn_mg(XPUSHmortal, (p), (l)); } STMT_END
-#define mXPUSHn(n)     STMT_START { sv_setnv_mg(XPUSHmortal, (NV)(n)); } STMT_END
-#define mXPUSHi(i)     STMT_START { sv_setiv_mg(XPUSHmortal, (IV)(i)); } STMT_END
-#define mXPUSHu(u)     STMT_START { sv_setuv_mg(XPUSHmortal, (UV)(u)); } STMT_END
+#define PUSHmortal     PUSHs(sv_newmortal())
+#define mPUSHp(p,l)    sv_setpvn_mg(PUSHmortal, (p), (l))
+#define mPUSHn(n)      sv_setnv_mg(PUSHmortal, (NV)(n))
+#define mPUSHi(i)      sv_setiv_mg(PUSHmortal, (IV)(i))
+#define mPUSHu(u)      sv_setuv_mg(PUSHmortal, (UV)(u))
+
+#define XPUSHmortal    XPUSHs(sv_newmortal())
+#define mXPUSHp(p,l)   STMT_START { EXTEND(sp,1); sv_setpvn_mg(PUSHmortal, (p), (l)); } STMT_END
+#define mXPUSHn(n)     STMT_START { EXTEND(sp,1); sv_setnv_mg(PUSHmortal, (NV)(n)); } STMT_END
+#define mXPUSHi(i)     STMT_START { EXTEND(sp,1); sv_setiv_mg(PUSHmortal, (IV)(i)); } STMT_END
+#define mXPUSHu(u)     STMT_START { EXTEND(sp,1); sv_setuv_mg(PUSHmortal, (UV)(u)); } STMT_END
 
 #define SETs(s)                (*sp = s)
 #define SETTARG                STMT_START { SvSETMAGIC(TARG); SETs(TARG); } STMT_END

However, the code above is __UNTESTED__.

Marcus

-- 
APL is a natural extension of assembler language programming;
...and is best for educational purposes.
		-- A. Perlis

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