/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: 2020-05-06 02:13:25 UTC
  • mfrom: (7490.7.21 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200506021325-awbmmqu1zyorz7sj
Merge 3.1 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Functionality for doing annotations in the 'optimal' way"""
18
18
 
19
 
from __future__ import absolute_import
20
 
 
21
19
 
22
20
cdef extern from "python-compat.h":
23
21
    pass
24
22
 
 
23
from cpython.dict cimport (
 
24
    PyDict_GetItem,
 
25
    PyDict_SetItem,
 
26
    )
 
27
from cpython.list cimport (
 
28
    PyList_Append,
 
29
    PyList_CheckExact,
 
30
    PyList_GET_ITEM,
 
31
    PyList_GET_SIZE,
 
32
    PyList_SetItem,
 
33
    PyList_Sort,
 
34
    )
 
35
from cpython.object cimport (
 
36
    Py_EQ,
 
37
    Py_LT,
 
38
    PyObject,
 
39
    PyObject_RichCompareBool,
 
40
    )
 
41
from cpython.ref cimport (
 
42
    Py_INCREF,
 
43
    )
 
44
from cpython.tuple cimport (
 
45
    PyTuple_CheckExact,
 
46
    PyTuple_GET_ITEM,
 
47
    PyTuple_GET_SIZE,
 
48
    PyTuple_New,
 
49
    PyTuple_SET_ITEM,
 
50
    )
 
51
 
25
52
cdef extern from "Python.h":
26
 
    ctypedef int Py_ssize_t
27
 
    ctypedef struct PyObject:
28
 
        pass
29
53
    ctypedef struct PyListObject:
30
54
        PyObject **ob_item
31
 
    int PyList_CheckExact(object)
32
 
    PyObject *PyList_GET_ITEM(object, Py_ssize_t o)
33
 
    Py_ssize_t PyList_GET_SIZE(object)
34
 
    int PyList_Append(object, object) except -1
35
 
    int PyList_SetItem(object, Py_ssize_t o, object) except -1
36
 
    int PyList_Sort(object) except -1
37
55
 
38
 
    int PyTuple_CheckExact(object)
39
 
    object PyTuple_New(Py_ssize_t len)
40
 
    void PyTuple_SET_ITEM(object, Py_ssize_t pos, object)
41
56
    void PyTuple_SET_ITEM_ptr "PyTuple_SET_ITEM" (object, Py_ssize_t,
42
57
                                                  PyObject *)
43
 
    int PyTuple_Resize(PyObject **, Py_ssize_t newlen)
44
 
    PyObject *PyTuple_GET_ITEM(object, Py_ssize_t o)
45
 
    Py_ssize_t PyTuple_GET_SIZE(object)
46
 
 
47
 
    PyObject *PyDict_GetItem(object d, object k)
48
 
    int PyDict_SetItem(object d, object k, object v) except -1
49
 
 
50
 
    void Py_INCREF(object)
 
58
 
51
59
    void Py_INCREF_ptr "Py_INCREF" (PyObject *)
52
60
    void Py_DECREF_ptr "Py_DECREF" (PyObject *)
53
61
 
54
 
    int Py_EQ
55
 
    int Py_LT
56
 
    int PyObject_RichCompareBool(object, object, int opid) except -1
57
62
    int PyObject_RichCompareBool_ptr "PyObject_RichCompareBool" (
58
63
        PyObject *, PyObject *, int opid)
59
64
 
91
96
 
92
97
    :param tpl: The tuple we are investigating, *must* be a PyTuple
93
98
    :param pos: The last item we found. Will be updated to the new position.
94
 
    
 
99
 
95
100
    This cannot raise an exception, as it does no error checking.
96
101
    """
97
102
    pos[0] = pos[0] + 1
104
109
    """Combine the annotations from both sides."""
105
110
    cdef Py_ssize_t pos_one, pos_two, len_one, len_two
106
111
    cdef Py_ssize_t out_pos
107
 
    cdef PyObject *temp, *left, *right
 
112
    cdef PyObject *temp
 
113
    cdef PyObject *left
 
114
    cdef PyObject *right
108
115
 
109
116
    if (PyObject_RichCompareBool(ann_one, ann_two, Py_LT)):
110
117
        cache_key = (ann_one, ann_two)
171
178
    matching_blocks defines the ranges that match.
172
179
    """
173
180
    cdef Py_ssize_t parent_idx, lines_idx, match_len, idx
174
 
    cdef PyListObject *par_list, *ann_list
175
 
    cdef PyObject **par_temp, **ann_temp
 
181
    cdef PyListObject *par_list
 
182
    cdef PyListObject *ann_list
 
183
    cdef PyObject **par_temp
 
184
    cdef PyObject **ann_temp
176
185
 
177
186
    _check_annotations_are_lists(annotations, parent_annotations)
178
187
    par_list = <PyListObject *>parent_annotations
197
206
                            matching_blocks, ann_cache) except -1:
198
207
    cdef Py_ssize_t parent_idx, ann_idx, lines_idx, match_len, idx
199
208
    cdef Py_ssize_t pos
200
 
    cdef PyObject *ann_temp, *par_temp
 
209
    cdef PyObject *ann_temp
 
210
    cdef PyObject *par_temp
201
211
 
202
212
    _check_annotations_are_lists(annotations, parent_annotations)
203
213
    last_ann = None