r63213 - in /branches/upstream/libdigest-crc-perl/current: CRC.xs Changes README lib/Digest/CRC.pm t/crc.t

ansgar-guest at users.alioth.debian.org ansgar-guest at users.alioth.debian.org
Sun Oct 3 15:06:55 UTC 2010


Author: ansgar-guest
Date: Sun Oct  3 15:06:40 2010
New Revision: 63213

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=63213
Log:
[svn-upgrade] new version libdigest-crc-perl (0.16)

Modified:
    branches/upstream/libdigest-crc-perl/current/CRC.xs
    branches/upstream/libdigest-crc-perl/current/Changes
    branches/upstream/libdigest-crc-perl/current/README
    branches/upstream/libdigest-crc-perl/current/lib/Digest/CRC.pm
    branches/upstream/libdigest-crc-perl/current/t/crc.t

Modified: branches/upstream/libdigest-crc-perl/current/CRC.xs
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdigest-crc-perl/current/CRC.xs?rev=63213&op=diff
==============================================================================
--- branches/upstream/libdigest-crc-perl/current/CRC.xs (original)
+++ branches/upstream/libdigest-crc-perl/current/CRC.xs Sun Oct  3 15:06:40 2010
@@ -148,3 +148,45 @@
 
         OUTPUT:
 		RETVAL
+
+SV *
+_crc64(message)
+          SV * message
+
+          PREINIT:
+                  unsigned long long poly64rev = 0xd800000000000000ULL;
+                  unsigned long long crc = 0x0000000000000000ULL;
+                  unsigned long long part;
+                  int i, j;
+                  static int init = 0;
+                  static unsigned long long CRCTable[256];
+                  STRLEN len;
+                  const char *msg, *end;
+
+          CODE:
+               SvGETMAGIC(message);
+               msg = SvPV(message, len);
+               end = msg + len;
+
+               if (!init) {
+                 init = 1;
+
+                 for (i = 0; i < 256; i++) {
+                   part = i;
+                   for (j = 0; j < 8; j++) {
+                     if (part & 1)
+                       part = (part >> 1) ^ poly64rev;
+                     else
+                       part >>= 1;
+                   }
+                   CRCTable[i] = part;
+                 }
+               }
+               while (msg < end)
+                 crc = CRCTable[(crc ^ *msg++) & 0xff] ^ (crc >> 8);
+
+               RETVAL = newSVuv(crc);
+
+        OUTPUT:
+               RETVAL
+

Modified: branches/upstream/libdigest-crc-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdigest-crc-perl/current/Changes?rev=63213&op=diff
==============================================================================
--- branches/upstream/libdigest-crc-perl/current/Changes (original)
+++ branches/upstream/libdigest-crc-perl/current/Changes Sun Oct  3 15:06:40 2010
@@ -40,3 +40,13 @@
 0.14  Mon Nov  5 08:10:11 2007
         - fixed __reflect error in non XS part
 
+0.15  Sun Sep 12 13:46:13 2010
+        - added crc64 support, #50064
+          Thanks to Anders Ossowicki <aowi at novozymes.com>
+        - added bit reversing per byte, #59575
+          Thanks to Joel Peshkin <joel at peshkin.net>
+        - clone method nwo copies content too
+          Thanks to Stefan Ochs <stefan.ochs at opentext.com>
+
+0.16  Wed Sep 29 08:11:42 2010
+        - fixed crc64 support for non-xs case, #61490, #61491

Modified: branches/upstream/libdigest-crc-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdigest-crc-perl/current/README?rev=63213&op=diff
==============================================================================
--- branches/upstream/libdigest-crc-perl/current/README (original)
+++ branches/upstream/libdigest-crc-perl/current/README Sun Oct  3 15:06:40 2010
@@ -1,4 +1,4 @@
-Digest::CRC version 0.14
+Digest::CRC version 0.16
 ========================
 
 NAME

Modified: branches/upstream/libdigest-crc-perl/current/lib/Digest/CRC.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdigest-crc-perl/current/lib/Digest/CRC.pm?rev=63213&op=diff
==============================================================================
--- branches/upstream/libdigest-crc-perl/current/lib/Digest/CRC.pm (original)
+++ branches/upstream/libdigest-crc-perl/current/lib/Digest/CRC.pm Sun Oct  3 15:06:40 2010
@@ -8,15 +8,16 @@
 @ISA = qw(Exporter);
 
 @EXPORT_OK = qw(
- crc8 crcccitt crc16 crc32 crc
+ crc8 crcccitt crc16 crc32 crc64 crc
  crc_hex crc_base64
  crcccitt_hex crcccitt_base64
  crc8_hex crc8_base64
  crc16_hex crc16_base64
  crc32_hex crc32_base64
+ crc64_hex crc64_base64
 );
 
-$VERSION    = '0.14';
+$VERSION    = '0.16';
 $XS_VERSION = $VERSION;
 $VERSION    = eval $VERSION;
 
@@ -41,9 +42,9 @@
 }
 
 # Only load the non-XS stuff on demand
