In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/4c21785fe645f05e6e1a51824029d1cda897d57c?hp=32ed16fc7457f21807774447f05a5db39ea198c7>
- Log ----------------------------------------------------------------- commit 4c21785fe645f05e6e1a51824029d1cda897d57c Merge: 32ed16f 6c48f02 Author: Nicholas Clark <[email protected]> Date: Sat Jul 28 10:11:08 2012 +0200 Merge the refactoring of the filetest OPs' return code. commit 6c48f0257061da372cf9560e38107b0c1c42fa63 Author: Nicholas Clark <[email protected]> Date: Fri Jul 27 16:38:01 2012 +0200 Comment the code with how filetest operators interact with the Perl stack. M pp_sys.c commit 48d023d6dd4655c978fe712c6c3c23f1415bcf04 Author: Nicholas Clark <[email protected]> Date: Fri Jul 27 15:05:00 2012 +0200 Eliminate the macros FT_RETURN_FALSE() and FT_RETURN_TRUE(). As they now simply return the results of S_ft_return_false() and S_ft_return_true() respectively, use this explicitly in the 7 places where the macros had been used. M pp_sys.c commit 07ed4d4bd6e7cc6958b6ea257f2e7cfa1469e279 Author: Nicholas Clark <[email protected]> Date: Fri Jul 27 14:47:56 2012 +0200 Refactor the macro FT_RETURN_TRUE() into the function S_ft_return_true() This makes the true and false code paths as similar as possible. It also eliminates a macro that the HP compiler was choking on. M pp_sys.c commit 9a6b02e88d42f77b2a3c001bd483d8b69cbd3fb7 Author: Nicholas Clark <[email protected]> Date: Fri Jul 27 14:19:27 2012 +0200 Consolidate the code for returning false values from filetest operators. Move the code that implements the non-stacking return processing from the macro FT_RETURN_FALSE() into the static function S_ft_stacking_return_false(). Rename the function to S_ft_return_false() as it now handles all false cases. M pp_sys.c commit 697f9d37ed09fce0b3aa32beadd149fc18cca6e0 Author: Nicholas Clark <[email protected]> Date: Fri Jul 27 13:32:33 2012 +0200 Reorder S_ft_stacking_return_false(). Move the code which deals with setting the return value on perl's stack ahead of the code which calculates which op to run next (the return value of the C function). M pp_sys.c commit d2f677201f78036f37e6a614b0bc4cfa46cf02d8 Author: Nicholas Clark <[email protected]> Date: Fri Jul 27 13:16:29 2012 +0200 Remove dSP from all filetest ops. Following commit d2c4d2d1e22d3125, all filetest ops avoid manipulating the stack pointer until the point of pushing a return value. As all the filetest returns now go through either FT_RETURN_FALSE() or FT_RETURN_TRUE(), it's viable to put the dSP inside those two macros and use *PL_stack_sp in place of TOPs. This eliminates all uses of sp in the bodies of the functions (explicit, or implicit via macros), and that makes it clear that the main bodies of the functions are not manipulating the stack. M pp_sys.c commit 75a8cd125e994761848db7aca480a8aa108078a0 Author: Nicholas Clark <[email protected]> Date: Fri Jul 27 12:54:49 2012 +0200 Replace the macro RETURNX() with its expansion in FT_RETURN_{FALSE,TRUE} The macros FT_RETURN_FALSE and FT_RETURN_TRUE in pp_ctl.c are already very complex, sufficient to trigger an internal failure in HP's compiler [and possibly also some humans :-)]. Replacing RETURNX() with the 3 statements it expands to makes the intent of macros clearer, and exposes more refactoring possibilities. M pp_sys.c ----------------------------------------------------------------------- Summary of changes: pp_sys.c | 80 +++++++++++++++++++++++++++++++------------------------------- 1 files changed, 40 insertions(+), 40 deletions(-) diff --git a/pp_sys.c b/pp_sys.c index 549256b..1cb0403 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -2901,6 +2901,13 @@ PP(pp_stat) RETURN; } +/* All filetest ops avoid manipulating the perl stack pointer in their main + bodies (since commit d2c4d2d1e22d3125), and return using either + S_ft_return_false() or S_ft_return_true(). These two helper functions are + the only two which manipulate the perl stack. To ensure that no stack + manipulation macros are used, the filetest ops avoid defining a local copy + of the stack pointer with dSP. */ + /* If the next filetest is stacked up with this one (PL_op->op_private & OPpFT_STACKING), we leave the original argument on the stack for success, @@ -2909,39 +2916,39 @@ PP(pp_stat) */ static OP * -S_ft_stacking_return_false(pTHX_ SV *ret) { - dSP; +S_ft_return_false(pTHX_ SV *ret) { OP *next = NORMAL; - while (OP_IS_FILETEST(next->op_type) - && next->op_private & OPpFT_STACKED) - next = next->op_next; + dSP; + if (PL_op->op_flags & OPf_REF) XPUSHs(ret); else SETs(ret); PUTBACK; + + if (PL_op->op_private & OPpFT_STACKING) { + while (OP_IS_FILETEST(next->op_type) + && next->op_private & OPpFT_STACKED) + next = next->op_next; + } return next; } -#define FT_RETURN_FALSE(X) \ - STMT_START { \ - if (PL_op->op_private & OPpFT_STACKING) \ - return S_ft_stacking_return_false(aTHX_ X); \ - RETURNX(PL_op->op_flags & OPf_REF ? XPUSHs(X) : SETs(X)); \ - } STMT_END -#define FT_RETURN_TRUE(X) \ - RETURNX((void)( \ - PL_op->op_flags & OPf_REF \ - ? (bool)XPUSHs( \ - PL_op->op_private & OPpFT_STACKING ? (SV *)cGVOP_gv : (X) \ - ) \ - : (PL_op->op_private & OPpFT_STACKING || SETs(X)) \ - )) - -#define FT_RETURNNO FT_RETURN_FALSE(&PL_sv_no) -#define FT_RETURNUNDEF FT_RETURN_FALSE(&PL_sv_undef) -#define FT_RETURNYES FT_RETURN_TRUE(&PL_sv_yes) +PERL_STATIC_INLINE OP * +S_ft_return_true(pTHX_ SV *ret) { + dSP; + if (PL_op->op_flags & OPf_REF) + XPUSHs(PL_op->op_private & OPpFT_STACKING ? (SV *)cGVOP_gv : (ret)); + else if (!(PL_op->op_private & OPpFT_STACKING)) + SETs(ret); + PUTBACK; + return NORMAL; +} + +#define FT_RETURNNO return S_ft_return_false(aTHX_ &PL_sv_no) +#define FT_RETURNUNDEF return S_ft_return_false(aTHX_ &PL_sv_undef) +#define FT_RETURNYES return S_ft_return_true(aTHX_ &PL_sv_yes) #define tryAMAGICftest_MG(chr) STMT_START { \ - if ( (SvFLAGS(TOPs) & (SVf_ROK|SVs_GMG)) \ + if ( (SvFLAGS(*PL_stack_sp) & (SVf_ROK|SVs_GMG)) \ && PL_op->op_flags & OPf_KIDS) { \ OP *next = S_try_amagic_ftest(aTHX_ chr); \ if (next) return next; \ @@ -2951,13 +2958,12 @@ S_ft_stacking_return_false(pTHX_ SV *ret) { STATIC OP * S_try_amagic_ftest(pTHX_ char chr) { dVAR; - dSP; - SV* const arg = TOPs; + SV *const arg = *PL_stack_sp; assert(chr != '?'); if (!(PL_op->op_private & OPpFT_STACKING)) SvGETMAGIC(arg); - if (SvAMAGIC(TOPs)) + if (SvAMAGIC(arg)) { const char tmpchr = chr; SV * const tmpsv = amagic_call(arg, @@ -2967,8 +2973,8 @@ S_try_amagic_ftest(pTHX_ char chr) { if (!tmpsv) return NULL; - if (SvTRUE(tmpsv)) FT_RETURN_TRUE(tmpsv); - FT_RETURN_FALSE(tmpsv); + return SvTRUE(tmpsv) + ? S_ft_return_true(aTHX_ tmpsv) : S_ft_return_false(aTHX_ tmpsv); } return NULL; } @@ -2997,7 +3003,6 @@ PP(pp_ftrread) bool effective = FALSE; char opchar = '?'; - dSP; switch (PL_op->op_type) { case OP_FTRREAD: opchar = 'R'; break; @@ -3061,7 +3066,7 @@ PP(pp_ftrread) if (use_access) { #if defined(HAS_ACCESS) || defined (PERL_EFF_ACCESS) - const char *name = TOPpx; + const char *name = SvPV_nolen(*PL_stack_sp); if (effective) { # ifdef PERL_EFF_ACCESS result = PERL_EFF_ACCESS(name, access_mode); @@ -3099,7 +3104,6 @@ PP(pp_ftis) I32 result; const int op_type = PL_op->op_type; char opchar = '?'; - dSP; switch (op_type) { case OP_FTIS: opchar = 'e'; break; @@ -3141,8 +3145,8 @@ PP(pp_ftis) break; } SvSETMAGIC(TARG); - if (SvTRUE_nomg(TARG)) FT_RETURN_TRUE(TARG); - else FT_RETURN_FALSE(TARG); + return SvTRUE_nomg(TARG) + ? S_ft_return_true(aTHX_ TARG) : S_ft_return_false(aTHX_ TARG); } } @@ -3151,7 +3155,6 @@ PP(pp_ftrowned) dVAR; I32 result; char opchar = '?'; - dSP; switch (PL_op->op_type) { case OP_FTROWNED: opchar = 'O'; break; @@ -3252,7 +3255,6 @@ PP(pp_ftrowned) PP(pp_ftlink) { dVAR; - dSP; I32 result; tryAMAGICftest_MG('l'); @@ -3268,7 +3270,6 @@ PP(pp_ftlink) PP(pp_fttty) { dVAR; - dSP; int fd; GV *gv; char *name = NULL; @@ -3279,7 +3280,7 @@ PP(pp_fttty) if (PL_op->op_flags & OPf_REF) gv = cGVOP_gv; else { - SV *tmpsv = TOPs; + SV *tmpsv = *PL_stack_sp; if (!(gv = MAYBE_DEREF_GV_nomg(tmpsv))) { name = SvPV_nomg(tmpsv, namelen); gv = gv_fetchpvn_flags(name, namelen, SvUTF8(tmpsv), SVt_PVIO); @@ -3308,7 +3309,6 @@ PP(pp_fttty) PP(pp_fttext) { dVAR; - dSP; I32 i; I32 len; I32 odd = 0; @@ -3327,7 +3327,7 @@ PP(pp_fttext) == OPpFT_STACKED) gv = PL_defgv; else { - sv = TOPs; + sv = *PL_stack_sp; gv = MAYBE_DEREF_GV_nomg(sv); } -- Perl5 Master Repository
