/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/_chk_map_pyx.pyx

  • Committer: Robert Collins
  • Date: 2010-05-06 23:41:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506234135-yivbzczw1sejxnxc
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
expected to return an object which can be used to unlock them. This reduces
duplicate code when using cleanups. The previous 'tokens's returned by
``Branch.lock_write`` and ``Repository.lock_write`` are now attributes
on the result of the lock_write. ``repository.RepositoryWriteLockResult``
and ``branch.BranchWriteLockResult`` document this. (Robert Collins)

``log._get_info_for_log_files`` now takes an add_cleanup callable.
(Robert Collins)

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) except? -1
40
39
 
41
40
    int PyDict_SetItem(object d, object k, object v) except -1
42
41
 
64
63
    PyObject * StaticTuple_GET_ITEM_ptr "StaticTuple_GET_ITEM" (StaticTuple,
65
64
                                                                Py_ssize_t)
66
65
 
67
 
cdef object crc32
68
 
from zlib import crc32
 
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)
69
72
 
70
73
 
71
74
# Set up the StaticTuple C_API functionality
98
101
    cdef Py_ssize_t num_bits
99
102
    cdef Py_ssize_t i, j
100
103
    cdef Py_ssize_t num_out_bytes
101
 
    cdef unsigned long crc_val
 
104
    cdef Bytef *c_bit
 
105
    cdef uLong c_len
 
106
    cdef uInt crc_val
102
107
    cdef Py_ssize_t out_off
103
108
    cdef char *c_out
 
109
    cdef PyObject *bit
104
110
 
 
111
    if not StaticTuple_CheckExact(key):
 
112
        raise TypeError('key %r is not a StaticTuple' % (key,))
105
113
    num_bits = len(key)
106
114
    # 4 bytes per crc32, and another 1 byte between bits
107
115
    num_out_bytes = (9 * num_bits) - 1
111
119
        if i > 0:
112
120
            c_out[0] = c'\x00'
113
121
            c_out = c_out + 1
114
 
        crc_val = PyInt_AsUnsignedLongMask(crc32(key[i]))
 
122
        # We use the _ptr variant, because GET_ITEM returns a borrowed
 
123
        # reference, and Pyrex assumes that returned 'object' are a new
 
124
        # reference
 
125
        bit = StaticTuple_GET_ITEM_ptr(key, i)
 
126
        if not PyString_CheckExact_ptr(bit):
 
127
            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)
115
131
        # Hex(val) order
116
132
        sprintf(c_out, '%08X', crc_val)
117
133
        c_out = c_out + 8
123
139
    cdef Py_ssize_t num_bits
124
140
    cdef Py_ssize_t i, j
125
141
    cdef Py_ssize_t num_out_bytes
126
 
    cdef unsigned long crc_val
 
142
    cdef Bytef *c_bit
 
143
    cdef uLong c_len
 
144
    cdef uInt crc_val
127
145
    cdef Py_ssize_t out_off
128
146
    cdef char *c_out
 
147
    cdef PyObject *bit
129
148
 
 
149
    if not StaticTuple_CheckExact(key):
 
150
        raise TypeError('key %r is not a StaticTuple' % (key,))
130
151
    num_bits = len(key)
131
152
    # 4 bytes per crc32, and another 1 byte between bits
132
153
    num_out_bytes = (5 * num_bits) - 1
136
157
        if i > 0:
137
158
            c_out[0] = c'\x00'
138
159
            c_out = c_out + 1
139
 
        crc_val = PyInt_AsUnsignedLongMask(crc32(key[i]))
 
160
        bit = StaticTuple_GET_ITEM_ptr(key, i)
 
161
        if not PyString_CheckExact_ptr(bit):
 
162
            raise TypeError('Bit %d of %r is not a string: %r'
 
163
                            % (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)
140
167
        # MSB order
141
168
        c_out[0] = (crc_val >> 24) & 0xFF
142
169
        c_out[1] = (crc_val >> 16) & 0xFF