In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/03d5bcf83cdbcccf9aefa373ec7b6a3dc11c5142?hp=540810e8986e170e75f4b34a7ca1f1dd5b0da3c4>

- Log -----------------------------------------------------------------
commit 03d5bcf83cdbcccf9aefa373ec7b6a3dc11c5142
Author: Vincent Pit <[email protected]>
Date:   Thu Jun 3 12:08:14 2010 +0200

    Deprecate find_rundefsvoffset()

M       embed.fnc
M       pod/perl5132delta.pod
M       proto.h

commit 483ce06a4f6c720f66285117b98747911f62226a
Author: Vincent Pit <[email protected]>
Date:   Thu Jun 3 11:55:20 2010 +0200

    The UNDERBAR macro should use find_rundefsv() as well

M       XSUB.h
M       pod/perl5132delta.pod

commit 789bd863840ef4ff6c46f7c2ee0f3f64e0b5daa6
Author: Vincent Pit <[email protected]>
Date:   Thu Jun 3 11:44:15 2010 +0200

    Make pp_reverse fetch the lexical $_ from the correct pad
    
    This is achieved by introducing a new find_rundefsv() function in pad.c
    
    This fixes [perl #75436].

M       embed.fnc
M       embed.h
M       global.sym
M       pad.c
M       pod/perl5132delta.pod
M       pp.c
M       proto.h
M       t/op/reverse.t
-----------------------------------------------------------------------

Summary of changes:
 XSUB.h                |   11 +++++------
 embed.fnc             |    4 +++-
 embed.h               |    2 ++
 global.sym            |    1 +
 pad.c                 |   22 ++++++++++++++++++++++
 pod/perl5132delta.pod |   16 +++++++++++++++-
 pp.c                  |    9 +--------
 proto.h               |    5 ++++-
 t/op/reverse.t        |   14 +++++++++++++-
 9 files changed, 66 insertions(+), 18 deletions(-)

diff --git a/XSUB.h b/XSUB.h
index 06cb1c3..ca2c297 100644
--- a/XSUB.h
+++ b/XSUB.h
@@ -72,8 +72,9 @@ Sets up the C<ix> variable for an XSUB which has aliases.  
This is usually
 handled automatically by C<xsubpp>.
 
 =for apidoc Ams||dUNDERBAR
-Sets up the C<padoff_du> variable for an XSUB that wishes to use
-C<UNDERBAR>.
+Sets up any variable needed by the C<UNDERBAR> macro. It used to define
+C<padoff_du>, but it is currently a noop. However, it is strongly adviced
+to still use it for ensuring past and future compatibility.
 
 =for apidoc AmU||UNDERBAR
 The SV* corresponding to the $_ variable. Works even if there
@@ -166,10 +167,8 @@ is a lexical $_ in scope.
 #define XSINTERFACE_FUNC_SET(cv,f)     \
                CvXSUBANY(cv).any_dxptr = (void (*) (pTHX_ void*))(f)
 
-#define dUNDERBAR PADOFFSET padoff_du = find_rundefsvoffset()
-#define UNDERBAR ((padoff_du == NOT_IN_PAD \
-           || PAD_COMPNAME_FLAGS_isOUR(padoff_du)) \
-       ? DEFSV : PAD_SVl(padoff_du))
+#define dUNDERBAR dNOOP
+#define UNDERBAR  find_rundefsv()
 
 /* Simple macros to put new mortal values onto the stack.   */
 /* Typically used to return values from XS functions.       */
diff --git a/embed.fnc b/embed.fnc
index 8e463c1..01605a9 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -855,7 +855,9 @@ p   |PADOFFSET|allocmy      |NN const char *const 
name|const STRLEN len\
                                |const U32 flags
 : Used in op.c and toke.c
 AMpdR  |PADOFFSET|pad_findmy   |NN const char* name|STRLEN len|U32 flags
-Ap     |PADOFFSET|find_rundefsvoffset  |
+ApD    |PADOFFSET|find_rundefsvoffset  |
+: Used in pp.c
+Ap     |SV*    |find_rundefsv  |
 : Used in perly.y
 pR     |OP*    |oopsAV         |NN OP* o
 : Used in perly.y
diff --git a/embed.h b/embed.h
index 90e8045..588c50a 100644
--- a/embed.h
+++ b/embed.h
@@ -673,6 +673,7 @@
 #endif
 #define pad_findmy             Perl_pad_findmy
 #define find_rundefsvoffset    Perl_find_rundefsvoffset
+#define find_rundefsv          Perl_find_rundefsv
 #ifdef PERL_CORE
 #define oopsAV                 Perl_oopsAV
 #define oopsHV                 Perl_oopsHV
@@ -3106,6 +3107,7 @@
 #endif
 #define pad_findmy(a,b,c)      Perl_pad_findmy(aTHX_ a,b,c)
 #define find_rundefsvoffset()  Perl_find_rundefsvoffset(aTHX)
+#define find_rundefsv()                Perl_find_rundefsv(aTHX)
 #ifdef PERL_CORE
 #define oopsAV(a)              Perl_oopsAV(aTHX_ a)
 #define oopsHV(a)              Perl_oopsHV(aTHX_ a)
