Rev 5215: (vila, for jam) Remove zlib dependency in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu May 6 13:15:50 BST 2010


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5215 [merge]
revision-id: pqm at pqm.ubuntu.com-20100506121546-8s3a5j30c319mtwn
parent: pqm at pqm.ubuntu.com-20100505185116-yheyjpt123oq3wm2
parent: john at arbash-meinel.com-20100429220834-1zg31lotg09qirfc
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2010-05-06 13:15:46 +0100
message:
  (vila, for jam) Remove zlib dependency
modified:
  bzrlib/_chk_map_pyx.pyx        _chk_map_pyx.pyx-20090309111231-peyz7p2azr0dzdrb-1
  setup.py                       setup.py-20050314065409-02f8a0a6e3f9bc70
=== modified file 'bzrlib/_chk_map_pyx.pyx'
--- a/bzrlib/_chk_map_pyx.pyx	2010-02-17 17:11:16 +0000
+++ b/bzrlib/_chk_map_pyx.pyx	2010-04-29 22:08:34 +0000
@@ -36,6 +36,7 @@
     int PyString_CheckExact(object)
     char *PyString_AS_STRING(object s)
     Py_ssize_t PyString_GET_SIZE(object)
+    unsigned long PyInt_AsUnsignedLongMask(object) except? -1
 
     int PyDict_SetItem(object d, object k, object v) except -1
 
@@ -63,12 +64,8 @@
     PyObject * StaticTuple_GET_ITEM_ptr "StaticTuple_GET_ITEM" (StaticTuple,
                                                                 Py_ssize_t)
 
-cdef extern from "zlib.h":
-    ctypedef unsigned long uLong
-    ctypedef unsigned int uInt
-    ctypedef unsigned char Bytef
-
-    uLong crc32(uLong crc, Bytef *buf, uInt len)
+cdef object crc32
+from zlib import crc32
 
 
 # Set up the StaticTuple C_API functionality
@@ -101,15 +98,10 @@
     cdef Py_ssize_t num_bits
     cdef Py_ssize_t i, j
     cdef Py_ssize_t num_out_bytes
-    cdef Bytef *c_bit
-    cdef uLong c_len
-    cdef uInt crc_val
+    cdef unsigned long crc_val
     cdef Py_ssize_t out_off
     cdef char *c_out
-    cdef PyObject *bit
 
-    if not StaticTuple_CheckExact(key):
-        raise TypeError('key %r is not a StaticTuple' % (key,))
     num_bits = len(key)
     # 4 bytes per crc32, and another 1 byte between bits
     num_out_bytes = (9 * num_bits) - 1
@@ -119,15 +111,7 @@
         if i > 0:
             c_out[0] = c'\x00'
             c_out = c_out + 1
-        # We use the _ptr variant, because GET_ITEM returns a borrowed
-        # reference, and Pyrex assumes that returned 'object' are a new
-        # reference
-        bit = StaticTuple_GET_ITEM_ptr(key, i)
-        if not PyString_CheckExact_ptr(bit):
-            raise TypeError('Bit %d of %r is not a string' % (i, key))
-        c_bit = <Bytef *>PyString_AS_STRING_ptr(bit)
-        c_len = PyString_GET_SIZE_ptr(bit)
-        crc_val = crc32(0, c_bit, c_len)
+        crc_val = PyInt_AsUnsignedLongMask(crc32(key[i]))
         # Hex(val) order
         sprintf(c_out, '%08X', crc_val)
         c_out = c_out + 8
@@ -139,15 +123,10 @@
     cdef Py_ssize_t num_bits
     cdef Py_ssize_t i, j
     cdef Py_ssize_t num_out_bytes
-    cdef Bytef *c_bit
-    cdef uLong c_len
-    cdef uInt crc_val
+    cdef unsigned long crc_val
     cdef Py_ssize_t out_off
     cdef char *c_out
-    cdef PyObject *bit
 
-    if not StaticTuple_CheckExact(key):
-        raise TypeError('key %r is not a StaticTuple' % (key,))
     num_bits = len(key)
     # 4 bytes per crc32, and another 1 byte between bits
     num_out_bytes = (5 * num_bits) - 1
@@ -157,13 +136,7 @@
         if i > 0:
             c_out[0] = c'\x00'
             c_out = c_out + 1
-        bit = StaticTuple_GET_ITEM_ptr(key, i)
-        if not PyString_CheckExact_ptr(bit):
-            raise TypeError('Bit %d of %r is not a string: %r'
-                            % (i, key, <object>bit))
-        c_bit = <Bytef *>PyString_AS_STRING_ptr(bit)
-        c_len = PyString_GET_SIZE_ptr(bit)
-        crc_val = crc32(0, c_bit, c_len)
+        crc_val = PyInt_AsUnsignedLongMask(crc32(key[i]))
         # MSB order
         c_out[0] = (crc_val >> 24) & 0xFF
         c_out[1] = (crc_val >> 16) & 0xFF

=== modified file 'setup.py'
--- a/setup.py	2010-04-08 04:34:03 +0000
+++ b/setup.py	2010-04-19 21:04:31 +0000
@@ -281,7 +281,6 @@
     add_pyrex_extension('bzrlib._dirstate_helpers_pyx',
                         libraries=['Ws2_32'])
     add_pyrex_extension('bzrlib._walkdirs_win32')
-    z_lib = 'zdll'
 else:
     if have_pyrex and pyrex_version_info[:3] == (0,9,4):
         # Pyrex 0.9.4.1 fails to compile this extension correctly
@@ -298,8 +297,7 @@
     else:
         add_pyrex_extension('bzrlib._dirstate_helpers_pyx')
     add_pyrex_extension('bzrlib._readdir_pyx')
-    z_lib = 'z'
-add_pyrex_extension('bzrlib._chk_map_pyx', libraries=[z_lib])
+add_pyrex_extension('bzrlib._chk_map_pyx')
 ext_modules.append(Extension('bzrlib._patiencediff_c',
                              ['bzrlib/_patiencediff_c.c']))
 if have_pyrex and pyrex_version_info < (0, 9, 6, 3):




More information about the bazaar-commits mailing list