/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 breezy/_annotator_pyx.pyx

  • Committer: Jelmer Vernooij
  • Date: 2017-06-08 23:30:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170608233031-3qavls2o7a1pqllj
Update imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
#
17
 
# cython: language_level=3
18
16
 
19
17
"""Functionality for doing annotations in the 'optimal' way"""
20
18
 
21
 
 
22
19
cdef extern from "python-compat.h":
23
20
    pass
24
21
 
25
 
from cpython.dict cimport (
26
 
    PyDict_GetItem,
27
 
    PyDict_SetItem,
28
 
    )
29
 
from cpython.list cimport (
30
 
    PyList_Append,
31
 
    PyList_CheckExact,
32
 
    PyList_GET_ITEM,
33
 
    PyList_GET_SIZE,
34
 
    PyList_SetItem,
35
 
    PyList_Sort,
36
 
    )
37
 
from cpython.object cimport (
38
 
    Py_EQ,
39
 
    Py_LT,
40
 
    PyObject,
41
 
    PyObject_RichCompareBool,
42
 
    )
43
 
from cpython.ref cimport (
44
 
    Py_INCREF,
45
 
    )
46
 
from cpython.tuple cimport (
47
 
    PyTuple_CheckExact,
48
 
    PyTuple_GET_ITEM,
49
 
    PyTuple_GET_SIZE,
50
 
    PyTuple_New,
51
 
    PyTuple_SET_ITEM,
52
 
    )
53
 
 
54
22
cdef extern from "Python.h":
 
23
    ctypedef int Py_ssize_t
 
24
    ctypedef struct PyObject:
 
25
        pass
55
26
    ctypedef struct PyListObject:
56
27
        PyObject **ob_item
 
28
    int PyList_CheckExact(object)
 
29
    PyObject *PyList_GET_ITEM(object, Py_ssize_t o)
 
30
    Py_ssize_t PyList_GET_SIZE(object)
 
31
    int PyList_Append(object, object) except -1
 
32
    int PyList_SetItem(object, Py_ssize_t o, object) except -1
 
33
    int PyList_Sort(object) except -1
57
34
 
 
35
    int PyTuple_CheckExact(object)
 
36
    object PyTuple_New(Py_ssize_t len)
 
37
    void PyTuple_SET_ITEM(object, Py_ssize_t pos, object)
58
38
    void PyTuple_SET_ITEM_ptr "PyTuple_SET_ITEM" (object, Py_ssize_t,
59
39
                                                  PyObject *)
60
 
 
 
40
    int PyTuple_Resize(PyObject **, Py_ssize_t newlen)
 
41
    PyObject *PyTuple_GET_ITEM(object, Py_ssize_t o)
 
42
    Py_ssize_t PyTuple_GET_SIZE(object)
 
43
 
 
44
    PyObject *PyDict_GetItem(object d, object k)
 
45
    int PyDict_SetItem(object d, object k, object v) except -1
 
46
 
 
47
    void Py_INCREF(object)
61
48
    void Py_INCREF_ptr "Py_INCREF" (PyObject *)
62
49
    void Py_DECREF_ptr "Py_DECREF" (PyObject *)
63
50
 
 
51
    int Py_EQ
 
52
    int Py_LT
 
53
    int PyObject_RichCompareBool(object, object, int opid) except -1
64
54
    int PyObject_RichCompareBool_ptr "PyObject_RichCompareBool" (
65
55
        PyObject *, PyObject *, int opid)
66
56
 
67
57
 
68
 
from . import _annotator_py
 
58
from breezy import _annotator_py
69
59
 
70
60
 
71
61
cdef int _check_annotations_are_lists(annotations,
98
88
 
99
89
    :param tpl: The tuple we are investigating, *must* be a PyTuple
100
90
    :param pos: The last item we found. Will be updated to the new position.
101
 
 
 
91
    
102
92
    This cannot raise an exception, as it does no error checking.
103
93
    """
104
94
    pos[0] = pos[0] + 1
111
101
    """Combine the annotations from both sides."""
112
102
    cdef Py_ssize_t pos_one, pos_two, len_one, len_two
113
103
    cdef Py_ssize_t out_pos
114
 
    cdef PyObject *temp
115
 
    cdef PyObject *left
116
 
    cdef PyObject *right
 
104
    cdef PyObject *temp, *left, *right
117
105
 
118
106
    if (PyObject_RichCompareBool(ann_one, ann_two, Py_LT)):
119
107
        cache_key = (ann_one, ann_two)
180
168
    matching_blocks defines the ranges that match.
181
169
    """
182
170
    cdef Py_ssize_t parent_idx, lines_idx, match_len, idx
183
 
    cdef PyListObject *par_list
184
 
    cdef PyListObject *ann_list
185
 
    cdef PyObject **par_temp
186
 
    cdef PyObject **ann_temp
 
171
    cdef PyListObject *par_list, *ann_list
 
172
    cdef PyObject **par_temp, **ann_temp
187
173
 
188
174
    _check_annotations_are_lists(annotations, parent_annotations)
189
175
    par_list = <PyListObject *>parent_annotations
208
194
                            matching_blocks, ann_cache) except -1:
209
195
    cdef Py_ssize_t parent_idx, ann_idx, lines_idx, match_len, idx
210
196
    cdef Py_ssize_t pos
211
 
    cdef PyObject *ann_temp
212
 
    cdef PyObject *par_temp
 
197
    cdef PyObject *ann_temp, *par_temp
213
198
 
214
199
    _check_annotations_are_lists(annotations, parent_annotations)
215
200
    last_ann = None
284
269
        """
285
270
        cdef Py_ssize_t pos, num_lines
286
271
 
287
 
        from . import annotate
 
272
        from breezy import annotate
288
273
 
289
274
        custom_tiebreaker = annotate._break_annotation_tie
290
275
        annotations, lines = self.annotate(key)