diff --git a/global.sym b/global.sym
index 8861fca..5ab0090 100644
--- a/global.sym
+++ b/global.sym
@@ -396,6 +396,7 @@ Perl_ninstr
 Perl_op_free
 Perl_pad_findmy
 Perl_find_rundefsvoffset
+Perl_find_rundefsv
 Perl_pad_sv
 Perl_reentrant_size
 Perl_reentrant_init
diff --git a/pad.c b/pad.c
index 477ee0f..e8ba139 100644
--- a/pad.c
+++ b/pad.c
@@ -704,6 +704,28 @@ Perl_find_rundefsvoffset(pTHX)
 }
 
 /*
+ * Returns a lexical $_, if there is one, at run time ; or the global one
+ * otherwise.
+ */
+
+SV *
+Perl_find_rundefsv(pTHX)
+{
+    SV *namesv;
+    int flags;
+    PADOFFSET po;
+
+    po = pad_findlex("$_", find_runcv(NULL), PL_curcop->cop_seq, 1,
+           NULL, &namesv, &flags);
+
+    if (po == NOT_IN_PAD
+       || (SvFLAGS(namesv) & (SVpad_NAME|SVpad_OUR)) == (SVpad_NAME|SVpad_OUR))
+       return DEFSV;
+
+    return PAD_SVl(po);
+}
+
+/*
 =for apidoc pad_findlex
 
 Find a named lexical anywhere in a chain of nested pads. Add fake entries
diff --git a/pod/perl5132delta.pod b/pod/perl5132delta.pod
index fe45773..9551f4a 100644
--- a/pod/perl5132delta.pod
+++ b/pod/perl5132delta.pod
@@ -181,8 +181,22 @@ XXX Changes which affect the interface available to C<XS> 
code go here.
 
 =item *
 
+The C<fund_rundefsvoffset> function has been deprecated. It appeared that
+its design was insufficient to reliably get the lexical C<$_> at run-time.
+
+Use the new C<find_rundefsv> function or the C<UNDERBAR> macro instead.
+They directly return the right SV representing C<$_>, whether it's lexical
+or dynamic.
+
+=item *
+
 The following new functions or macros have been added to the public API:
-C<SvNV_nomg>,  C<sv_2nv_flags>.
+C<SvNV_nomg>,  C<sv_2nv_flags>, C<find_rundefsv>.
+
+=item *
+
+The C<UNDERBAR> macro now calls C<find_rundefsv>. C<dUNDERBAR> is now a
+noop but should still be used to ensure past and future compatibility.
 
 =back
 
diff --git a/pp.c b/pp.c
index 937fdfd..2649c7e 100644
--- a/pp.c
+++ b/pp.c
@@ -5489,19 +5489,12 @@ PP(pp_reverse)
        register I32 tmp;
        dTARGET;
        STRLEN len;
-       PADOFFSET padoff_du;
 
        SvUTF8_off(TARG);                               /* decontaminate */
        if (SP - MARK > 1)
            do_join(TARG, &PL_sv_no, MARK, SP);
        else {
-           sv_setsv(TARG, (SP > MARK)
-                   ? *SP
-                   : (padoff_du = find_rundefsvoffset(),
-                       (padoff_du == NOT_IN_PAD
-                        || PAD_COMPNAME_FLAGS_isOUR(padoff_du))
-                       ? DEFSV : PAD_SVl(padoff_du)));
-
+           sv_setsv(TARG, SP > MARK ? *SP : find_rundefsv());
            if (! SvOK(TARG) && ckWARN(WARN_UNINITIALIZED))
                report_uninit(TARG);
        }
diff --git a/proto.h b/proto.h
index 6ccf19c..9ce57d5 100644
--- a/proto.h
+++ b/proto.h
@@ -2509,7 +2509,10 @@ PERL_CALLCONV PADOFFSET  Perl_pad_findmy(pTHX_ const 
char* name, STRLEN len, U32
 #define PERL_ARGS_ASSERT_PAD_FINDMY    \
        assert(name)
 
-PERL_CALLCONV PADOFFSET        Perl_find_rundefsvoffset(pTHX);
+PERL_CALLCONV PADOFFSET        Perl_find_rundefsvoffset(pTHX)
+                       __attribute__deprecated__;
+
+PERL_CALLCONV SV*      Perl_find_rundefsv(pTHX);
 PERL_CALLCONV OP*      Perl_oopsAV(pTHX_ OP* o)
                        __attribute__warn_unused_result__
                        __attribute__nonnull__(pTHX_1);
diff --git a/t/op/reverse.t b/t/op/reverse.t
index 2fa0877..916724c 100644
--- a/t/op/reverse.t
+++ b/t/op/reverse.t
@@ -6,7 +6,7 @@ BEGIN {
     require './test.pl';
 }
 
-plan tests => 23;
+plan tests => 26;
 
 is(reverse("abc"), "cba");
 
@@ -91,3 +91,15 @@ use Tie::Array;
     my $c = scalar reverse($b);
     is($a, $c);
 }
+
+{
+    # Lexical $_.
+    sub blurp { my $_ = shift; reverse }
+
+    is(blurp("foo"), "oof");
+    is(sub { my $_ = shift; reverse }->("bar"), "rab");
+    {
+        local $_ = "XXX";
+        is(blurp("paz"), "zap");
+    }
+}

--
Perl5 Master Repository

Reply via email to