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)
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)
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
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')
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)
240
target = <char *>patch_delta(source, source_size,
245
result = PyString_FromStringAndSize(target, target_size)