equal
deleted
inserted
replaced
36 |
36 |
37 struct flist { |
37 struct flist { |
38 struct frag *base, *head, *tail; |
38 struct frag *base, *head, *tail; |
39 }; |
39 }; |
40 |
40 |
41 static struct flist *lalloc(int size) |
41 static struct flist *lalloc(Py_ssize_t size) |
42 { |
42 { |
43 struct flist *a = NULL; |
43 struct flist *a = NULL; |
44 |
44 |
45 if (size < 1) |
45 if (size < 1) |
46 size = 1; |
46 size = 1; |
66 free(a->base); |
66 free(a->base); |
67 free(a); |
67 free(a); |
68 } |
68 } |
69 } |
69 } |
70 |
70 |
71 static int lsize(struct flist *a) |
71 static Py_ssize_t lsize(struct flist *a) |
72 { |
72 { |
73 return a->tail - a->head; |
73 return a->tail - a->head; |
74 } |
74 } |
75 |
75 |
76 /* move hunks in source that are less cut to dest, compensating |
76 /* move hunks in source that are less cut to dest, compensating |
195 lfree(b); |
195 lfree(b); |
196 return c; |
196 return c; |
197 } |
197 } |
198 |
198 |
199 /* decode a binary patch into a hunk list */ |
199 /* decode a binary patch into a hunk list */ |
200 static struct flist *decode(const char *bin, int len) |
200 static struct flist *decode(const char *bin, Py_ssize_t len) |
201 { |
201 { |
202 struct flist *l; |
202 struct flist *l; |
203 struct frag *lt; |
203 struct frag *lt; |
204 const char *data = bin + 12, *end = bin + len; |
204 const char *data = bin + 12, *end = bin + len; |
205 |
205 |
234 l->tail = lt; |
234 l->tail = lt; |
235 return l; |
235 return l; |
236 } |
236 } |
237 |
237 |
238 /* calculate the size of resultant text */ |
238 /* calculate the size of resultant text */ |
239 static int calcsize(int len, struct flist *l) |
239 static Py_ssize_t calcsize(Py_ssize_t len, struct flist *l) |
240 { |
240 { |
241 int outlen = 0, last = 0; |
241 Py_ssize_t outlen = 0, last = 0; |
242 struct frag *f = l->head; |
242 struct frag *f = l->head; |
243 |
243 |
244 while (f != l->tail) { |
244 while (f != l->tail) { |
245 if (f->start < last || f->end > len) { |
245 if (f->start < last || f->end > len) { |
246 if (!PyErr_Occurred()) |
246 if (!PyErr_Occurred()) |
256 |
256 |
257 outlen += len - last; |
257 outlen += len - last; |
258 return outlen; |
258 return outlen; |
259 } |
259 } |
260 |
260 |
261 static int apply(char *buf, const char *orig, int len, struct flist *l) |
261 static int apply(char *buf, const char *orig, Py_ssize_t len, struct flist *l) |
262 { |
262 { |
263 struct frag *f = l->head; |
263 struct frag *f = l->head; |
264 int last = 0; |
264 int last = 0; |
265 char *p = buf; |
265 char *p = buf; |
266 |
266 |
281 memcpy(p, orig + last, len - last); |
281 memcpy(p, orig + last, len - last); |
282 return 1; |
282 return 1; |
283 } |
283 } |
284 |
284 |
285 /* recursively generate a patch of all bins between start and end */ |
285 /* recursively generate a patch of all bins between start and end */ |
286 static struct flist *fold(PyObject *bins, int start, int end) |
286 static struct flist *fold(PyObject *bins, Py_ssize_t start, Py_ssize_t end) |
287 { |
287 { |
288 int len; |
288 Py_ssize_t len, blen; |
289 Py_ssize_t blen; |
|
290 const char *buffer; |
289 const char *buffer; |
291 |
290 |
292 if (start + 1 == end) { |
291 if (start + 1 == end) { |
293 /* trivial case, output a decoded list */ |
292 /* trivial case, output a decoded list */ |
294 PyObject *tmp = PyList_GetItem(bins, start); |
293 PyObject *tmp = PyList_GetItem(bins, start); |
310 { |
309 { |
311 PyObject *text, *bins, *result; |
310 PyObject *text, *bins, *result; |
312 struct flist *patch; |
311 struct flist *patch; |
313 const char *in; |
312 const char *in; |
314 char *out; |
313 char *out; |
315 int len, outlen; |
314 Py_ssize_t len, outlen, inlen; |
316 Py_ssize_t inlen; |
|
317 |
315 |
318 if (!PyArg_ParseTuple(args, "OO:mpatch", &text, &bins)) |
316 if (!PyArg_ParseTuple(args, "OO:mpatch", &text, &bins)) |
319 return NULL; |
317 return NULL; |
320 |
318 |
321 len = PyList_Size(bins); |
319 len = PyList_Size(bins); |