-defined &_crc or eval <<'ENOXS';
-
-sub _reflect {
+defined &_crc or eval <<'ENOXS' or die $@;
+
+sub _reflect($$) {
   my ($in, $width) = @_;
   my $out = 0;
   for(my $i=1; $i < ($width+1); $i++) {
@@ -53,7 +54,7 @@
   $out;
 }
 
-sub _tabinit {
+sub _tabinit($$$) {
   my ($width,$poly_in,$ref) = @_;
   my @crctab;
   my $poly = $poly_in;
@@ -82,10 +83,14 @@
   \@crctab;
 }
 
-sub _crc {
+sub _crc($$$$$$$) {
   my ($message,$width,$init,$xorout,$refin,$refout,$tab) = @_;
   my $crc = $init;
-  $crc = _reflect($crc,$width) if $refin;
+  if ($refin == 1) {
+    $crc = _reflect($crc,$width);
+  } elsif ($refin > 1 and $refin <= $width) {
+    $crc = _reflect($crc,$refin);
+  }
   my $pos = -length $message;
   my $mask = 2**$width-1;
   while ($pos) {
@@ -96,13 +101,19 @@
     }
   }
 
-  if ($refout^$refin) {
-    $crc = _reflect($crc,$width);
+  if ($refout && !$refin) {
+    if ($refout == 1) {
+      $crc = _reflect($crc,$width);
+    } elsif ($refout > 1 and $refout <= $width) {
+      $crc = _reflect($crc,$refout);
+    }
   }
 
   $crc = $crc ^ $xorout;
   $crc & $mask;
 }
+
+1;
 
 ENOXS
 
@@ -232,7 +243,8 @@
     xorout => $self->{xorout},
     poly => $self->{poly},
     refin => $self->{refin},
-    refout => $self->{refout}
+    refout => $self->{refout},
+    _data => $self->{_data}
   };
   bless $clone, ref $self || $self;
 }
@@ -267,6 +279,11 @@
 
 sub crc32 { crc($_[0],@{$_typedef{crc32}}) }
 
+# CRC64
+# special XS implementation (_crc64)
+
+sub crc64 { _crc64($_[0]) }
+
 sub crc_hex { _encode_hex &crc }
 
 sub crc_base64 { _encode_base64 &crc }
@@ -286,6 +303,10 @@
 sub crc32_hex { _encode_hex &crc32 }
 
 sub crc32_base64 { _encode_base64 &crc32 }
+
+sub crc64_hex { _encode_hex &crc64 }
+
+sub crc64_base64 { _encode_base64 &crc64 }
 
 1;
 __END__
@@ -298,7 +319,8 @@
 
   # Functional style
 
-  use Digest::CRC qw(crc32 crc16 crcccitt crc crc8);
+  use Digest::CRC qw(crc64 crc32 crc16 crcccitt crc crc8);
+  $crc = crc64("123456789");
   $crc = crc32("123456789");
   $crc = crc16("123456789");
   $crc = crcccitt("123456789");
@@ -325,7 +347,7 @@
 
 The B<Digest::CRC> module calculates CRC sums of all sorts.
 It contains wrapper functions with the correct parameters for CRC-CCITT,
-CRC-16 and CRC-32.
+CRC-16, CRC-32 and CRC-64.
 
 =head1 AUTHOR
 

Modified: branches/upstream/libdigest-crc-perl/current/t/crc.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdigest-crc-perl/current/t/crc.t?rev=63213&op=diff
==============================================================================
--- branches/upstream/libdigest-crc-perl/current/t/crc.t (original)
+++ branches/upstream/libdigest-crc-perl/current/t/crc.t Sun Oct  3 15:06:40 2010
@@ -1,5 +1,8 @@
 BEGIN {
   $tests = 20;
+  if ($ENV{'WITH_CRC64'}) {
+    $tests++;
+  }
   $| = 1;
 
   eval "use Test::More tests => $tests";
@@ -18,11 +21,16 @@
 ENDEV
 }
 
-use Digest::CRC qw(crc32 crc16 crcccitt crc8);
+use Digest::CRC qw(crc64 crc32 crc16 crcccitt crc8);
 ok(1, 'use');
 
 my $input = "123456789";
 my ($crc32,$crc16,$crcccitt,$crc8) = (crc32($input),crc16($input),crcccitt($input),crc8($input));
+
+if ($ENV{'WITH_CRC64'}) {
+  my $crc64 = crc64($input);
+  ok($crc64 == 5090661014116757502, 'crc64 '.$crc64); 
+}
 
 ok($crc32 == 3421780262, 'crc32'); 
 $crc32=$crc32^0xffffffff;
@@ -45,7 +53,7 @@
 $ctx->addfile(F);
 close(F);
 my $y = $ctx->digest;
-ok($y == 2371909219, 'OO crc32 with addfile '.$y); 
+ok($y == 3439495136, 'OO crc32 with addfile '.$y); 
 
 # start at offset >0 with previous checksum result
 $ctx = Digest::CRC->new(type=>"crc32",cont=>1,init=>460478609); 




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