85ab1f
From 9f38b6c605086a67f0d92591f8e8dc99bc1d9164 Mon Sep 17 00:00:00 2001
85ab1f
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
85ab1f
Date: Thu, 11 May 2017 09:25:35 +0200
85ab1f
Subject: [PATCH] Upgrade to 2.167
85ab1f
MIME-Version: 1.0
85ab1f
Content-Type: text/plain; charset=UTF-8
85ab1f
Content-Transfer-Encoding: 8bit
85ab1f
85ab1f
Unbundled from perl-5.25.12.
85ab1f
85ab1f
Signed-off-by: Petr Písař <ppisar@redhat.com>
85ab1f
---
85ab1f
 Changes     |  14 +++++
85ab1f
 Dumper.pm   |  47 ++++++++---------
85ab1f
 Dumper.xs   | 167 +++++++++++++++++++++++++++++++++++++++++++++---------------
85ab1f
 t/bugs.t    |  37 +++++++++++++-
85ab1f
 t/deparse.t |  22 ++++----
85ab1f
 5 files changed, 207 insertions(+), 80 deletions(-)
85ab1f
85ab1f
diff --git a/Changes b/Changes
85ab1f
index f9ea53f..a5430d5 100644
85ab1f
--- a/Changes
85ab1f
+++ b/Changes
85ab1f
@@ -6,6 +6,20 @@ Changes - public release history for Data::Dumper
85ab1f
 
85ab1f
 =over 8
85ab1f
 
85ab1f
+=item 2,166 (Nov 29 2016)
85ab1f
+
85ab1f
+Reduce memory usage by not importing from Carp
85ab1f
+Reduce memory usage by removing unused overload require.
85ab1f
+
85ab1f
+=item 2.165 (Nov 20 2016)
85ab1f
+
85ab1f
+Remove impediment to compiling under C++11.
85ab1f
+
85ab1f
+=item 2.164 (Nov 12 2016)
85ab1f
+
85ab1f
+The XS implementation now handles the C<Deparse> option, so using it no
85ab1f
+longer forces use of the pure-Perl version.
85ab1f
+
85ab1f
 =item 2.161 (Jul 11 2016)
85ab1f
 
85ab1f
 Perl 5.12 fix/workaround until fixed PPPort release.
85ab1f
diff --git a/Dumper.pm b/Dumper.pm
85ab1f
index c71ad35..00f6326 100644
85ab1f
--- a/Dumper.pm
85ab1f
+++ b/Dumper.pm
85ab1f
@@ -10,16 +10,15 @@
85ab1f
 package Data::Dumper;
85ab1f
 
85ab1f
 BEGIN {
85ab1f
-    $VERSION = '2.161'; # Don't forget to set version and release
85ab1f
+    $VERSION = '2.167'; # Don't forget to set version and release
85ab1f
 }               # date in POD below!
85ab1f
 
85ab1f
 #$| = 1;
85ab1f
 
85ab1f
 use 5.006_001;
85ab1f
 require Exporter;
85ab1f
-require overload;
85ab1f
 
85ab1f
-use Carp;
85ab1f
+use Carp ();
85ab1f
 
85ab1f
 BEGIN {
85ab1f
     @ISA = qw(Exporter);
85ab1f
@@ -70,7 +69,7 @@ $Maxrecurse = 1000      unless defined $Maxrecurse;
85ab1f
 sub new {
85ab1f
   my($c, $v, $n) = @_;
85ab1f
 
85ab1f
-  croak "Usage:  PACKAGE->new(ARRAYREF, [ARRAYREF])"
85ab1f
+  Carp::croak("Usage:  PACKAGE->new(ARRAYREF, [ARRAYREF])")
85ab1f
     unless (defined($v) && (ref($v) eq 'ARRAY'));
85ab1f
   $n = [] unless (defined($n) && (ref($n) eq 'ARRAY'));
85ab1f
 
85ab1f
@@ -170,11 +169,11 @@ sub Seen {
85ab1f
           $s->{seen}{$id} = [$k, $v];
85ab1f
         }
85ab1f
         else {
85ab1f
-          carp "Only refs supported, ignoring non-ref item \$$k";
85ab1f
+          Carp::carp("Only refs supported, ignoring non-ref item \$$k");
85ab1f
         }
85ab1f
       }
85ab1f
       else {
85ab1f
-        carp "Value of ref must be defined; ignoring undefined item \$$k";
85ab1f
+        Carp::carp("Value of ref must be defined; ignoring undefined item \$$k");
85ab1f
       }
85ab1f
     }
85ab1f
     return $s;
85ab1f
@@ -195,7 +194,7 @@ sub Values {
85ab1f
       return $s;
85ab1f
     }
