This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Storable and uninitalized array values
authorMarcus Holland-Moritz <mhx-perl@gmx.net>
Sat, 2 Aug 2003 13:40:16 +0000 (15:40 +0200)
committerJarkko Hietaniemi <jhi@iki.fi>
Sun, 3 Aug 2003 18:44:29 +0000 (18:44 +0000)
From: "Marcus Holland-Moritz" <mhx-perl@gmx.net>
Message-ID: <00ab01c358ea$d940a5b0$0c2f1fac@R2D2>

p4raw-id: //depot/perl@20453

ext/Storable/Storable.xs
ext/Storable/t/freeze.t

index e344700..1bf09c1 100644 (file)
@@ -850,12 +850,12 @@ static const char byteorderstr_56[] = {BYTEORDER_BYTES_56, 0};
 #define STORE_SCALAR(pv, len)  STORE_PV_LEN(pv, len, SX_SCALAR, SX_LSCALAR)
 
 /*
- * Store undef in arrays and hashes without recursing through store().
+ * Store &PL_sv_undef in arrays without recursing through store().
  */
-#define STORE_UNDEF()                                  \
+#define STORE_SV_UNDEF()                                       \
   STMT_START {                                                 \
        cxt->tagnum++;                                          \
-       PUTMARK(SX_UNDEF);                                      \
+       PUTMARK(SX_SV_UNDEF);                                   \
   } STMT_END
 
 /*
@@ -2037,7 +2037,7 @@ static int store_array(stcxt_t *cxt, AV *av)
                sav = av_fetch(av, i, 0);
                if (!sav) {
                        TRACEME(("(#%d) undef item", i));
-                       STORE_UNDEF();
+                       STORE_SV_UNDEF();
                        continue;
                }
                TRACEME(("(#%d) item", i));
index de13af6..bf557df 100644 (file)
@@ -24,7 +24,7 @@ sub BEGIN {
 
 use Storable qw(freeze nfreeze thaw);
 
-print "1..19\n";
+print "1..20\n";
 
 $a = 'toto';
 $b = \$a;
@@ -136,3 +136,9 @@ ok 18, !$@;
 
 thaw $frozen;                  # used to segfault here
 ok 19, 1;
+
+$a = []; $#$a = 2; $a->[1] = undef;
+$b = thaw freeze $a;
+@a = map { ~~ exists $a->[$_] } 0 .. $#$a;
+@b = map { ~~ exists $b->[$_] } 0 .. $#$b;
+ok 20, "@a" eq "@b";