# New Ticket Created by  Will Coleda 
# Please include the string:  [perl #46933]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=46933 >


Currently, Data::Dumper treats Undef pmcs like any other pmcs. When dumping, 
then, if a single Undef is repeatedly re-used, the Undef is cached by the 
dumper (like any other PMC) and rather than dump as "undef", dumps as a 
reference. Here's some sample code from particle: 

.sub 'test' :main
    load_bytecode 'Data/Dumper.pir'
    $P0 = new 'Undef'
    $P1 = new 'Undef'
    $P2 = new 'Hash' 

    $P2['$P0'] = $P0
    $P2['$P1'] = $P1
    $P2['$P0-ref'] = $P0 

    $P99 = new 'Data::Dumper'
    $P99.'dumper'( $P2 )
.end 

c:\usr\local\parrot\trunk>parrot ..\t-dumper.pir
"VAR1" => Hash {
    "$P0" => undef,
    "$P0-ref" => \VAR1["$P0"],
    "$P1" => undef
} 

So, since Undef isn't treated in a special fashion, I can understand why 
this works the way it does, and it is arguably correct. 

I propose that we change this to make Undef special cased, and avoid caching 
the Undef PMC in dumper, so that a more perl5-like output is created (where 
undef isn't an object, it's a value. Small patch follows; all tests pass (so 
nothing is relying on the existing behavior.). Thjs changes the output above 
to: 

"VAR1" => Hash {
    "$P0" => undef,
    "$P0-ref" => undef,
    "$P1" => undef
} 

I'll wait for a consensus before applying; There was disagreement on #parrot 
about changing this, putting it out here for discussion. 

$ svn diff runtime/
Index: runtime/parrot/library/Data/Dumper/Base.pir
===================================================================
 --- runtime/parrot/library/Data/Dumper/Base.pir (revision 22503)
+++ runtime/parrot/library/Data/Dumper/Base.pir (working copy)
@@ -188,6 +188,10 @@
     .local string func
     .local string name 

+    # Don't cache undef...
+    $I0 = defined _dump
+    unless $I0 goto NOT_IN_CACHE
+
     (type, name) = self."cache"( paramName, _dump ) 

     if type == -1 goto NOT_IN_CACHE

Reply via email to