]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blobdiff - lib/Test/Valgrind/Tool/SuppressionsParser.pm
Cleanup Test::Valgrind::Tool::SuppressionsParser.pm
[perl/modules/Test-Valgrind.git] / lib / Test / Valgrind / Tool / SuppressionsParser.pm
index 3f4c29b24a514cd421930c03f83bc35052f31014..6142e4278d01b484eb7bcb0a24ed0fd88d3b3a22 100644 (file)
@@ -9,11 +9,11 @@ Test::Valgrind::Tool::SuppressionsParser - Mock Test::Valgrind::Tool for parsing
 
 =head1 VERSION
 
-Version 1.00
+Version 1.02
 
 =cut
 
-our $VERSION = '1.00';
+our $VERSION = '1.02';
 
 =head1 DESCRIPTION
 
@@ -40,7 +40,7 @@ sub new { shift->_croak('This mock tool isn\'t meant to be used directly') }
 
 =head2 C<report_class_suppressions $session>
 
-Generated reports are L<Test::Valgrind::Report::Suppressions> objects.
+Generated reports are C<Test::Valgrind::Report::Suppressions> objects.
 Their C<data> member contains the raw text of the suppression.
 
 =cut
@@ -60,39 +60,49 @@ sub parse_suppressions {
  my @supps;
 
  while (<$fh>) {
-  s/^\s*#\s//;
-  next if /^==/;
+  s/^\s*#\s//;        # Strip comments
+
+  next if /^==/;      # Valgrind info line
   next if /valgrind/; # and /\Q$file\E/;
-  s/^\s*//;
-  s/<[^>]+>//;
-  s/\s*$//;
+
+  s/^\s*//;           # Strip leading spaces
+  s/<[^>]+>//;        # Strip tags
+  s/\s*$//;           # Strip trailing spaces
   next unless length;
-  if ($_ eq '{') {
+
+  if ($_ eq '{') {      # A suppression block begins
    $in = 1;
-  } elsif ($_ eq '}') {
-   my $unknown_tail;
-   ++$unknown_tail while $s =~ s/(\n)\s*obj:\*\s*$/$1/;
-   $s .= "...\n" if $unknown_tail and $sess->version ge '3.4.0';
-   push @supps, $s;
-   $s  = '';
+  } elsif ($_ eq '}') { # A suppression block ends
+   # With valgrind 3.4.0, we can replace unknown series of frames by '...'
+   if ($sess->version ge '3.4.0') {
+    my $unknown_tail;
+    ++$unknown_tail while $s =~ s/(\n)\s*obj:\*\s*$/$1/;
+    $s .= "...\n" if $unknown_tail;
+   }
+
+   push @supps, $s;     # Add the suppression that just ended to the list
+   $s  = '';            # Reset the state
    $in = 0;
-  } elsif ($in) {
-   $s .= "$_\n";
+  } elsif ($in) {       # We're inside a suppresion block
+   $s .= "$_\n";        # Append the current line to the state
   }
  }
 
  my @extra;
+
  for (@supps) {
   if (/\bfun:(m|c|re)alloc\b/) {
    my $t = $1;
-   my %call;
-   if ($t eq 'm') { # malloc can also be called by calloc or realloc
+
+   my %call; # Frames to append (if the value is 1) or to prepend (if it's 0)
+   if ($t eq 'm') {       # malloc can also be called by calloc or realloc
     $call{$_} = 1 for qw/calloc realloc/;
    } elsif ($t eq 're') { # realloc can also call malloc or free
     $call{$_} = 0 for qw/malloc free/;
-   } elsif ($t eq 'c') { # calloc can also call malloc
+   } elsif ($t eq 'c') {  # calloc can also call malloc
     $call{$_} = 0 for qw/malloc/;
    }
+
    my $c = $_;
    for (keys %call) {
     my $d = $c;
@@ -104,16 +114,12 @@ sub parse_suppressions {
   }
  }
 
- my %dupes;
- @dupes{@supps, @extra} = ();
- @supps = keys %dupes;
-
  my $num;
  $sess->report($self->report_class($sess)->new(
   id   => ++$num,
   kind => 'Suppression',
   data => $_,
- )) for @supps;
+ )) for @supps, @extra;
 }
 
 =head1 SEE ALSO