r2445 - in packages/libdigest-crc-perl/trunk: . debian lib/Digest t

Gunnar Wolf gwolf at costa.debian.org
Sun Mar 19 18:01:59 UTC 2006


Author: gwolf
Date: 2006-03-19 18:01:59 +0000 (Sun, 19 Mar 2006)
New Revision: 2445

Modified:
   packages/libdigest-crc-perl/trunk/CRC.xs
   packages/libdigest-crc-perl/trunk/Changes
   packages/libdigest-crc-perl/trunk/META.yml
   packages/libdigest-crc-perl/trunk/debian/changelog
   packages/libdigest-crc-perl/trunk/debian/watch
   packages/libdigest-crc-perl/trunk/lib/Digest/CRC.pm
   packages/libdigest-crc-perl/trunk/t/crc.t
Log:
New upstream release



Modified: packages/libdigest-crc-perl/trunk/CRC.xs
===================================================================
--- packages/libdigest-crc-perl/trunk/CRC.xs	2006-03-19 17:59:45 UTC (rev 2444)
+++ packages/libdigest-crc-perl/trunk/CRC.xs	2006-03-19 18:01:59 UTC (rev 2445)
@@ -41,6 +41,17 @@
 
 PROTOTYPES: ENABLE
 
+UV
+_reflect(in, width)
+	UV in
+	IV width
+
+	CODE:
+		RETVAL = reflect(in, width);
+
+	OUTPUT:
+		RETVAL
+
 SV *
 _tabinit(width, poly, ref)
 	IV width

Modified: packages/libdigest-crc-perl/trunk/Changes
===================================================================
--- packages/libdigest-crc-perl/trunk/Changes	2006-03-19 17:59:45 UTC (rev 2444)
+++ packages/libdigest-crc-perl/trunk/Changes	2006-03-19 18:01:59 UTC (rev 2445)
@@ -22,6 +22,9 @@
 	- crc8 bug fixed. Thanks to Mathis Moder <mathis at pixelconcepts.de>
 
 0.09  Mon Jul 05 23:37:13 2004
-	- major performance improvements by adding optional XS code. 
+        - major performance improvements by adding optional XS code.
           Thanks to Marcus Holland-Moritz <mhx-perl at gmx.net>
 
+0.10  Sat Mar 18 21:07:22 2004
+        - adapted behaviour to Digest
+

Modified: packages/libdigest-crc-perl/trunk/META.yml
===================================================================
--- packages/libdigest-crc-perl/trunk/META.yml	2006-03-19 17:59:45 UTC (rev 2444)
+++ packages/libdigest-crc-perl/trunk/META.yml	2006-03-19 18:01:59 UTC (rev 2445)
@@ -1,16 +1,10 @@
---- #YAML:1.0
-name: Digest-CRC
-version: 0.09
-author:
-  - Oliver Maul, oli at 42.nu
-abstract: Generic CRC functions
-license: perl
-requires: {}
-recommends: {}
-build_requires: {}
-conflicts: {}
-provides:
-  Digest::CRC:
-    file: lib/Digest/CRC.pm
-    version: 0.09
-generated_by: Module::Build version 0.22
+# http://module-build.sourceforge.net/META-spec.html
+#XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
+name:         Digest-CRC
+version:      0.10
+version_from: lib/Digest/CRC.pm
+installdirs:  site
+requires:
+
+distribution_type: module
+generated_by: ExtUtils::MakeMaker version 6.17

Modified: packages/libdigest-crc-perl/trunk/debian/changelog
===================================================================
--- packages/libdigest-crc-perl/trunk/debian/changelog	2006-03-19 17:59:45 UTC (rev 2444)
+++ packages/libdigest-crc-perl/trunk/debian/changelog	2006-03-19 18:01:59 UTC (rev 2445)
@@ -1,3 +1,10 @@
+libdigest-crc-perl (0.10-1) unstable; urgency=low
+
+  * New upstream release, including changes that fix O(n) memory usage
+    (Closes: #342543)
+
+ -- Gunnar Wolf <gwolf at debian.org>  Sun, 19 Mar 2006 05:59:56 -0600
+
 libdigest-crc-perl (0.09-1) unstable; urgency=low
 
   * Initial Release.

Modified: packages/libdigest-crc-perl/trunk/debian/watch
===================================================================
--- packages/libdigest-crc-perl/trunk/debian/watch	2006-03-19 17:59:45 UTC (rev 2444)
+++ packages/libdigest-crc-perl/trunk/debian/watch	2006-03-19 18:01:59 UTC (rev 2445)
@@ -1,3 +1,3 @@
 version=3
-http://mirrors.kernel.org/cpan/modules/by-module/Digest/Digest-CRC-([\d\.]+)\.tar\.gz
+http://www.cpan.org/modules/by-module/Digest/Digest-CRC-([\d\.]+)\.tar\.gz
 

Modified: packages/libdigest-crc-perl/trunk/lib/Digest/CRC.pm
===================================================================
--- packages/libdigest-crc-perl/trunk/lib/Digest/CRC.pm	2006-03-19 17:59:45 UTC (rev 2444)
+++ packages/libdigest-crc-perl/trunk/lib/Digest/CRC.pm	2006-03-19 18:01:59 UTC (rev 2445)
@@ -16,7 +16,7 @@
  crc32_hex crc32_base64
 );
 
-$VERSION    = '0.09';
+$VERSION    = '0.10';
 $XS_VERSION = $VERSION;
 $VERSION    = eval $VERSION;
 
@@ -30,6 +30,16 @@
   1
 };
 