85ab1f
     else {
85ab1f
-      croak "Argument to Values, if provided, must be array ref";
85ab1f
+      Carp::croak("Argument to Values, if provided, must be array ref");
85ab1f
     }
85ab1f
   }
85ab1f
   else {
85ab1f
@@ -214,7 +213,7 @@ sub Names {
85ab1f
       return $s;
85ab1f
     }
85ab1f
     else {
85ab1f
-      croak "Argument to Names, if provided, must be array ref";
85ab1f
+      Carp::croak("Argument to Names, if provided, must be array ref");
85ab1f
     }
85ab1f
   }
85ab1f
   else {
85ab1f
@@ -227,7 +226,6 @@ sub DESTROY {}
85ab1f
 sub Dump {
85ab1f
     return &Dumpxs
85ab1f
     unless $Data::Dumper::Useperl || (ref($_[0]) && $_[0]->{useperl})
85ab1f
-        || $Data::Dumper::Deparse || (ref($_[0]) && $_[0]->{deparse})
85ab1f
 
85ab1f
             # Use pure perl version on earlier releases on EBCDIC platforms
85ab1f
         || (! $IS_ASCII && $] lt 5.021_010);
85ab1f
@@ -439,7 +437,7 @@ sub _dump {
85ab1f
         if (ref($s->{sortkeys}) eq 'CODE') {
85ab1f
           $keys = $s->{sortkeys}($val);
85ab1f
           unless (ref($keys) eq 'ARRAY') {
85ab1f
-            carp "Sortkeys subroutine did not return ARRAYREF";
85ab1f
+            Carp::carp("Sortkeys subroutine did not return ARRAYREF");
85ab1f
             $keys = [];
85ab1f
           }
85ab1f
         }
85ab1f
@@ -487,16 +485,16 @@ sub _dump {
85ab1f
         require B::Deparse;
85ab1f
         my $sub =  'sub ' . (B::Deparse->new)->coderef2text($val);
85ab1f
         $pad    =  $s->{sep} . $s->{pad} . $s->{apad} . $s->{xpad} x ($s->{level} - 1);
85ab1f
-        $sub    =~ s/\n/$pad/gse;
85ab1f
+        $sub    =~ s/\n/$pad/gs;
85ab1f
         $out   .=  $sub;
85ab1f
       }
85ab1f
       else {
85ab1f
         $out .= 'sub { "DUMMY" }';
85ab1f
-        carp "Encountered CODE ref, using dummy placeholder" if $s->{purity};
85ab1f
+        Carp::carp("Encountered CODE ref, using dummy placeholder") if $s->{purity};
85ab1f
       }
85ab1f
     }
85ab1f
     else {
85ab1f
-      croak "Can't handle '$realtype' type";
85ab1f
+      Carp::croak("Can't handle '$realtype' type");
85ab1f
     }
85ab1f
 
85ab1f
     if ($realpack and !$no_bless) { # we have a blessed ref
85ab1f
@@ -1212,9 +1210,10 @@ $Data::Dumper::Deparse  I<or>  $I<OBJ>->Deparse(I<[NEWVAL]>)
85ab1f
 
85ab1f
 Can be set to a boolean value to control whether code references are
85ab1f
 turned into perl source code. If set to a true value, C<B::Deparse>
85ab1f
-will be used to get the source of the code reference. Using this option
85ab1f
-will force using the Perl implementation of the dumper, since the fast
85ab1f
-XSUB implementation doesn't support it.
85ab1f
+will be used to get the source of the code reference. In older versions,
85ab1f
+using this option imposed a significant performance penalty when dumping
85ab1f
+parts of a data structure other than code references, but that is no
85ab1f
+longer the case.
85ab1f
 
85ab1f
 Caution : use this option only if you know that your coderefs will be
85ab1f
 properly reconstructed by C<B::Deparse>.
85ab1f
@@ -1435,15 +1434,9 @@ the C<Deparse> flag), an anonymous subroutine that
85ab1f
 contains the string '"DUMMY"' will be inserted in its place, and a warning
85ab1f
 will be printed if C<Purity> is set.  You can C<eval> the result, but bear
85ab1f
 in mind that the anonymous sub that gets created is just a placeholder.
85ab1f
-Someday, perl will have a switch to cache-on-demand the string
85ab1f
-representation of a compiled piece of code, I hope.  If you have prior
85ab1f
-knowledge of all the code refs that your data structures are likely
85ab1f
-to have, you can use the C<Seen> method to pre-seed the internal reference
85ab1f
-table and make the dumped output point to them, instead.  See L</EXAMPLES>
85ab1f
-above.
85ab1f
-
85ab1f
-The C<Deparse> flag makes Dump() run slower, since the XSUB
85ab1f
-implementation does not support it.
85ab1f
+Even using the C<Deparse> flag will in some cases produce results that
85ab1f
+behave differently after being passed to C<eval>; see the documentation
85ab1f
+for L<B::Deparse>.
85ab1f
 
85ab1f
 SCALAR objects have the weirdest looking C<bless> workaround.
85ab1f
 
85ab1f
@@ -1466,13 +1459,13 @@ be to use the C<Sortkeys> filter of Data::Dumper.
85ab1f
 
85ab1f
 Gurusamy Sarathy        gsar@activestate.com
85ab1f
 
85ab1f
-Copyright (c) 1996-2016 Gurusamy Sarathy. All rights reserved.
85ab1f
+Copyright (c) 1996-2017 Gurusamy Sarathy. All rights reserved.
85ab1f
 This program is free software; you can redistribute it and/or
85ab1f
 modify it under the same terms as Perl itself.
85ab1f
 
85ab1f
 =head1 VERSION
85ab1f
 
85ab1f
-Version 2.161  (July 11 2016)
85ab1f
+Version 2.167  (January 4 2017)
85ab1f
 
85ab1f
 =head1 SEE ALSO
85ab1f
 
85ab1f
diff --git a/Dumper.xs b/Dumper.xs
85ab1f
index b22088f..0e7142e 100644
85ab1f
--- a/Dumper.xs
85ab1f
+++ b/Dumper.xs
85ab1f
@@ -63,6 +63,7 @@ typedef struct {
85ab1f
     I32 useqq;
85ab1f
     int use_sparse_seen_hash;
85ab1f
     int trailingcomma;
85ab1f
+    int deparse;
85ab1f
 } Style;
85ab1f
 
85ab1f
 static STRLEN num_q (const char *s, STRLEN slen);
85ab1f
@@ -369,7 +370,7 @@ esc_q_utf8(pTHX_ SV* sv, const char *src, STRLEN slen, I32 do_utf8, I32 useqq)
85ab1f
             UV k;
85ab1f
 
85ab1f
             if (do_utf8
85ab1f
-                && ! isASCII(*(U8*)s)
85ab1f
+                && ! isASCII(*s)
85ab1f
                     /* Exclude non-ASCII low ordinal controls.  This should be
85ab1f
                      * optimized out by the compiler on ASCII platforms; if not
85ab1f
                      * could wrap it in a #ifdef EBCDIC, but better to avoid
85ab1f
@@ -387,11 +388,11 @@ esc_q_utf8(pTHX_ SV* sv, const char *src, STRLEN slen, I32 do_utf8, I32 useqq)
85ab1f
                 increment = (k == 0 && *s != '\0') ? 1 : UTF8SKIP(s);
85ab1f
 
85ab1f
 #if PERL_VERSION < 10
85ab1f
-                sprintf(r, "\\x{%"UVxf"}", k);
85ab1f
+                sprintf(r, "\\x{%" UVxf "}", k);
85ab1f
                 r += strlen(r);
85ab1f
                 /* my_sprintf is not supported by ppport.h */
85ab1f
 #else
85ab1f
-                r = r + my_sprintf(r, "\\x{%"UVxf"}", k);
85ab1f
+                r = r + my_sprintf(r, "\\x{%" UVxf "}", k);
85ab1f
 #endif
85ab1f
                 continue;
85ab1f
             }
85ab1f
@@ -505,6 +506,53 @@ sv_x(pTHX_ SV *sv, const char *str, STRLEN len, I32 n)
85ab1f
     return sv;
85ab1f
 }
