This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
macroise op_sibling in Perl_ck_fun()
authorDavid Mitchell <davem@iabyn.com>
Tue, 10 Jun 2014 15:34:16 +0000 (16:34 +0100)
committerDavid Mitchell <davem@iabyn.com>
Tue, 8 Jul 2014 15:40:03 +0000 (16:40 +0100)
This is logically part of the previous commit, but since Perl_ck_fun()
took the address of o->op_sibling, it wasn't straightforward to simply
replace op_sibling with the relevant macros. So we now do it as a separate
commit.

It's basically trying to insert a new op into the sibling chain, and
depending on whether it inserts at the front or not, it updates
&cLISTOPo->op_first or &kid->op_sibling.

Rather than taking the address, make each assignment check whether the
destination is op_first or op_sibling. Slightly less elegant, but hey, it
works!

op.c

diff --git a/op.c b/op.c
index ab03c30..f0bd58b 100644 (file)
--- a/op.c
+++ b/op.c
@@ -8625,7 +8625,7 @@ Perl_ck_fun(pTHX_ OP *o)
     }
 
     if (o->op_flags & OPf_KIDS) {
-        OP **tokid = &cLISTOPo->op_first;
+        OP *prev_kid = NULL;
         OP *kid = cLISTOPo->op_first;
         OP *sibl;
         I32 numargs = 0;
@@ -8634,7 +8634,7 @@ Perl_ck_fun(pTHX_ OP *o)
        if (kid->op_type == OP_PUSHMARK ||
            (kid->op_type == OP_NULL && kid->op_targ == OP_PUSHMARK))
        {
-           tokid = &kid->op_sibling;
+           prev_kid = kid;
            kid = OP_SIBLING(kid);
        }
        if (kid && kid->op_type == OP_COREARGS) {
@@ -8650,8 +8650,13 @@ Perl_ck_fun(pTHX_ OP *o)
 
        while (oa) {
            if (oa & OA_OPTIONAL || (oa & 7) == OA_LIST) {
-               if (!kid && !seen_optional && PL_opargs[type] & OA_DEFGV)
-                   *tokid = kid = newDEFSVOP();
+               if (!kid && !seen_optional && PL_opargs[type] & OA_DEFGV) {
+                   kid = newDEFSVOP();
+                    if (prev_kid)
+                        OP_SIBLING_set(prev_kid, kid);
+                    else
+                        cLISTOPo->op_first = kid;
+                }
                seen_optional = TRUE;
            }
            if (!kid) break;
@@ -8712,7 +8717,10 @@ Perl_ck_fun(pTHX_ OP *o)
                    newop->op_next = newop;
                    kid = newop;
                    OP_SIBLING_set(kid, sibl);
-                   *tokid = kid;
+                    if (prev_kid)
+                        OP_SIBLING_set(prev_kid, kid);
+                    else
+                        cLISTOPo->op_first = kid;
                }
                break;
            case OA_FILEREF:
@@ -8831,7 +8839,10 @@ Perl_ck_fun(pTHX_ OP *o)
                        kid->op_private |= priv;
                    }
                    OP_SIBLING_set(kid, sibl);
-                   *tokid = kid;
+                    if (prev_kid)
+                        OP_SIBLING_set(prev_kid, kid);
+                    else
+                        cLISTOPo->op_first = kid;
                }
                scalar(kid);
                break;
@@ -8844,7 +8855,7 @@ Perl_ck_fun(pTHX_ OP *o)
                break;
            }
            oa >>= 4;
-           tokid = &kid->op_sibling;
+           prev_kid = kid;
            kid = OP_SIBLING(kid);
        }
        /* FIXME - should the numargs or-ing move after the too many