@@ -9652,6 +9652,33 @@ Perl_newWHILEOP(pTHX_ I32 flags, I32 debuggable, LOOP *loop,
9652
9652
return o;
9653
9653
}
9654
9654
9655
+ #define find_argop_from_entersub(op) S_find_argop_from_entersub(op)
9656
+ static OP *
9657
+ S_find_argop_from_entersub(OP *entersubop) {
9658
+ assert(entersubop != NULL);
9659
+
9660
+ OP *aop = cUNOPx(entersubop)->op_first;
9661
+ if (!OpHAS_SIBLING(aop)) {
9662
+ aop = cUNOPx(aop)->op_first;
9663
+ }
9664
+ /* move past pushmark */
9665
+ aop = OpSIBLING(aop);
9666
+
9667
+ return aop;
9668
+ }
9669
+
9670
+ #define find_cvop_from_argop(op) S_find_cvop_from_argop(op)
9671
+ static OP *
9672
+ S_find_cvop_from_argop(OP *cvop) {
9673
+ assert(cvop != NULL);
9674
+
9675
+ /* CV is the last argument to entersub */
9676
+ while (OpHAS_SIBLING(cvop)) {
9677
+ cvop = OpSIBLING(cvop);
9678
+ }
9679
+ return cvop;
9680
+ }
9681
+
9655
9682
#define op_is_cv_xsub(o, xsub) S_op_is_cv_xsub(aTHX_ o, xsub)
9656
9683
static bool
9657
9684
S_op_is_cv_xsub(pTHX_ OP *o, XSUBADDR_t xsub)
@@ -9693,13 +9720,8 @@ S_op_is_call_to_cv_xsub(pTHX_ OP *o, XSUBADDR_t xsub)
9693
9720
return false;
9694
9721
9695
9722
/* entersub may be a UNOP, not a LISTOP, so we can't just use op_last */
9696
- OP *aop = cUNOPo->op_first;
9697
- if (!OpHAS_SIBLING(aop)) {
9698
- aop = cUNOPx(aop)->op_first;
9699
- }
9700
- aop = OpSIBLING(aop);
9701
- OP *cvop;
9702
- for (cvop = aop; OpHAS_SIBLING(cvop); cvop = OpSIBLING(cvop)) ;
9723
+ OP *aop = find_argop_from_entersub(o);
9724
+ OP *cvop = find_cvop_from_argop(aop);
9703
9725
9704
9726
return op_is_cv_xsub(cvop, xsub);
9705
9727
}
@@ -14723,10 +14745,7 @@ Perl_ck_entersub_args_list(pTHX_ OP *entersubop)
14723
14745
14724
14746
PERL_ARGS_ASSERT_CK_ENTERSUB_ARGS_LIST;
14725
14747
14726
- aop = cUNOPx(entersubop)->op_first;
14727
- if (!OpHAS_SIBLING(aop))
14728
- aop = cUNOPx(aop)->op_first;
14729
- for (aop = OpSIBLING(aop); OpHAS_SIBLING(aop); aop = OpSIBLING(aop)) {
14748
+ for (aop = find_argop_from_entersub(entersubop); OpHAS_SIBLING(aop); aop = OpSIBLING(aop)) {
14730
14749
/* skip the extra attributes->import() call implicitly added in
14731
14750
* something like foo(my $x : bar)
14732
14751
*/
@@ -14773,7 +14792,7 @@ Perl_ck_entersub_args_proto(pTHX_ OP *entersubop, GV *namegv, SV *protosv)
14773
14792
{
14774
14793
STRLEN proto_len;
14775
14794
const char *proto, *proto_end;
14776
- OP *aop, *prev, *cvop, * parent;
14795
+ OP *aop, *prev, *parent;
14777
14796
int optional = 0;
14778
14797
I32 arg = 0;
14779
14798
I32 contextclass = 0;
@@ -14795,7 +14814,7 @@ Perl_ck_entersub_args_proto(pTHX_ OP *entersubop, GV *namegv, SV *protosv)
14795
14814
}
14796
14815
prev = aop;
14797
14816
aop = OpSIBLING(aop);
14798
- for ( cvop = aop; OpHAS_SIBLING(cvop); cvop = OpSIBLING(cvop)) ;
14817
+ OP * cvop = find_cvop_from_argop(aop) ;
14799
14818
while (aop != cvop) {
14800
14819
OP* o3 = aop;
14801
14820
@@ -15030,18 +15049,17 @@ Perl_ck_entersub_args_proto_or_list(pTHX_ OP *entersubop,
15030
15049
OP *
15031
15050
Perl_ck_entersub_args_core(pTHX_ OP *entersubop, GV *namegv, SV *protosv)
15032
15051
{
15052
+ PERL_ARGS_ASSERT_CK_ENTERSUB_ARGS_CORE;
15053
+
15033
15054
IV cvflags = SvIVX(protosv);
15034
15055
int opnum = cvflags & 0xffff;
15035
15056
OP *aop = cUNOPx(entersubop)->op_first;
15036
15057
15037
- PERL_ARGS_ASSERT_CK_ENTERSUB_ARGS_CORE;
15038
-
15039
15058
if (!opnum) {
15040
- OP *cvop;
15041
15059
if (!OpHAS_SIBLING(aop))
15042
15060
aop = cUNOPx(aop)->op_first;
15043
15061
aop = OpSIBLING(aop);
15044
- for ( cvop = aop; OpSIBLING(cvop); cvop = OpSIBLING(cvop)) ;
15062
+ OP * cvop = find_cvop_from_argop(aop) ;
15045
15063
if (aop != cvop) {
15046
15064
SV *namesv = cv_name((CV *)namegv, NULL, CV_NAME_NOTQUAL);
15047
15065
yyerror_pv(form("Too many arguments for %" SVf,
@@ -15319,21 +15337,15 @@ S_entersub_alloc_targ(pTHX_ OP * const o)
15319
15337
OP *
15320
15338
Perl_ck_subr(pTHX_ OP *o)
15321
15339
{
15322
- OP *aop, *cvop;
15323
- CV *cv;
15324
- GV *namegv;
15325
15340
SV **const_class = NULL;
15326
15341
OP *const_op = NULL;
15327
15342
15328
15343
PERL_ARGS_ASSERT_CK_SUBR;
15329
15344
15330
- aop = cUNOPx(o)->op_first;
15331
- if (!OpHAS_SIBLING(aop))
15332
- aop = cUNOPx(aop)->op_first;
15333
- aop = OpSIBLING(aop);
15334
- for (cvop = aop; OpHAS_SIBLING(cvop); cvop = OpSIBLING(cvop)) ;
15335
- cv = rv2cv_op_cv(cvop, RV2CVOPCV_MARK_EARLY);
15336
- namegv = cv ? (GV*)rv2cv_op_cv(cvop, RV2CVOPCV_MAYBE_NAME_GV) : NULL;
15345
+ OP *aop = find_argop_from_entersub(o);
15346
+ OP *cvop = find_cvop_from_argop(aop);
15347
+ CV *cv = rv2cv_op_cv(cvop, RV2CVOPCV_MARK_EARLY);
15348
+ GV *namegv = cv ? (GV*)rv2cv_op_cv(cvop, RV2CVOPCV_MAYBE_NAME_GV) : NULL;
15337
15349
15338
15350
o->op_private &= ~1;
15339
15351
o->op_private |= (PL_hints & HINT_STRICT_REFS);
0 commit comments