~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_chk_map_pyx.pyx

  • Committer: Martin
  • Date: 2010-04-19 21:04:31 UTC
  • mto: This revision was merged to the branch mainline in revision 5215.
  • Revision ID: gzlist@googlemail.com-20100419210431-jvis645p9vdpzuy1
Use python builtin crc32 function rather than zlib C api for _chk_map_pyx

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    int PyString_CheckExact(object)
37
37
    char *PyString_AS_STRING(object s)
38
38
    Py_ssize_t PyString_GET_SIZE(object)
 
39
    unsigned long PyInt_AsUnsignedLongMask(object)
39
40
 
40
41
    int PyDict_SetItem(object d, object k, object v) except -1
41
42
 
63
64
    PyObject * StaticTuple_GET_ITEM_ptr "StaticTuple_GET_ITEM" (StaticTuple,
64
65
                                                                Py_ssize_t)
65
66
 
66
 
cdef extern from "zlib.h":
67
 
    ctypedef unsigned long uLong
68
 
    ctypedef unsigned int uInt
69
 
    ctypedef unsigned char Bytef
70
 
 
71
 
    uLong crc32(uLong crc, Bytef *buf, uInt len)
 
67
cdef object crc32
 
68
from binascii import crc32
72
69
 
73
70
 
74
71
# Set up the StaticTuple C_API functionality
101
98
    cdef Py_ssize_t num_bits
102
99
    cdef Py_ssize_t i, j
103
100
    cdef Py_ssize_t num_out_bytes
104
 
    cdef Bytef *c_bit
105
 
    cdef uLong c_len
106
 
    cdef uInt crc_val
 
101
    cdef unsigned long crc_val
107
102
    cdef Py_ssize_t out_off
108
103
    cdef char *c_out
109
104
    cdef PyObject *bit
125
120
        bit = StaticTuple_GET_ITEM_ptr(key, i)
126
121
        if not PyString_CheckExact_ptr(bit):
127
122
            raise TypeError('Bit %d of %r is not a string' % (i, key))
128
 
        c_bit = <Bytef *>PyString_AS_STRING_ptr(bit)
129
 
        c_len = PyString_GET_SIZE_ptr(bit)
130
 
        crc_val = crc32(0, c_bit, c_len)
 
123
        crc_val = PyInt_AsUnsignedLongMask(crc32(<object>bit))
131
124
        # Hex(val) order
132
125
        sprintf(c_out, '%08X', crc_val)
133
126
        c_out = c_out + 8
139
132
    cdef Py_ssize_t num_bits
140
133
    cdef Py_ssize_t i, j
141
134
    cdef Py_ssize_t num_out_bytes
142
 
    cdef Bytef *c_bit
143
 
    cdef uLong c_len
144
 
    cdef uInt crc_val
 
135
    cdef unsigned long crc_val
145
136
    cdef Py_ssize_t out_off
146
137
    cdef char *c_out
147
138
    cdef PyObject *bit
161
152
        if not PyString_CheckExact_ptr(bit):
162
153
            raise TypeError('Bit %d of %r is not a string: %r'
163
154
                            % (i, key, <object>bit))
164
 
        c_bit = <Bytef *>PyString_AS_STRING_ptr(bit)
165
 
        c_len = PyString_GET_SIZE_ptr(bit)
166
 
        crc_val = crc32(0, c_bit, c_len)
 
155
        crc_val = PyInt_AsUnsignedLongMask(crc32(<object>bit))
167
156
        # MSB order
168
157
        c_out[0] = (crc_val >> 24) & 0xFF
169
158
        c_out[1] = (crc_val >> 16) & 0xFF