In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/3ee084aa8474e0a47583aee63a88beeea5d4742f?hp=7d7d93ad5efb66d5764017a7a62c90f3b5353986>

- Log -----------------------------------------------------------------
commit 3ee084aa8474e0a47583aee63a88beeea5d4742f
Author: Daniel Dragan <[email protected]>
Date:   Wed Dec 5 23:39:44 2012 -0500

    add PERL_NO_GET_CONTEXT to xs template in h2xs.PL
    
    An XS module not using PERL_NO_GET_CONTEXT is extremely inefficient under
    threaded Perls. Prevent PERL_NO_GET_CONTEXT-less modules in the future
    by making it a default. Many XS modules are created with h2xs.
    Also see this anonymous complaint http://perlmonks.org/?node_id=990732 .

M       utils/h2xs.PL

commit 230834321e308444d408bdbf755d181b67e82d4c
Author: Father Chrysostomos <[email protected]>
Date:   Wed Dec 5 12:53:30 2012 -0800

    Stop renamed packages from making reset() crash
    
    This only affected threaded builds.  I think the comments in the added
    test explain well enough what was happening.
    
    The solution is to store a stashpad offset in the pmop, instead of the
    name of the stash.  This is similar to what was done with cop stashes
    in d4d03940c58a.
    
    Not only does this fix the crash, but it also makes compilation faster
    and saves memory (no separate malloc for every m?pat?).
    
    I had to move Safefree(PL_stashpad) later on in perl_destruct, because
    freeing a pmop causes the PL_stashpad to be accessed, and pmops can be
    freed during sv_clean_all.  Its previous location was not a problem
    for cops, as PL_stashpad[cop->cop_stashoff] is only accessed when
    PL_curcop==that_cop and Perl code is running, not when cops are freed.

M       embed.fnc
M       embed.h
M       op.c
M       op.h
M       perl.c
M       proto.h
M       t/op/reset.t

commit bcea25a760263ce058f5588c6ae62af6f09a211e
Author: Father Chrysostomos <[email protected]>
Date:   Tue Dec 4 14:52:45 2012 -0800

    Don’t use PMf_ONCE flag for split-to-array
    
    Currently the PMf_ONCE flag has two purposes.  It is used to indicate
    that m?? must match only once.  That’s what distinguishes m?? and m//
    internally.  The other use indicates that @x = split... modifies the
    array in place.
    
    Whenever the split op is modified to point straight to the array, the
    PMf_ONCE flag is set.  pp_split checks both whether there is an array
    attached to the op (via a GV in the pad under threads, or a pointer
    from the op to the GV under non-threaded builds) and whether the
    flag is set.
    
    This makes the flag redundant in the split case.
    
    Removing its use here not only simplifies the code and removes redun-
    dant bit-fiddling, but also makes this comment in toke.c, added by
    ad639bfb6, come true:
    
        /* This is the only point in the code that sets PMf_ONCE:  */
    
    (That was actually harmless, as it doesn’t hurt to have a stash refer-
    ring to pmops that don’t use the PMf_USED flag, and the PMf_ONCE flag
    is set for split way after that code is run.  It is also unnecessary
    for split, as that bookkeeping code in toke.c only applies to the m??
    use of PMf_ONCE.)
    
    This commit also removes a gimme != G_ARRAY check that thas been
    redundant since a6d8037e26a.

M       op.c
M       pp.c

commit 19b29141f68d34f2b832ff2cddd54122e3ed3c28
Author: Father Chrysostomos <[email protected]>
Date:   Fri Nov 30 09:54:08 2012 -0800

    perldiag: -D message is a warning
    
    Under non-debugging builds, I get this:
    
    $ perl -D -e 'print "ok\n"'
    Recompile perl with -DDEBUGGING to use -D switch (did you mean -d ?)
    ok
    
    It is a default warning (S), not a fatal error (F).

M       pod/perldiag.pod

commit a125938c1974610beb011694a8740a593dfd84f9
Author: Father Chrysostomos <[email protected]>
Date:   Fri Nov 30 09:50:01 2012 -0800

    perldiag: Remove category from ‘POSIX syntax [. .]...’
    
    Warnings categories apply only to warnings.

M       pod/perldiag.pod

commit 55b37f1c313121c8cbb341aceea93a386169d6fd
Author: Father Chrysostomos <[email protected]>
Date:   Wed Nov 28 22:42:57 2012 -0800

    pp_goto: Call get-magic before choosing goto type
    
    Deciding whether this is goto-label or goto-sub can only correctly
    happen after get-magic has been invoked, as get-magic can cause the
    argument to begin or cease to be a subroutine reference.

