/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/_patiencediff_c.c

  • Committer: John Arbash Meinel
  • Date: 2009-07-31 17:42:29 UTC
  • mto: This revision was merged to the branch mainline in revision 4611.
  • Revision ID: john@arbash-meinel.com-20090731174229-w2zdsdlfpeddk8gl
Now we got to the per-workingtree tests, etc.

The main causes seem to break down into:
  bzrdir.clone() is known to be broken wrt locking, this effects
  everything that tries to 'push'

  shelf code is not compatible with strict locking

  merge code seems to have an issue. This might actually be the
  root cause of the clone() problems.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 Copyright (C) 2007, 2010 Canonical Ltd
 
2
 Copyright (C) 2007 Canonical Ltd
3
3
 
4
4
 This program is free software; you can redistribute it and/or modify
5
5
 it under the terms of the GNU General Public License as published by
46
46
#define SENTINEL -1
47
47
 
48
48
 
49
 
/* malloc returns NULL on some platforms if you try to allocate nothing,
50
 
 * causing <https://bugs.edge.launchpad.net/bzr/+bug/511267> and
51
 
 * <https://bugs.edge.launchpad.net/bzr/+bug/331095>.  On glibc it passes, but
52
 
 * let's make it fail to aid testing. */
53
 
#define guarded_malloc(x) ( (x) ? malloc(x) : NULL )
54
 
 
55
49
enum {
56
50
    OP_EQUAL = 0,
57
51
    OP_INSERT,
189
183
    while (hsize < bsize + 1)
190
184
        hsize *= 2;
191
185
 
192
 
    /* can't be 0 */
193
 