+sub _reflectperl {
+  my ($in, $width) = @_;
+  my $out = 0;
+  for(my $i=1; $i < ($width+1); $i++) {
+    $out |= 1 << ($width-$i) if ($in & 1);
+    $in=$in>>1;
+  }
+  $out;
+}
+
 # Only load the non-XS stuff on demand
 defined &_crc or eval <<'ENOXS';
 
@@ -74,7 +84,7 @@
 sub _crc {
   my ($message,$width,$init,$xorout,$refin,$refout,$tab) = @_;
   my $crc = $init;
-  $crc = _reflect($crc,$width) if $refin;
+  $crc = __reflect($crc,$width) if $refin;
   my $pos = -length $message;
   my $mask = 2**$width-1;
   while ($pos) {
@@ -86,6 +96,7 @@
   }
 
   if ($refout^$refin) {
+    print STDERR "refout\n";
     $crc = _reflect($crc,$width);
   }
 
@@ -108,9 +119,11 @@
   my %params=@_;
   my $class = ref($that) || $that;
   my $self = {map { ($_ => $params{$_}) }
-                      qw(type width init xorout poly refin refout)};
+                      qw(type width init xorout poly refin refout cont)};
   bless $self, $class;
   $self->reset();
+  map { if (defined($params{$_})) { $self->{$_} = $params{$_} } }
+                      qw(type width init xorout poly refin refout cont);
   $self
 }
 
@@ -131,7 +144,7 @@
     $self->{refin} = $typeparams->[5],
   }
   $self->{_tab} = _tabinit($self->{width}, $self->{poly}, $self->{refin});
-  delete $self->{_data};
+  $self->{_data} = undef;
   $self
 }
 
@@ -164,10 +177,18 @@
     require Symbol;
     $fh = Symbol::qualify($fh, scalar caller);
   }
-  # $self->{_data} .= do{local$/;<$fh>};
   my $read = 0;
   my $buffer = '';
-  $self->add($buffer) while $read = read $fh, $buffer, 8192;
+  my $crc;
+  my $oldinit = $self->{init};
+  while ($read = read $fh, $buffer, 32*1024) {
+    $self->add($buffer);
+    $crc = $self->digest;
+    $self->{cont}=1;
+    $self->{init}=$crc;
+  }
+  $self->{init} = $oldinit;
+  $self->{_crc} = $crc;
   die __PACKAGE__, " read failed: $!" unless defined $read;
   $self
 }
@@ -177,8 +198,21 @@
 
 sub digest {
   my $self = shift;
-  _crc($self->{_data},$self->{width},$self->{init},$self->{xorout},
-       $self->{refin},$self->{refout},$self->{_tab});
+  my $crc;
+  if (!$self->{_crc}) {
+    my $init = $self->{init};
+    if ($self->{cont}) {
+      $init = ($self->{init} ^ $self->{xorout});
+      $init = _reflect($init, $self->{width}) if $self->{refin};
+    }
+    $crc =_crc($self->{_data},$self->{width},$init,$self->{xorout},
+	 $self->{refin},$self->{refout},$self->{_tab});
+  } else {
+    $crc = $self->{_crc};
+    $self->{_crc} = undef;
+  }
+  $self->{_data} = undef;
+  $crc
 }
 
 sub hexdigest {
@@ -276,8 +310,8 @@
   use Digest::CRC;
 
   $ctx = Digest::CRC->new(type=>"crc16");
-  $ctx = Digest::CRC->new(width=>16, init=>0x0000, xorout=>0x0000, 
-                          poly=>0x8005, refin=>1, refout=>1);
+  $ctx = Digest::CRC->new(width=>16, init=>0x2345, xorout=>0x0000, 
+                          poly=>0x8005, refin=>1, refout=>1, cont=>1);
 
   $ctx->add($data);
   $ctx->addfile(*FILE);

Modified: packages/libdigest-crc-perl/trunk/t/crc.t
===================================================================
--- packages/libdigest-crc-perl/trunk/t/crc.t	2006-03-19 17:59:45 UTC (rev 2444)
+++ packages/libdigest-crc-perl/trunk/t/crc.t	2006-03-19 18:01:59 UTC (rev 2445)
@@ -1,5 +1,5 @@
 BEGIN {
-  $tests = 16;
+  $tests = 18;
   $| = 1;
 
   eval "use Test::More tests => $tests";
@@ -28,12 +28,25 @@
 ok($crcccitt == 10673, 'crcccitt'); 
 ok($crc16 == 47933, 'crc16'); 
 ok($crc8 == 244, 'crc8'); 
-
-my $ctx;
-$ctx = Digest::CRC->new(); 
+my $ctx; $ctx = Digest::CRC->new(); 
 $ctx->add($input);
 ok($ctx->digest == 3421780262, 'OO crc32'); 
 
+# addfile
+open(F,"<Changes")||die "Cannot open Changes";
+$ctx->addfile(F);
+close(F);
+ok($ctx->digest == 83730842, 'OO crc32 with addfile'); 
+
+# start at offset >0 with previous checksum result
+$ctx = Digest::CRC->new(type=>"crc32",cont=>1,init=>1901368946); 
+open(F,"<Changes")||die "Cannot open Changes";
+use Fcntl qw(:seek);
+seek(F,536,Fcntl::SEEK_SET);
+$ctx->addfile(F);
+close(F);
+ok($ctx->digest == 3281456132, 'OO crc32 with addfile'); 
+
 $ctx = Digest::CRC->new(type=>"crcccitt"); 
 $ctx->add($input);
 ok($ctx->digest == 10673, 'OO crcccitt'); 




More information about the Pkg-perl-cvs-commits mailing list