M       pp_ctl.c
M       t/op/goto.t
-----------------------------------------------------------------------

Summary of changes:
 embed.fnc        |    6 +-----
 embed.h          |    1 +
 op.c             |   18 ++----------------
 op.h             |   45 +++++++++++----------------------------------
 perl.c           |    5 ++++-
 pod/perldiag.pod |   14 +++++++-------
 pp.c             |    2 +-
 pp_ctl.c         |    3 ++-
 proto.h          |   21 +++++----------------
 t/op/goto.t      |    8 +++++++-
 t/op/reset.t     |   19 ++++++++++++++++++-
 utils/h2xs.PL    |    1 +
 12 files changed, 60 insertions(+), 83 deletions(-)

diff --git a/embed.fnc b/embed.fnc
index e7ac5f1..3dea370 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -1761,11 +1761,7 @@ s        |void   |unwind_handler_stack|NULLOK const void 
*p
 #if defined(PERL_IN_OP_C)
 sRn    |bool   |is_handle_constructor|NN const OP *o|I32 numargs
 sR     |I32    |is_list_assignment|NULLOK const OP *o
-#  ifdef USE_ITHREADS
-so     |void   |forget_pmop    |NN PMOP *const o|U32 flags
-#  else
-so     |void   |forget_pmop    |NN PMOP *const o
-#  endif
+s      |void   |forget_pmop    |NN PMOP *const o
 s      |void   |find_and_forget_pmops  |NN OP *o
 s      |void   |cop_free       |NN COP *cop
 s      |OP*    |modkids        |NULLOK OP *o|I32 type
diff --git a/embed.h b/embed.h
index da45a43..25bd724 100644
--- a/embed.h
+++ b/embed.h
@@ -1401,6 +1401,7 @@
 #define find_and_forget_pmops(a)       S_find_and_forget_pmops(aTHX_ a)
 #define fold_constants(a)      S_fold_constants(aTHX_ a)
 #define force_list(a)          S_force_list(aTHX_ a)
+#define forget_pmop(a)         S_forget_pmop(aTHX_ a)
 #define gen_constant_list(a)   S_gen_constant_list(aTHX_ a)
 #define gv_ename(a)            S_gv_ename(aTHX_ a)
 #define inplace_aassign(a)     S_inplace_aassign(aTHX_ a)
diff --git a/op.c b/op.c
index b0a3073..766ca19 100644
--- a/op.c
+++ b/op.c
@@ -654,12 +654,6 @@ S_op_destroy(pTHX_ OP *o)
     FreeOp(o);
 }
 
-#ifdef USE_ITHREADS
-#  define forget_pmop(a,b)     S_forget_pmop(aTHX_ a,b)
-#else
-#  define forget_pmop(a,b)     S_forget_pmop(aTHX_ a)
-#endif
-
 /* Destructor */
 
 void
@@ -877,7 +871,7 @@ clear_pmop:
        if (!(cPMOPo->op_pmflags & PMf_CODELIST_PRIVATE))
            op_free(cPMOPo->op_code_list);
        cPMOPo->op_code_list = NULL;
-       forget_pmop(cPMOPo, 1);
+       forget_pmop(cPMOPo);
        cPMOPo->op_pmreplrootu.op_pmreplroot = NULL;
         /* we use the same protection as the "SAFE" version of the PM_ macros
          * here since sv_clean_all might release some PMOPs
@@ -920,9 +914,6 @@ S_cop_free(pTHX_ COP* cop)
 
 STATIC void
 S_forget_pmop(pTHX_ PMOP *const o
-#ifdef USE_ITHREADS
-             , U32 flags
-#endif
              )
 {
     HV * const pmstash = PmopSTASH(o);
@@ -955,10 +946,6 @@ S_forget_pmop(pTHX_ PMOP *const o
     }
     if (PL_curpm == o) 
        PL_curpm = NULL;
-#ifdef USE_ITHREADS
-    if (flags)
-       PmopSTASH_free(o);
-#endif
 }
 
 STATIC void
@@ -974,7 +961,7 @@ S_find_and_forget_pmops(pTHX_ OP *o)
            case OP_PUSHRE:
            case OP_MATCH:
            case OP_QR:
-               forget_pmop((PMOP*)kid, 0);
+               forget_pmop((PMOP*)kid);
            }
            find_and_forget_pmops(kid);
            kid = kid->op_sibling;
@@ -5596,7 +5583,6 @@ Perl_newASSIGNOP(pTHX_ I32 flags, OP *left, I32 optype, 
OP *right)
                            = MUTABLE_GV(cSVOPx(tmpop)->op_sv);
                        cSVOPx(tmpop)->op_sv = NULL;    /* steal it */
 #endif