    hashtable = (struct bucket *) guarded_malloc(sizeof(struct bucket) * hsize);
 
186
    hashtable = (struct bucket *)malloc(sizeof(struct bucket) * hsize);
194
187
    if (hashtable == NULL) {
195
188
        PyErr_NoMemory();
196
189
        return 0;
305
298
        apos = SENTINEL;
306
299
        /* loop through all lines in the linked list */
307
300
        for (i = h[equiv].a_pos; i != SENTINEL; i = lines_a[i].next) {
308
 
            /* the index is lower than alo, continue to the next line */
 
301
            /* the index is lower than alo, the the next line */
309
302
            if (i < alo) {
310
303
                h[equiv].a_pos = i;
311
304
                continue;
326
319
        /* check for duplicates of this line in lines_b[blo:bhi] */
327
320
        /* loop through all lines in the linked list */
328
321
        for (i = h[equiv].b_pos; i != SENTINEL; i = lines_b[i].next) {
329
 
            /* the index is lower than blo, continue to the next line */
 
322
            /* the index is lower than blo, the the next line */
330
323
            if (i < blo) {
331
324
                h[equiv].b_pos = i;
332
325
                continue;
467
460
    last_a_pos = alo - 1;
468
461
    last_b_pos = blo - 1;
469
462
 
470
 
    lcs = (struct matching_line *)guarded_malloc(sizeof(struct matching_line) * (bhi - blo));
 
463
    lcs = (struct matching_line *)malloc(sizeof(struct matching_line) * (bhi - blo));
471
464
    if (lcs == NULL)
472
465
        return 0;
473
466
 
627
620
    if (!equate_lines(&hashtable, a, b, asize, bsize))
628
621
        goto error;
629
622
 
630
 
    if (bsize > 0) {
631
 
        matches = (struct matching_line *)guarded_malloc(sizeof(struct matching_line) * bsize);
632
 
        if (matches == NULL)
633
 
            goto error;
 
623
    matches = (struct matching_line *)malloc(sizeof(struct matching_line) * bsize);
 
624
    if (matches == NULL)
 
625
        goto error;
634
626
 
635
 
        backpointers = (Py_ssize_t *)guarded_malloc(sizeof(Py_ssize_t) * bsize * 4);
636
 
        if (backpointers == NULL)
637
 
            goto error;
638
 
    }
 
627
    backpointers = (Py_ssize_t *)malloc(sizeof(Py_ssize_t) * bsize * 4);
 
628
    if (backpointers == NULL)
 
629
        goto error;
639
630
 
640
631
    nmatches = unique_lcs(matches, &hashtable, backpointers, a, b, 0, 0, asize, bsize);
641
632
 
701
692
        goto error;
702
693
 
703
694
    matches.count = 0;
704
 
 
705
 
    if (bsize > 0) {
706
 
        matches.matches = (struct matching_block *)guarded_malloc(sizeof(struct matching_block) * bsize);
707
 
        if (matches.matches == NULL)
708
 
            goto error;
709
 
 
710
 
        backpointers = (Py_ssize_t *)guarded_malloc(sizeof(Py_ssize_t) * bsize * 4);
711
 
        if (backpointers == NULL)
712
 
            goto error;
713
 
    } else {
714
 
        matches.matches = NULL;
715
 
        backpointers = NULL;
716
 
    }
 
695
    matches.matches = (struct matching_block *)malloc(sizeof(struct matching_block) * bsize);
 
696
    if (matches.matches == NULL)
 
697
        goto error;
 
698
 
 
699
    backpointers = (Py_ssize_t *)malloc(sizeof(Py_ssize_t) * bsize * 4);
 
700
    if (backpointers == NULL)
 
701
        goto error;
717
702
 
718
703
    res = recurse_matches(&matches, &hashtable, backpointers,
719
704
                          a, b, alo, blo, ahi, bhi, maxrecursion);
780
765
            return NULL;
781
766
        }
782
767
 
783
 
        if (self->bsize > 0) {
784
 
            self->backpointers = (Py_ssize_t *)guarded_malloc(sizeof(Py_ssize_t) * self->bsize * 4);
785
 
            if (self->backpointers == NULL) {
786
 
                Py_DECREF(self);
787
 
                PyErr_NoMemory();
788
 
                return NULL;
789
 
            }
790
 
        } else {
791
 
            self->backpointers = NULL;
 
768
        self->backpointers = (Py_ssize_t *)malloc(sizeof(Py_ssize_t) * self->bsize * 4);
 
769
        if (self->backpointers == NULL) {
 
770
            Py_DECREF(self);
 
771
            PyErr_NoMemory();
 
772
            return NULL;
792
773
        }
793
774
 
794
775
    }
831
812
    struct matching_blocks matches;
832
813
 
833
814
    matches.count = 0;
834
 
    if (self->bsize > 0) {
835
 
        matches.matches = (struct matching_block *)
836
 
            guarded_malloc(sizeof(struct matching_block) * self->bsize);
837
 
        if (matches.matches == NULL)
838
 
            return PyErr_NoMemory();
839
 
    } else
840
 
        matches.matches = NULL;
 
815
    matches.matches = (struct matching_block *)malloc(sizeof(struct matching_block) * self->bsize);
 
816
    if (matches.matches == NULL)
 
817
        return PyErr_NoMemory();
841
818
 
842
819
    res = recurse_matches(&matches, &self->hashtable, self->backpointers,
843
820
                          self->a, self->b, 0, 0,
923
900
    struct matching_blocks matches;
924
901
 
925
902
    matches.count = 0;
926
 
    matches.matches = (struct matching_block *)guarded_malloc(sizeof(struct matching_block) * (self->bsize + 1));
 
903
    matches.matches = (struct matching_block *)malloc(sizeof(struct matching_block) * (self->bsize + 1));
927
904
    if (matches.matches == NULL)
928
905
        return PyErr_NoMemory();
929
906
 
1036
1013
        return NULL;
1037
1014
 
1038
1015
    matches.count = 0;
1039
 
    matches.matches = (struct matching_block *)guarded_malloc(sizeof(struct matching_block) * (self->bsize + 1));
 
1016
    matches.matches = (struct matching_block *)malloc(sizeof(struct matching_block) * (self->bsize + 1));
1040
1017
    if (matches.matches == NULL)
1041
1018
        return PyErr_NoMemory();
1042
1019
 
1054
1031
    matches.count++;
1055
1032
 
1056
1033
    ncodes = 0;
1057
 
    codes = (struct opcode *)guarded_malloc(sizeof(struct opcode) * matches.count * 2);
 
1034
    codes = (struct opcode *)malloc(sizeof(struct opcode) * matches.count * 2);
1058
1035
    if (codes == NULL) {
1059
1036
        free(matches.matches);
1060
1037
        return PyErr_NoMemory();
1275
1252
    PyModule_AddObject(m, "PatienceSequenceMatcher_c",
1276
1253
                       (PyObject *)&PatienceSequenceMatcherType);
1277
1254
}
1278
 
 
1279
 
 
1280
 
/* vim: sw=4 et 
1281
 
 */