85ab1f
 
85ab1f
+static SV *
85ab1f
+deparsed_output(pTHX_ SV *val)
85ab1f
+{
85ab1f
+    SV *text;
85ab1f
+    int n;
85ab1f
+    dSP;
85ab1f
+
85ab1f
+    /* This is passed to load_module(), which decrements its ref count and
85ab1f
+     * modifies it (so we also can't reuse it below) */
85ab1f
+    SV *pkg = newSVpvs("B::Deparse");
85ab1f
+
85ab1f
+    load_module(PERL_LOADMOD_NOIMPORT, pkg, 0);
85ab1f
+
85ab1f
+    SAVETMPS;
85ab1f
+
85ab1f
+    PUSHMARK(SP);
85ab1f
+    mXPUSHs(newSVpvs("B::Deparse"));
85ab1f
+    PUTBACK;
85ab1f
+
85ab1f
+    n = call_method("new", G_SCALAR);
85ab1f
+    SPAGAIN;
85ab1f
+
85ab1f
+    if (n != 1) {
85ab1f
+        croak("B::Deparse->new returned %d items, but expected exactly 1", n);
85ab1f
+    }
85ab1f
+
85ab1f
+    PUSHMARK(SP - n);
85ab1f
+    XPUSHs(val);
85ab1f
+    PUTBACK;
85ab1f
+
85ab1f
+    n = call_method("coderef2text", G_SCALAR);
85ab1f
+    SPAGAIN;
85ab1f
+
85ab1f
+    if (n != 1) {
85ab1f
+        croak("$b_deparse->coderef2text returned %d items, but expected exactly 1", n);
85ab1f
+    }
85ab1f
+
85ab1f
+    text = POPs;
85ab1f
+    SvREFCNT_inc(text);         /* the caller will mortalise this */
85ab1f
+
85ab1f
+    FREETMPS;
85ab1f
+
85ab1f
+    PUTBACK;
85ab1f
+
85ab1f
+    return text;
85ab1f
+}
85ab1f
+
85ab1f
 /*
85ab1f
  * This ought to be split into smaller functions. (it is one long function since
85ab1f
  * it exactly parallels the perl version, which was one long thing for
85ab1f
@@ -565,14 +613,14 @@ DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv,
85ab1f
             i = perl_call_method(SvPVX_const(style->freezer), G_EVAL|G_VOID|G_DISCARD);
85ab1f
 	    SPAGAIN;
85ab1f
 	    if (SvTRUE(ERRSV))
85ab1f
-		warn("WARNING(Freezer method call failed): %"SVf"", ERRSV);
85ab1f
+		warn("WARNING(Freezer method call failed): %" SVf, ERRSV);
85ab1f
 	    PUTBACK; FREETMPS; LEAVE;
85ab1f
 	}
85ab1f
 	
85ab1f
 	ival = SvRV(val);
85ab1f
 	realtype = SvTYPE(ival);
85ab1f
 #ifdef DD_USE_OLD_ID_FORMAT
85ab1f
-        idlen = my_snprintf(id, sizeof(id), "0x%"UVxf, PTR2UV(ival));
85ab1f
+        idlen = my_snprintf(id, sizeof(id), "0x%" UVxf, PTR2UV(ival));
85ab1f
 #else
85ab1f
 	id_buffer = PTR2UV(ival);
85ab1f
 	idlen = sizeof(id_buffer);
85ab1f
@@ -630,7 +678,7 @@ DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv,
85ab1f
 #ifdef DD_USE_OLD_ID_FORMAT
85ab1f
 		    warn("ref name not found for %s", id);
85ab1f
 #else
85ab1f
-		    warn("ref name not found for 0x%"UVxf, PTR2UV(ival));
85ab1f
+		    warn("ref name not found for 0x%" UVxf, PTR2UV(ival));
85ab1f
 #endif
85ab1f
 		    return 0;
85ab1f
 		}
85ab1f
@@ -848,10 +896,10 @@ DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv,
85ab1f
 		ilen = inamelen;
85ab1f
 		sv_setiv(ixsv, ix);
85ab1f
 #if PERL_VERSION < 10
85ab1f
-                (void) sprintf(iname+ilen, "%"IVdf, (IV)ix);
85ab1f
+                (void) sprintf(iname+ilen, "%" IVdf, (IV)ix);
85ab1f
 		ilen = strlen(iname);
85ab1f
 #else
85ab1f
-                ilen = ilen + my_sprintf(iname+ilen, "%"IVdf, (IV)ix);
85ab1f
+                ilen = ilen + my_sprintf(iname+ilen, "%" IVdf, (IV)ix);
85ab1f
 #endif
85ab1f
 		iname[ilen++] = ']'; iname[ilen] = '\0';
85ab1f
                 if (style->indent >= 3) {
85ab1f
@@ -886,7 +934,6 @@ DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv,
85ab1f
 	    SV *sname;
85ab1f
 	    HE *entry = NULL;
85ab1f
 	    char *key;
85ab1f
-	    STRLEN klen;
85ab1f
 	    SV *hval;
85ab1f
 	    AV *keys = NULL;
85ab1f
 	
85ab1f
@@ -976,6 +1023,7 @@ DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv,
85ab1f
                 char *nkey_buffer = NULL;
85ab1f
                 STRLEN nticks = 0;
85ab1f
 		SV* keysv;
85ab1f
+                STRLEN klen;
85ab1f
 		STRLEN keylen;
85ab1f
                 STRLEN nlen;
85ab1f
 		bool do_utf8 = FALSE;
85ab1f
@@ -1029,7 +1077,7 @@ DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv,
85ab1f
                 if (style->quotekeys || key_needs_quote(key,keylen)) {
85ab1f
                     if (do_utf8 || style->useqq) {
85ab1f
                         STRLEN ocur = SvCUR(retval);
85ab1f
-                        nlen = esc_q_utf8(aTHX_ retval, key, klen, do_utf8, style->useqq);
85ab1f
+                        klen = nlen = esc_q_utf8(aTHX_ retval, key, klen, do_utf8, style->useqq);
85ab1f
                         nkey = SvPVX(retval) + ocur;
85ab1f
                     }
85ab1f
                     else {
85ab1f
@@ -1095,9 +1143,41 @@ DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv,
85ab1f
 	    SvREFCNT_dec(totpad);
85ab1f
 	}
85ab1f
 	else if (realtype == SVt_PVCV) {
85ab1f
-	    sv_catpvs(retval, "sub { \"DUMMY\" }");
85ab1f
-            if (style->purity)
85ab1f
-		warn("Encountered CODE ref, using dummy placeholder");
85ab1f
+            if (style->deparse) {
85ab1f
+                SV *deparsed = sv_2mortal(deparsed_output(aTHX_ val));
85ab1f
+                SV *fullpad = sv_2mortal(newSVsv(style->sep));
85ab1f
+                const char *p;
85ab1f
+                STRLEN plen;
85ab1f
+                I32 i;
85ab1f
+
85ab1f
+                sv_catsv(fullpad, style->pad);
85ab1f
+                sv_catsv(fullpad, apad);
85ab1f
+                for (i = 0; i < level; i++) {
85ab1f
+                    sv_catsv(fullpad, style->xpad);
85ab1f
+                }
85ab1f
+
85ab1f
+                sv_catpvs(retval, "sub ");
85ab1f
+                p = SvPV(deparsed, plen);
85ab1f
+                while (plen > 0) {
85ab1f
+                    const char *nl = (const char *) memchr(p, '\n', plen);
85ab1f
+                    if (!nl) {
85ab1f
+                        sv_catpvn(retval, p, plen);
85ab1f
+                        break;
85ab1f
+                    }
85ab1f
+                    else {
85ab1f
+                        size_t n = nl - p;
85ab1f
+                        sv_catpvn(retval, p, n);
85ab1f
+                        sv_catsv(retval, fullpad);
85ab1f
+                        p += n + 1;
85ab1f
+                        plen -= n + 1;
85ab1f
+                    }
85ab1f
+                }
85ab1f
+            }
85ab1f
+            else {
85ab1f
+                sv_catpvs(retval, "sub { \"DUMMY\" }");
85ab1f
+                if (style->purity)
85ab1f
+                    warn("Encountered CODE ref, using dummy placeholder");
85ab1f
+            }
85ab1f
 	}
85ab1f
 	else {
85ab1f
 	    warn("cannot handle ref type %d", (int)realtype);
85ab1f
@@ -1144,7 +1224,7 @@ DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv,
85ab1f
 	
85ab1f
 	if (namelen) {
85ab1f
 #ifdef DD_USE_OLD_ID_FORMAT
85ab1f
-	    idlen = my_snprintf(id, sizeof(id), "0x%"UVxf, PTR2UV(val));
85ab1f
+	    idlen = my_snprintf(id, sizeof(id), "0x%" UVxf, PTR2UV(val));
85ab1f
 #else
85ab1f
 	    id_buffer = PTR2UV(val);
85ab1f
 	    idlen = sizeof(id_buffer);
85ab1f
@@ -1184,9 +1264,9 @@ DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv,
85ab1f
         if (DD_is_integer(val)) {
85ab1f
             STRLEN len;
85ab1f
 	    if (SvIsUV(val))
85ab1f
-	      len = my_snprintf(tmpbuf, sizeof(tmpbuf), "%"UVuf, SvUV(val));
85ab1f
+	      len = my_snprintf(tmpbuf, sizeof(tmpbuf), "%" UVuf, SvUV(val));
85ab1f
 	    else
85ab1f
-	      len = my_snprintf(tmpbuf, sizeof(tmpbuf), "%"IVdf, SvIV(val));
85ab1f
+	      len = my_snprintf(tmpbuf, sizeof(tmpbuf), "%" IVdf, SvIV(val));
85ab1f
             if (SvPOK(val)) {
85ab1f
               /* Need to check to see if this is a string such as " 0".
85ab1f
                  I'm assuming from sprintf isn't going to clash with utf8. */