-                       pm->op_pmflags |= PMf_ONCE;
                        tmpop = cUNOPo->op_first;       /* to list (nulled) */
                        tmpop = ((UNOP*)tmpop)->op_first; /* to pushmark */
                        tmpop->op_sibling = NULL;       /* don't free split */
diff --git a/op.h b/op.h
index 97228b1..c1800df 100644
--- a/op.h
+++ b/op.h
@@ -371,10 +371,7 @@ struct pmop {
     union {
        OP *    op_pmreplstart; /* Only used in OP_SUBST */
 #ifdef USE_ITHREADS
-       struct {
-            char *     op_pmstashpv;   /* Only used in OP_MATCH, with PMf_ONCE 
set */
-            U32     op_pmstashflags;  /* currently only SVf_UTF8 or 0 */
-        } op_pmstashthr;
+       PADOFFSET op_pmstashoff; /* Only used in OP_MATCH, with PMf_ONCE set */
 #else
        HV *    op_pmstash;
 #endif
@@ -454,30 +451,13 @@ struct pmop {
 
 #ifdef USE_ITHREADS
 
-#  define PmopSTASHPV(o)                                               \
-    (((o)->op_pmflags & PMf_ONCE) ? 
(o)->op_pmstashstartu.op_pmstashthr.op_pmstashpv : NULL)
-#  if defined (DEBUGGING) && defined(__GNUC__) && 
!defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN)
-#    define PmopSTASHPV_set(o,pv)      ({                              \
-       assert((o)->op_pmflags & PMf_ONCE);                             \
-       ((o)->op_pmstashstartu.op_pmstashthr.op_pmstashpv = savesharedpv(pv));  
\
-    })
-#  else
-#    define PmopSTASHPV_set(o,pv)                                      \
-    ((o)->op_pmstashstartu.op_pmstashthr.op_pmstashpv = savesharedpv(pv))
-#  endif
-#  define PmopSTASH_flags(o)           
((o)->op_pmstashstartu.op_pmstashthr.op_pmstashflags)
-#  define PmopSTASH_flags_set(o,flags) 
((o)->op_pmstashstartu.op_pmstashthr.op_pmstashflags = flags)
-#  define PmopSTASH(o)         (PmopSTASHPV(o)                                 
    \
-                                ? 
gv_stashpv((o)->op_pmstashstartu.op_pmstashthr.op_pmstashpv,   \
-                                            GV_ADD | PmopSTASH_flags(o)) : 
NULL)
-#  define PmopSTASH_set(o,hv)  (PmopSTASHPV_set(o, (hv) ? HvNAME_get(hv) : 
NULL), \
-                                PmopSTASH_flags_set(o,                         
   \
-                                            ((hv) && HvNAME_HEK(hv) &&         
  \
-                                                        HvNAMEUTF8(hv))        
   \
-                                                ? SVf_UTF8                     
   \
-                                                : 0))
-#  define PmopSTASH_free(o)    PerlMemShared_free(PmopSTASHPV(o))
-
+#  define PmopSTASH(o)         ((o)->op_pmflags & PMf_ONCE                     
    \
+                                ? 
PL_stashpad[(o)->op_pmstashstartu.op_pmstashoff]   \
+                                : NULL)
+#  define PmopSTASH_set(o,hv)  \
+       (assert_((o)->op_pmflags & PMf_ONCE)                            \
+        (o)->op_pmstashstartu.op_pmstashoff =                          \
+           (hv) ? alloccopstash(hv) : NULL)
 #else
 #  define PmopSTASH(o)                                                 \
     (((o)->op_pmflags & PMf_ONCE) ? (o)->op_pmstashstartu.op_pmstash : NULL)
@@ -489,13 +469,10 @@ struct pmop {
 #  else
 #    define PmopSTASH_set(o,hv)        ((o)->op_pmstashstartu.op_pmstash = 
(hv))
 #  endif
-#  define PmopSTASHPV(o)       (PmopSTASH(o) ? HvNAME_get(PmopSTASH(o)) : NULL)
-   /* op_pmstashstartu.op_pmstash is not refcounted */
-#  define PmopSTASHPV_set(o,pv)        PmopSTASH_set((o), 
gv_stashpv(pv,GV_ADD))
-/* Note that if this becomes non-empty, then S_forget_pmop in op.c will need
-   changing */
-#  define PmopSTASH_free(o)    
 #endif
