Jeff Hardy avatar Jeff Hardy committed 8620ace

Replace CRC32 implementation with binascii.crc32

Comments (0)

Files changed (6)

IronPython.Zlib/Compress.cs

 /* ****************************************************************************
  *
- * Copyright (c) Jeff Hardy 2007-2008.
+ * Copyright (c) Jeff Hardy 2007-2009.
  *
  * This source code is subject to terms and conditions of the Microsoft Public License. A 
  * copy of the license can be found in the License.txt file at the root of this distribution. If 

IronPython.Zlib/Crc32.cs

-/*
- * Based on example code from the W3C.
- * http://www.w3.org/TR/PNG/#D-CRCAppendix
- * 
- */
-
-using System;
-
-namespace IronPython.Zlib
-{
-    public static class Crc32
-    {
-        public static uint Calculate(uint crc, byte[] buf)
-        {
-            uint c = crc;
-            
-            for(int n = 0; n < buf.Length; n++)
-            {
-                c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8);
-            }
-            
-            return c;
-        }
-
-        static Crc32()
-        {
-            for(uint n = 0; n < 256; n++)
-            {
-                uint c = n;
-                for(int k = 0; k < 8; k++)
-                {
-                    if((c & 1) != 0)
-                        c = 0xedb88320 ^ (c >> 1);
-                    else
-                        c = c >> 1;
-                }
-                crc_table[n] = c;
-            }
-        }
-
-        private static readonly uint[] crc_table = new uint[256];
-    }
-}

IronPython.Zlib/Decompress.cs

 /* ****************************************************************************
  *
- * Copyright (c) Jeff Hardy 2007-2008.
+ * Copyright (c) Jeff Hardy 2007-2009.
  *
  * This source code is subject to terms and conditions of the Microsoft Public License. A 
  * copy of the license can be found in the License.txt file at the root of this distribution. If 

IronPython.Zlib/IronPython.Zlib.csproj

     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="IronPython, Version=2.6.0.1, Culture=neutral, processorArchitecture=MSIL">
+    <Reference Include="IronPython, Version=2.6.0.10, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\..\..\..\..\Bin\IronPython-Nightly\latest.debug\IronPython.dll</HintPath>
+      <HintPath>..\..\..\..\..\Bin\IronPython-2.6B1\IronPython.dll</HintPath>
     </Reference>
-    <Reference Include="IronPython.Modules, Version=2.6.0.1, Culture=neutral, processorArchitecture=MSIL">
+    <Reference Include="IronPython.Modules, Version=2.6.0.10, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\..\..\..\..\Bin\IronPython-Nightly\latest.debug\IronPython.Modules.dll</HintPath>
+      <HintPath>..\..\..\..\..\Bin\IronPython-2.6B1\IronPython.Modules.dll</HintPath>
     </Reference>
-    <Reference Include="Microsoft.Scripting, Version=0.9.5.1, Culture=neutral, processorArchitecture=MSIL">
+    <Reference Include="Microsoft.Scripting, Version=0.9.6.10, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\..\..\..\..\Bin\IronPython-Nightly\latest.debug\Microsoft.Scripting.dll</HintPath>
+      <HintPath>..\..\..\..\..\Bin\IronPython-2.6B1\Microsoft.Scripting.dll</HintPath>
     </Reference>
-    <Reference Include="Microsoft.Scripting.Core, Version=0.9.5.1, Culture=neutral, processorArchitecture=MSIL">
+    <Reference Include="Microsoft.Scripting.Core, Version=0.9.6.10, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\..\..\..\..\Bin\IronPython-Nightly\latest.debug\Microsoft.Scripting.Core.dll</HintPath>
+      <HintPath>..\..\..\..\..\Bin\IronPython-2.6B1\Microsoft.Scripting.Core.dll</HintPath>
     </Reference>
     <Reference Include="System" />
     <Reference Include="System.Data" />
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Compress.cs" />
-    <Compile Include="Crc32.cs" />
     <Compile Include="Decompress.cs" />
     <Compile Include="zlib.net\Adler32.cs" />
     <Compile Include="zlib.net\Deflate.cs" />

IronPython.Zlib/ZlibModule.cs

 /* ****************************************************************************
  *
- * Copyright (c) Jeff Hardy 2007-2008.
+ * Copyright (c) Jeff Hardy 2007-2009.
  *
  * This source code is subject to terms and conditions of the Microsoft Public License. A 
  * copy of the license can be found in the License.txt file at the root of this distribution. If 
 using IronPython.Runtime;
 using IronPython.Runtime.Types;
 using ComponentAce.Compression.Libs.zlib;
+using System.Runtime.InteropServices;
 
 [assembly: PythonModule("zlib", typeof(IronPython.Zlib.ZlibModule))]
 
 
         #region crc32
 
-        public static int crc32(string data)
+        public static int crc32(string data, [DefaultParameterValue(0)] int baseValue)
         {
-            return crc32(data, 0);
+            return IronPython.Modules.PythonBinaryAscii.crc32(data, baseValue);
         }
 
-        public static int crc32(string data, long value)
+        public static int crc32(string data, uint baseValue)
         {
-            return (int)Crc32.Calculate((uint)value, Latin1.GetBytes(data));
+            return IronPython.Modules.PythonBinaryAscii.crc32(data, baseValue);
         }
 
         #endregion

IronPython.Zlib/run_tests.py

    calculated_crc32 = zlib.crc32("\xFF") & 0xFFFFFFFF
    correct_crc32 = 0xFF000000
    if calculated_crc32 != correct_crc32:
-       raise AssertionError("CRC32 value incorrect %08X" % (calculated_crc32,))
+       raise AssertionError("test_crc32_basic: CRC32 value incorrect %08X" % (calculated_crc32,))
 
 def test_resume_negative_crc32():
    previous_crc32 = -1
    calculated_crc32 = zlib.crc32("", previous_crc32)
    if calculated_crc32 != previous_crc32:
-       raise AssertionError("CRC32 should not change if empty string is added %08X" % (calculated_crc32,))
+       raise AssertionError("test_resume_negative_crc32: CRC32 should not change if empty string is added %08X" % (calculated_crc32,))
 
 def test_decompressobj_unused_data():
    s = "\x03\x00leftover" # minimal two byte stream plus eight bytes trailer
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.