85ab1f
@@ -1412,53 +1492,55 @@ Data_Dumper_Dumpxs(href, ...)
85ab1f
 		&& (hv = (HV*)SvRV((SV*)href))
85ab1f
 		&& SvTYPE(hv) == SVt_PVHV)		{
85ab1f
 
85ab1f
-		if ((svp = hv_fetch(hv, "seen", 4, FALSE)) && SvROK(*svp))
85ab1f
+		if ((svp = hv_fetchs(hv, "seen", FALSE)) && SvROK(*svp))
85ab1f
 		    seenhv = (HV*)SvRV(*svp);
85ab1f
                 else
85ab1f
                     style.use_sparse_seen_hash = 1;
85ab1f
-		if ((svp = hv_fetch(hv, "noseen", 6, FALSE)))
85ab1f
+		if ((svp = hv_fetchs(hv, "noseen", FALSE)))
85ab1f
                     style.use_sparse_seen_hash = (SvOK(*svp) && SvIV(*svp) != 0);
85ab1f
-		if ((svp = hv_fetch(hv, "todump", 6, FALSE)) && SvROK(*svp))
85ab1f
+		if ((svp = hv_fetchs(hv, "todump", FALSE)) && SvROK(*svp))
85ab1f
 		    todumpav = (AV*)SvRV(*svp);
85ab1f
-		if ((svp = hv_fetch(hv, "names", 5, FALSE)) && SvROK(*svp))
85ab1f
+		if ((svp = hv_fetchs(hv, "names", FALSE)) && SvROK(*svp))
85ab1f
 		    namesav = (AV*)SvRV(*svp);
85ab1f
-		if ((svp = hv_fetch(hv, "indent", 6, FALSE)))
85ab1f
+		if ((svp = hv_fetchs(hv, "indent", FALSE)))
85ab1f
                     style.indent = SvIV(*svp);
85ab1f
-		if ((svp = hv_fetch(hv, "purity", 6, FALSE)))
85ab1f
+		if ((svp = hv_fetchs(hv, "purity", FALSE)))
85ab1f
                     style.purity = SvIV(*svp);
85ab1f
-		if ((svp = hv_fetch(hv, "terse", 5, FALSE)))
85ab1f
+		if ((svp = hv_fetchs(hv, "terse", FALSE)))
85ab1f
 		    terse = SvTRUE(*svp);
85ab1f
-		if ((svp = hv_fetch(hv, "useqq", 5, FALSE)))
85ab1f
+		if ((svp = hv_fetchs(hv, "useqq", FALSE)))
85ab1f
                     style.useqq = SvTRUE(*svp);
85ab1f
-		if ((svp = hv_fetch(hv, "pad", 3, FALSE)))
85ab1f
+		if ((svp = hv_fetchs(hv, "pad", FALSE)))
85ab1f
                     style.pad = *svp;
85ab1f
-		if ((svp = hv_fetch(hv, "xpad", 4, FALSE)))
85ab1f
+		if ((svp = hv_fetchs(hv, "xpad", FALSE)))
85ab1f
                     style.xpad = *svp;
85ab1f
-		if ((svp = hv_fetch(hv, "apad", 4, FALSE)))
85ab1f
+		if ((svp = hv_fetchs(hv, "apad", FALSE)))
85ab1f
 		    apad = *svp;
85ab1f
-		if ((svp = hv_fetch(hv, "sep", 3, FALSE)))
85ab1f
+		if ((svp = hv_fetchs(hv, "sep", FALSE)))
85ab1f
                     style.sep = *svp;
85ab1f
-		if ((svp = hv_fetch(hv, "pair", 4, FALSE)))
85ab1f
+		if ((svp = hv_fetchs(hv, "pair", FALSE)))
85ab1f
                     style.pair = *svp;
85ab1f
-		if ((svp = hv_fetch(hv, "varname", 7, FALSE)))
85ab1f
+		if ((svp = hv_fetchs(hv, "varname", FALSE)))
85ab1f
 		    varname = *svp;
85ab1f
-		if ((svp = hv_fetch(hv, "freezer", 7, FALSE)))
85ab1f
+		if ((svp = hv_fetchs(hv, "freezer", FALSE)))
85ab1f
                     style.freezer = *svp;
85ab1f
-		if ((svp = hv_fetch(hv, "toaster", 7, FALSE)))
85ab1f
+		if ((svp = hv_fetchs(hv, "toaster", FALSE)))
85ab1f
                     style.toaster = *svp;
85ab1f
-		if ((svp = hv_fetch(hv, "deepcopy", 8, FALSE)))
85ab1f
+		if ((svp = hv_fetchs(hv, "deepcopy", FALSE)))
85ab1f
                     style.deepcopy = SvTRUE(*svp);
85ab1f
-		if ((svp = hv_fetch(hv, "quotekeys", 9, FALSE)))
85ab1f
+		if ((svp = hv_fetchs(hv, "quotekeys", FALSE)))
85ab1f
                     style.quotekeys = SvTRUE(*svp);
85ab1f
-                if ((svp = hv_fetch(hv, "trailingcomma", 13, FALSE)))
85ab1f
+                if ((svp = hv_fetchs(hv, "trailingcomma", FALSE)))
85ab1f
                     style.trailingcomma = SvTRUE(*svp);
85ab1f
-		if ((svp = hv_fetch(hv, "bless", 5, FALSE)))
85ab1f
+                if ((svp = hv_fetchs(hv, "deparse", FALSE)))
85ab1f
+                    style.deparse = SvTRUE(*svp);
85ab1f
+		if ((svp = hv_fetchs(hv, "bless", FALSE)))
85ab1f
                     style.bless = *svp;
85ab1f
-		if ((svp = hv_fetch(hv, "maxdepth", 8, FALSE)))
85ab1f
+		if ((svp = hv_fetchs(hv, "maxdepth", FALSE)))
85ab1f
                     style.maxdepth = SvIV(*svp);
85ab1f
-		if ((svp = hv_fetch(hv, "maxrecurse", 10, FALSE)))
85ab1f
+		if ((svp = hv_fetchs(hv, "maxrecurse", FALSE)))
85ab1f
                     style.maxrecurse = SvIV(*svp);
85ab1f
-		if ((svp = hv_fetch(hv, "sortkeys", 8, FALSE))) {
85ab1f
+		if ((svp = hv_fetchs(hv, "sortkeys", FALSE))) {
85ab1f
                     SV *sv = *svp;
85ab1f
                     if (! SvTRUE(sv))
85ab1f
                         style.sortkeys = NULL;
85ab1f
@@ -1525,9 +1607,10 @@ Data_Dumper_Dumpxs(href, ...)
85ab1f
 		    }
85ab1f
 		    else {
85ab1f
 			STRLEN nchars;
85ab1f
-			sv_setpvn(name, "$", 1);
85ab1f
+			sv_setpvs(name, "$");
85ab1f
 			sv_catsv(name, varname);
85ab1f
-			nchars = my_snprintf(tmpbuf, sizeof(tmpbuf), "%"IVdf, (IV)(i+1));
85ab1f
+			nchars = my_snprintf(tmpbuf, sizeof(tmpbuf), "%" IVdf,
85ab1f
+                                                                     (IV)(i+1));
85ab1f
 			sv_catpvn(name, tmpbuf, nchars);
85ab1f
 		    }
85ab1f
 		
85ab1f
@@ -1575,7 +1658,7 @@ Data_Dumper_Dumpxs(href, ...)
85ab1f
 			sv_catpvs(retval, ";");
85ab1f
                         sv_catsv(retval, style.sep);
85ab1f
 		    }
85ab1f
-		    sv_setpvn(valstr, "", 0);
85ab1f
+		    SvPVCLEAR(valstr);
85ab1f
 		    if (gimme == G_ARRAY) {
85ab1f
 			XPUSHs(sv_2mortal(retval));
85ab1f
 			if (i < imax)	/* not the last time thro ? */
85ab1f
diff --git a/t/bugs.t b/t/bugs.t
85ab1f
index a440b0a..5db82da 100644
85ab1f
--- a/t/bugs.t
85ab1f
+++ b/t/bugs.t
85ab1f
@@ -12,7 +12,7 @@ BEGIN {
85ab1f
 }
85ab1f
 
85ab1f
 use strict;
85ab1f
-use Test::More tests => 15;
85ab1f
+use Test::More tests => 24;
85ab1f
 use Data::Dumper;
85ab1f
 
85ab1f
 {
85ab1f
@@ -144,4 +144,39 @@ SKIP: {
85ab1f
   &$tests;
85ab1f
 }
85ab1f
 
85ab1f
+{ # https://rt.perl.org/Ticket/Display.html?id=128524
85ab1f
+    my $want;
85ab1f
+    my $runtime = "runtime";
85ab1f
+    my $requires = "requires";
85ab1f
+    utf8::upgrade(my $uruntime = $runtime);
85ab1f
+    utf8::upgrade(my $urequires = $requires);
85ab1f
+    for my $run ($runtime, $uruntime) {
85ab1f
+        for my $req ($requires, $urequires) {
85ab1f
+            my $data = { $run => { $req => { foo => "bar" } } };
85ab1f
+            local $Data::Dumper::Useperl = 1;
85ab1f
+            # we want them all the same
85ab1f
+            defined $want or $want = Dumper($data);
85ab1f
+            is(Dumper( $data ), $want, "utf-8 indents");
85ab1f
+          SKIP:
85ab1f
+            {
85ab1f
+                defined &Data::Dumper::Dumpxs
85ab1f
+                  or skip "No XS available", 1;
85ab1f
+                local $Data::Dumper::Useperl = 0;
85ab1f
+                is(Dumper( $data ), $want, "utf8-indents");
85ab1f
+            }
85ab1f
+        }
85ab1f
+    }
85ab1f
+}
85ab1f
+
85ab1f
+# RT#130487 - stack management bug in XS deparse
85ab1f
+SKIP: {
85ab1f
+    skip "No XS available", 1 if !defined &Data::Dumper::Dumpxs;
85ab1f
+    sub rt130487_args { 0 + @_ }
85ab1f
+    my $code = sub {};
85ab1f
+    local $Data::Dumper::Useperl = 0;
85ab1f
+    local $Data::Dumper::Deparse = 1;
85ab1f
+    my $got = rt130487_args( Dumper($code) );
85ab1f
+    is($got, 1, "stack management in XS deparse works, rt 130487");
85ab1f
+}
85ab1f
+
85ab1f
 # EOF
85ab1f
diff --git a/t/deparse.t b/t/deparse.t
85ab1f
index c281fce..cddde8c 100644
85ab1f
--- a/t/deparse.t
85ab1f
+++ b/t/deparse.t
85ab1f
@@ -15,7 +15,7 @@ BEGIN {
85ab1f
 use strict;
85ab1f
 
85ab1f
 use Data::Dumper;
85ab1f
-use Test::More tests =>  8;
85ab1f
+use Test::More tests =>  16;
85ab1f
 use lib qw( ./t/lib );
85ab1f
 use Testing qw( _dumptostr );
85ab1f
 
85ab1f
@@ -24,7 +24,9 @@ use Testing qw( _dumptostr );
85ab1f
 
85ab1f
 note("\$Data::Dumper::Deparse and Deparse()");
85ab1f
 
85ab1f
-{
85ab1f
+for my $useperl (0, 1) {
85ab1f
+    local $Data::Dumper::Useperl = $useperl;
85ab1f
+
85ab1f
     my ($obj, %dumps, $deparse, $starting);
85ab1f
     use strict;
85ab1f
     my $struct = { foo => "bar\nbaz", quux => sub { "fleem" } };
85ab1f
@@ -46,11 +48,11 @@ note("\$Data::Dumper::Deparse and Deparse()");
85ab1f
     $dumps{'objzero'} = _dumptostr($obj);
85ab1f
 
85ab1f
     is($dumps{'noprev'}, $dumps{'dddzero'},
85ab1f
-        "No previous setting and \$Data::Dumper::Deparse = 0 are equivalent");
85ab1f
+        "No previous setting and \$Data::Dumper::Deparse = 0 are equivalent (useperl=$useperl)");
85ab1f
     is($dumps{'noprev'}, $dumps{'objempty'},
85ab1f
-        "No previous setting and Deparse() are equivalent");
85ab1f
+        "No previous setting and Deparse() are equivalent (useperl=$useperl)");
85ab1f
     is($dumps{'noprev'}, $dumps{'objzero'},
85ab1f
-        "No previous setting and Deparse(0) are equivalent");
85ab1f
+        "No previous setting and Deparse(0) are equivalent (useperl=$useperl)");
85ab1f
 
85ab1f
     local $Data::Dumper::Deparse = 1;
85ab1f
     $obj = Data::Dumper->new( [ $struct ] );
85ab1f
@@ -62,19 +64,19 @@ note("\$Data::Dumper::Deparse and Deparse()");
85ab1f
     $dumps{'objone'} = _dumptostr($obj);
85ab1f
 
85ab1f
     is($dumps{'dddtrue'}, $dumps{'objone'},
85ab1f
-        "\$Data::Dumper::Deparse = 1 and Deparse(1) are equivalent");
85ab1f
+        "\$Data::Dumper::Deparse = 1 and Deparse(1) are equivalent (useperl=$useperl)");
85ab1f
 
85ab1f
     isnt($dumps{'dddzero'}, $dumps{'dddtrue'},
85ab1f
-        "\$Data::Dumper::Deparse = 0 differs from \$Data::Dumper::Deparse = 1");
85ab1f
+        "\$Data::Dumper::Deparse = 0 differs from \$Data::Dumper::Deparse = 1 (useperl=$useperl)");
85ab1f
 
85ab1f
     like($dumps{'dddzero'},
85ab1f
         qr/quux.*?sub.*?DUMMY/s,
85ab1f
-        "\$Data::Dumper::Deparse = 0 reports DUMMY instead of deparsing coderef");
85ab1f
+        "\$Data::Dumper::Deparse = 0 reports DUMMY instead of deparsing coderef (useperl=$useperl)");
85ab1f
     unlike($dumps{'dddtrue'},
85ab1f
         qr/quux.*?sub.*?DUMMY/s,
85ab1f
-        "\$Data::Dumper::Deparse = 1 does not report DUMMY");
85ab1f
+        "\$Data::Dumper::Deparse = 1 does not report DUMMY (useperl=$useperl)");
85ab1f
     like($dumps{'dddtrue'},
85ab1f
         qr/quux.*?sub.*?use\sstrict.*?fleem/s,
85ab1f
-        "\$Data::Dumper::Deparse = 1 deparses coderef");
85ab1f
+        "\$Data::Dumper::Deparse = 1 deparses coderef (useperl=$useperl)");
85ab1f
 }
85ab1f
 
85ab1f
-- 
85ab1f
2.9.3
85ab1f