~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to _groupcompress_c.pyx

  • Committer: John Arbash Meinel
  • Date: 2009-02-27 18:21:04 UTC
  • mto: (0.23.23 groupcompress_rabin)
  • mto: This revision was merged to the branch mainline in revision 4280.
  • Revision ID: john@arbash-meinel.com-20090227182104-ogr8fu5548ewpzx3
Add a apply_delta2 function, just in case it matters.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
    unsigned long get_delta_hdr_size(unsigned char **datap,
42
42
                                     unsigned char *top)
43
43
    Py_ssize_t DELTA_SIZE_MIN
 
44
    void *patch_delta(void *src_buf, unsigned long src_size,
 
45
                      void *delta_buf, unsigned long delta_size,
 
46
                      unsigned long *dst_size)
44
47
 
45
48
cdef extern from "Python.h":
46
49
    int PyString_CheckExact(object)
213
216
    # *dst_size = out - dst_buf;
214
217
    assert (out - dst_buf) == PyString_GET_SIZE(result)
215
218
    return result
 
219
 
 
220
 
 
221
def apply_delta2(source_bytes, delta_bytes):
 
222
    """Apply a delta generated by make_delta to source_bytes."""
 
223
    # This defers to the patch-delta code rather than implementing it here
 
224
    # If this is faster, we can bring the memory allocation and error handling
 
225
    # into apply_delta(), and leave the primary loop in a separate C func.
 
226
    cdef char *source, *delta, *target
 
227
    cdef Py_ssize_t source_size, delta_size
 
228
    cdef unsigned long target_size
 
229
 
 
230
    if not PyString_CheckExact(source_bytes):
 
231
        raise TypeError('source is not a str')
 
232
    if not PyString_CheckExact(delta_bytes):
 
233
        raise TypeError('delta is not a str')
 
234
 
 
235
    source = PyString_AS_STRING(source_bytes)
 
236
    source_size = PyString_GET_SIZE(source_bytes)
 
237
    delta = PyString_AS_STRING(delta_bytes)
 
238
    delta_size = PyString_GET_SIZE(delta_bytes)
 
239
 
 
240
    target = <char *>patch_delta(source, source_size,
 
241
                                 delta, delta_size,
 
242
                                 &target_size)
 
243
    if target == NULL:
 
244
        return None
 
245
    result = PyString_FromStringAndSize(target, target_size)
 
246
    free(target)
 
247
    return result