+#define PmopSTASHPV(o) (PmopSTASH(o) ? HvNAME_get(PmopSTASH(o)) : NULL)
+   /* op_pmstashstartu.op_pmstash is not refcounted */
+#define PmopSTASHPV_set(o,pv)  PmopSTASH_set((o), gv_stashpv(pv,GV_ADD))
 
 struct svop {
     BASEOP
diff --git a/perl.c b/perl.c
index fe71325..a6f9c14 100644
--- a/perl.c
+++ b/perl.c
@@ -845,7 +845,6 @@ perl_destruct(pTHXx)
            ary[i] = &PL_sv_undef;
        }
     }
-    Safefree(PL_stashpad);
 #endif
 
 
@@ -1079,6 +1078,10 @@ perl_destruct(pTHXx)
     while (sv_clean_all() > 2)
        ;
 
+#ifdef USE_ITHREADS
+    Safefree(PL_stashpad); /* must come after sv_clean_all */
+#endif
+
     AvREAL_off(PL_fdpid);              /* no surviving entries */
     SvREFCNT_dec(PL_fdpid);            /* needed in io_close() */
     PL_fdpid = NULL;
diff --git a/pod/perldiag.pod b/pod/perldiag.pod
index dfa9a7d..2a0e838 100644
--- a/pod/perldiag.pod
+++ b/pod/perldiag.pod
@@ -3902,12 +3902,12 @@ where the problem was discovered.  See L<perlre>.
 
 =item POSIX syntax [. .] is reserved for future extensions in regex; marked by 
<-- HERE in m/%s/
 
-(F regexp) Within regular expression character classes ([]) the syntax
-beginning with "[." and ending with ".]" is reserved for future extensions.
-If you need to represent those character sequences inside a regular
-expression character class, just quote the square brackets with the
-backslash: "\[." and ".\]".  The <-- HERE shows in the regular expression
-about where the problem was discovered.  See L<perlre>.
+(F) Within regular expression character classes ([]) the syntax beginning
+with "[." and ending with ".]" is reserved for future extensions.  If you
+need to represent those character sequences inside a regular expression
+character class, just quote the square brackets with the backslash: "\[."
+and ".\]".  The <-- HERE shows in the regular expression about where the
+problem was discovered.  See L<perlre>.
 
 =item POSIX syntax [= =] is reserved for future extensions in regex; marked by 
<-- HERE in m/%s/
 
@@ -4143,7 +4143,7 @@ already been freed.
 
 =item Recompile perl with B<-D>DEBUGGING to use B<-D> switch
 
-(F debugging) You can't use the B<-D> option unless the code to produce
+(S debugging) You can't use the B<-D> option unless the code to produce
 the desired output is compiled into Perl, which entails some overhead,
 which is why it's currently left out of your copy.
 
diff --git a/pp.c b/pp.c
index e1c9d75..cf59a84 100644
--- a/pp.c
+++ b/pp.c
@@ -5353,7 +5353,7 @@ PP(pp_split)
 #endif
     else
        ary = NULL;
-    if (ary && (gimme != G_ARRAY || (pm->op_pmflags & PMf_ONCE))) {
+    if (ary) {
        realarray = 1;
        PUTBACK;
        av_extend(ary,0);
diff --git a/pp_ctl.c b/pp_ctl.c
index f889ca8..0256070 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -2768,6 +2768,7 @@ PP(pp_goto)
 
     if (PL_op->op_flags & OPf_STACKED) {
        SV * const sv = POPs;
+       SvGETMAGIC(sv);
 
        /* This egregious kludge implements goto &subroutine */
        if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
@@ -2951,7 +2952,7 @@ PP(pp_goto)
            }
        }
        else {
-           label       = SvPV_const(sv, label_len);
+           label       = SvPV_nomg_const(sv, label_len);
             label_flags = SvUTF8(sv);
        }
     }
