Skip Menu |

This queue is for tickets about the Data-Dump CPAN distribution.

Report information
The Basics
Id: 86592
Status: open
Priority: 0/
Queue: Data-Dump

People
Owner: Nobody in particular
Requestors: karel.miko [...] gmail.com
Cc: DMOL [...] cpan.org
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: undesirable change of SV flags
Date: Sun, 30 Jun 2013 20:43:56 +0200
To: bug-Data-Dump [...] rt.cpan.org
From: Karel Miko <karel.miko [...] gmail.com>
Hi, I have experienced some troubles when using Data::Dump with Mojo::JSON more info: https://groups.google.com/forum/?hl=en#!topic/mojolicious/33AustuMAW8 It turned out that under some circumstances Data::Dump sets SVp_IOK (maybe also SVp_NOK) flag on SV beeing dumped. In my opinion a module (Data::Dump) intended for dumping/printing data structure should avoid changing SV flags on data being printed/dumped so I think this is a Data::Dump's bug. The trouble is with this part: do {no warnings 'numeric'; $$rval + 0 eq $$rval} where SVp_IOK flag is turned on after using $$rval in numeric context. I have prepared a patch based on inspecting scalar via B::svref_2object(..)->FLAGS - as B is part of perl core I hope it is not a big trouble to have as a dependency. I am sending the patch attached to this RT as well as via github pull request. -- Karel

Message body is not shown because sender requested not to inline it.

Show quoted text
> The trouble is with this part: > do {no warnings 'numeric'; $$rval + 0 eq $$rval} > where SVp_IOK flag is turned on after using $$rval in numeric context.
That part also stringifies numbers, setting the SVp_POK flag, which trips up modules like JSON::PP and JSON::XS. perl -MJSON::PP -MData::Dump=pp -E 'my $x = {foo => 23, bar => "23"}; say encode_json $x; pp $x; say encode_json $x' -- sebastian
Thanks for fining this one. I just spend a day tracking this problem down.
Hi, Here is alternative fix, which uses Scalar::Util looks_like_number; still use B for testing. Submitted as pull request to github too. Basiliscos.
Subject: alternative-fix.diff
commit 704ecfe7e3d3a2ed986156e1a7c4bdce5bd85934 Author: Ivan Baidakou <dmol@gmx.com> Date: Sat Mar 29 16:53:28 2014 +0300 Alternative fix for RT#86592 diff --git a/Makefile.PL b/Makefile.PL index 920dafc..5653b49 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -10,6 +10,7 @@ WriteMakefile( MIN_PERL_VERSION => 5.006, PREREQ_PM => { Symbol => 0, + 'Scalr::Util' => 0, }, META_MERGE => { resources => { @@ -21,6 +22,7 @@ WriteMakefile( }, BUILD_REQUIRES => { Test => 0, + B => 0, }, ); diff --git a/lib/Data/Dump.pm b/lib/Data/Dump.pm index 5704db6..39f20c7 100644 --- a/lib/Data/Dump.pm +++ b/lib/Data/Dump.pm @@ -12,6 +12,7 @@ require Exporter; $VERSION = "1.22"; $DEBUG = 0; +use Scalar::Util qw/looks_like_number/; use overload (); use vars qw(%seen %refcnt @dump @fixup %require $TRY_BASE64 @FILTERS $INDENT); @@ -229,7 +230,7 @@ sub _dump if (!defined $$rval) { $out = "undef"; } - elsif (do {no warnings 'numeric'; $$rval + 0 eq $$rval}) { + elsif (looks_like_number($$rval) && $$rval + 0 eq $$rval) { $out = $$rval; } else { diff --git a/t/sv-flags.t b/t/sv-flags.t new file mode 100644 index 0000000..baf00e8 --- /dev/null +++ b/t/sv-flags.t @@ -0,0 +1,14 @@ +use strict; + +use Test qw(plan ok); + +plan tests => 2; + +use B; +use Data::Dump qw(dump); + +my $c = "abc"; +my $orig_flags = B::svref_2object(\$c)->FLAGS; +ok(dump($c), qq("abc")); +ok B::svref_2object(\$c)->FLAGS, $orig_flags; +
The issue is even more annoying, because in Mojo::JSON it causes strings to be printed as numbers. Thats because the pIOK Flag is bogusly set. sgikas@dev7:~ $ perl -MDevel::Peek -MData::Dump=pp -E '$a = "foo"; Dump $a; pp($a); Dump($a)' SV = PV(0x88dc20) at 0x8add78 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x8a7010 "foo"\0 CUR = 3 LEN = 16 "foo" SV = PVNV(0x970920) at 0x8add78 REFCNT = 1 FLAGS = (POK,pIOK,pNOK,pPOK) IV = 0 NV = 0 PV = 0x8a7010 "foo"\0 CUR = 3 LEN = 16
Using Data::Dump with data structures later send to MongoDB also has some rather strange effects; e.g. strings like "Information" being stored as numeric Inf. See https://jira.mongodb.org/browse/PERL-992 for more information. Btw.: the Github issue corresponding to this RT ticket is https://github.com/gisle/data-dump/issues/16
On 2014-03-29 10:08:04, DMOL wrote: Show quoted text
> Hi, > > Here is alternative fix, which uses Scalar::Util looks_like_number; > still use B for testing. > > Submitted as pull request to github too. > > Basiliscos.
There's a typo in the PREREQ_PM hash.