diff --git a/proto.h b/proto.h
index 0f19ccd..2351b32 100644
--- a/proto.h
+++ b/proto.h
@@ -4846,15 +4846,6 @@ PERL_CALLCONV void       Perl_utilize(pTHX_ int aver, 
I32 floor, OP* version, OP* idop
        assert(idop)
 
 #endif
-#if !(defined(USE_ITHREADS))
-#  if defined(PERL_IN_OP_C)
-STATIC void    S_forget_pmop(pTHX_ PMOP *const o)
-                       __attribute__nonnull__(pTHX_1);
-#define PERL_ARGS_ASSERT_FORGET_PMOP   \
-       assert(o)
-
-#  endif
-#endif
 #if !defined(HAS_BZERO) && !defined(HAS_MEMSET)
 PERL_CALLCONV char*    Perl_my_bzero(char* loc, I32 len)
                        __attribute__nonnull__(1);
@@ -5769,6 +5760,11 @@ STATIC OP*       S_fold_constants(pTHX_ OP *o)
        assert(o)
 
 STATIC OP*     S_force_list(pTHX_ OP* arg);
+STATIC void    S_forget_pmop(pTHX_ PMOP *const o)
+                       __attribute__nonnull__(pTHX_1);
+#define PERL_ARGS_ASSERT_FORGET_PMOP   \
+       assert(o)
+
 STATIC OP*     S_gen_constant_list(pTHX_ OP* o);
 STATIC SV*     S_gv_ename(pTHX_ GV *gv)
                        __attribute__nonnull__(pTHX_1);
@@ -5901,13 +5897,6 @@ STATIC OP*       S_too_many_arguments_sv(pTHX_ OP *o, 
SV* namesv, U32 flags)
 #define PERL_ARGS_ASSERT_TOO_MANY_ARGUMENTS_SV \
        assert(o); assert(namesv)
 
-#  if defined(USE_ITHREADS)
-STATIC void    S_forget_pmop(pTHX_ PMOP *const o, U32 flags)
-                       __attribute__nonnull__(pTHX_1);
-#define PERL_ARGS_ASSERT_FORGET_PMOP   \
-       assert(o)
-
-#  endif
 #endif
 #if defined(PERL_IN_OP_C) || defined(PERL_IN_SV_C)
 PERL_CALLCONV void     Perl_report_redefined_cv(pTHX_ const SV *name, const CV 
*old_cv, SV * const *new_const_svp)
diff --git a/t/op/goto.t b/t/op/goto.t
index 7dafb2a..486277d 100644
--- a/t/op/goto.t
+++ b/t/op/goto.t
@@ -10,7 +10,7 @@ BEGIN {
 
 use warnings;
 use strict;
-plan tests => 88;
+plan tests => 89;
 our $TODO;
 
 my $deprecated = 0;
@@ -663,3 +663,9 @@ eval { my $x = "\0"; goto $x };
 like $@, qr/^Can't find label \0 at /, 'goto $x where $x begins with \0';
 eval { goto "\0" };
 like $@, qr/^Can't find label \0 at /, 'goto "\0"';
+
+sub TIESCALAR { bless [pop] }
+sub FETCH     { $_[0][0] }
+tie my $t, "", sub { "cluck up porridge" };
+is eval { sub { goto $t }->() }//$@, 'cluck up porridge',
+  'tied arg returning sub ref';
diff --git a/t/op/reset.t b/t/op/reset.t
index f9ebeee..291bc39 100644
--- a/t/op/reset.t
+++ b/t/op/reset.t
@@ -7,7 +7,7 @@ BEGIN {
 }
 use strict;
 
-plan tests => 29;
+plan tests => 30;
 
 package aiieee;
 
@@ -103,6 +103,23 @@ is join("-", $scratch::a//'u', do { no strict; 
${"scratch::\0foo"} }//'u'),
    "u-u",
    'reset "\0char"';
 
+# This used to crash under threaded builds, because pmops were remembering
+# their stashes by name, rather than by pointer.
+fresh_perl_is( # it crashes more reliably with a smaller script
+  'package bar;
+   sub foo {
+     m??;
+     BEGIN { *baz:: = *bar::; *bar:: = *foo:: }
+     # The name "bar" no langer refers to the same package
+   }
+   undef &foo; # so freeing the op does not remove it from the stash’s list
+   $_ = "";
+   push @_, ($_) x 10000;  # and its memory is scribbled over
+   reset;  # so reset on the original package tries to reset an invalid op
+   print "ok\n";',
+  "ok\n", {},
+  "no crash if package is effectively renamed before op is freed");
+
 
 undef $/;
 my $prog = <DATA>;
diff --git a/utils/h2xs.PL b/utils/h2xs.PL
index 6b2c78f..25bd0ec 100644
--- a/utils/h2xs.PL
+++ b/utils/h2xs.PL
@@ -1386,6 +1386,7 @@ if( ! $opt_X ){ # print XS, unless it is disabled
 warn "Writing $ext$modpname/$modfname.xs\n";
 
 print XS <<"END";
+#define PERL_NO_GET_CONTEXT
 #include "EXTERN.h"
 #include "perl.h"
 #include "XSUB.h"

--
Perl5 Master Repository

Reply via email to