Merge lp:~jelmer/brz/python3-patiencediff into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/python3-patiencediff
Merge into: lp:brz
Diff against target: 209 lines (+30/-67)
1 file modified
breezy/_patiencediff_c.c (+30/-67)
To merge this branch: bzr merge lp:~jelmer/brz/python3-patiencediff
Reviewer Review Type Date Requested Status
Martin Packman Approve
Review via email: mp+349379@code.launchpad.net

This proposal supersedes a proposal from 2018-07-11.

Commit message

 Port patiencediff C extensions to python 3.

Description of the change

 Port patiencediff C extensions to python 3.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Thanks! I'm not certain about the fancy PatienceSequenceMatcherType initialisation, but does seem to work despite GCC complaining.

review: Approve
Revision history for this message
Martin Packman (gz) wrote :

Hm, actually, shouldn't this change use Py_NE or something?

- || PyObject_Compare(a->data, b->data));
+ || PyObject_RichCompareBool(a->data, b->data, Py_LT));

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/_patiencediff_c.c'
2--- breezy/_patiencediff_c.c 2017-06-13 02:58:21 +0000
3+++ breezy/_patiencediff_c.c 2018-07-12 18:28:33 +0000
4@@ -46,12 +46,6 @@
5 #define SENTINEL -1
6
7
8-/* malloc returns NULL on some platforms if you try to allocate nothing,
9- * causing <https://bugs.launchpad.net/bzr/+bug/511267> and
10- * <https://bugs.launchpad.net/bzr/+bug/331095>. On glibc it passes, but
11- * let's make it fail to aid testing. */
12-#define guarded_malloc(x) ( (x) ? malloc(x) : NULL )
13-
14 enum {
15 OP_EQUAL = 0,
16 OP_INSERT,
17@@ -151,7 +145,7 @@
18 compare_lines(struct line *a, struct line *b)
19 {
20 return ((a->hash != b->hash)
21- || PyObject_Compare(a->data, b->data));
22+ || PyObject_RichCompareBool(a->data, b->data, Py_EQ) == 0);
23 }
24
25
26@@ -190,7 +184,7 @@
27 hsize *= 2;
28
29 /* can't be 0 */
30- hashtable = (struct bucket *) guarded_malloc(sizeof(struct bucket) * hsize);
31+ hashtable = (struct bucket *)malloc(sizeof(struct bucket) * hsize);
32 if (hashtable == NULL) {
33 PyErr_NoMemory();
34 return 0;
35@@ -467,7 +461,7 @@
36 last_a_pos = alo - 1;
37 last_b_pos = blo - 1;
38
39- lcs = (struct matching_line *)guarded_malloc(sizeof(struct matching_line) * (bhi - blo));
40+ lcs = (struct matching_line *)malloc(sizeof(struct matching_line) * (bhi - blo));
41 if (lcs == NULL)
42 return 0;
43
44@@ -628,11 +622,11 @@
45 goto error;
46
47 if (bsize > 0) {
48- matches = (struct matching_line *)guarded_malloc(sizeof(struct matching_line) * bsize);
49+ matches = (struct matching_line *)malloc(sizeof(struct matching_line) * bsize);
50 if (matches == NULL)
51 goto error;
52
53- backpointers = (Py_ssize_t *)guarded_malloc(sizeof(Py_ssize_t) * bsize * 4);
54+ backpointers = (Py_ssize_t *)malloc(sizeof(Py_ssize_t) * bsize * 4);
55 if (backpointers == NULL)
56 goto error;
57 }
58@@ -694,11 +688,11 @@
59 matches.count = 0;
60
61 if (bsize > 0) {
62- matches.matches = (struct matching_block *)guarded_malloc(sizeof(struct matching_block) * bsize);
63+ matches.matches = (struct matching_block *)malloc(sizeof(struct matching_block) * bsize);
64 if (matches.matches == NULL)
65 goto error;
66
67- backpointers = (Py_ssize_t *)guarded_malloc(sizeof(Py_ssize_t) * bsize * 4);
68+ backpointers = (Py_ssize_t *)malloc(sizeof(Py_ssize_t) * bsize * 4);
69 if (backpointers == NULL)
70 goto error;
71 } else {
72@@ -767,7 +761,7 @@
73 }
74
75 if (self->bsize > 0) {
76- self->backpointers = (Py_ssize_t *)guarded_malloc(sizeof(Py_ssize_t) * self->bsize * 4);
77+ self->backpointers = (Py_ssize_t *)malloc(sizeof(Py_ssize_t) * self->bsize * 4);
78 if (self->backpointers == NULL) {
79 Py_DECREF(self);
80 PyErr_NoMemory();
81@@ -790,7 +784,7 @@
82 free(self->hashtable.table);
83 delete_lines(self->b, self->bsize);
84 delete_lines(self->a, self->asize);
85- self->ob_type->tp_free((PyObject *)self);
86+ ((PyObject *)self)->ob_type->tp_free((PyObject *)self);
87 }
88
89
90@@ -819,7 +813,7 @@
91 matches.count = 0;
92 if (self->bsize > 0) {
93 matches.matches = (struct matching_block *)
94- guarded_malloc(sizeof(struct matching_block) * self->bsize);
95+ malloc(sizeof(struct matching_block) * self->bsize);
96 if (matches.matches == NULL)
97 return PyErr_NoMemory();
98 } else
99@@ -900,7 +894,7 @@
100 struct matching_blocks matches;
101
102 matches.count = 0;
103- matches.matches = (struct matching_block *)guarded_malloc(sizeof(struct matching_block) * (self->bsize + 1));
104+ matches.matches = (struct matching_block *)malloc(sizeof(struct matching_block) * (self->bsize + 1));
105 if (matches.matches == NULL)
106 return PyErr_NoMemory();
107
108@@ -1005,7 +999,7 @@
109 return NULL;
110
111 matches.count = 0;
112- matches.matches = (struct matching_block *)guarded_malloc(sizeof(struct matching_block) * (self->bsize + 1));
113+ matches.matches = (struct matching_block *)malloc(sizeof(struct matching_block) * (self->bsize + 1));
114 if (matches.matches == NULL)
115 return PyErr_NoMemory();
116
117@@ -1023,7 +1017,7 @@
118 matches.count++;
119
120 ncodes = 0;
121- codes = (struct opcode *)guarded_malloc(sizeof(struct opcode) * matches.count * 2);
122+ codes = (struct opcode *)malloc(sizeof(struct opcode) * matches.count * 2);
123 if (codes == NULL) {
124 free(matches.matches);
125 return PyErr_NoMemory();
126@@ -1170,44 +1164,13 @@
127
128 static PyTypeObject PatienceSequenceMatcherType = {
129 PyObject_HEAD_INIT(NULL)
130- 0, /* ob_size */
131- "PatienceSequenceMatcher", /* tp_name */
132- sizeof(PatienceSequenceMatcher), /* tp_basicsize */
133- 0, /* tp_itemsize */
134- (destructor)PatienceSequenceMatcher_dealloc, /* tp_dealloc */
135- 0, /* tp_print */
136- 0, /* tp_getattr */
137- 0, /* tp_setattr */
138- 0, /* tp_compare */
139- 0, /* tp_repr */
140- 0, /* tp_as_number */
141- 0, /* tp_as_sequence */
142- 0, /* tp_as_mapping */
143- 0, /* tp_hash */
144- 0, /* tp_call */
145- 0, /* tp_str */
146- 0, /* tp_getattro */
147- 0, /* tp_setattro */
148- 0, /* tp_as_buffer */
149- Py_TPFLAGS_DEFAULT, /* tp_flags*/
150- PatienceSequenceMatcher_doc, /* tp_doc */
151- 0, /* tp_traverse */
152- 0, /* tp_clear */
153- 0, /* tp_richcompare */
154- 0, /* tp_weaklistoffset */
155- 0, /* tp_iter */
156- 0, /* tp_iternext */
157- PatienceSequenceMatcher_methods, /* tp_methods */
158- 0, /* tp_members */
159- 0, /* tp_getset */
160- 0, /* tp_base */
161- 0, /* tp_dict */
162- 0, /* tp_descr_get */
163- 0, /* tp_descr_set */
164- 0, /* tp_dictoffset */
165- 0, /* tp_init */
166- 0, /* tp_alloc */
167- PatienceSequenceMatcher_new, /* tp_new */
168+ .tp_name = "PatienceSequenceMatcher",
169+ .tp_basicsize = sizeof(PatienceSequenceMatcher),
170+ .tp_dealloc = (destructor)PatienceSequenceMatcher_dealloc,
171+ .tp_flags = Py_TPFLAGS_DEFAULT,
172+ .tp_doc = PatienceSequenceMatcher_doc,
173+ .tp_methods = PatienceSequenceMatcher_methods,
174+ .tp_new = PatienceSequenceMatcher_new,
175 };
176
177
178@@ -1217,23 +1180,23 @@
179 {NULL, NULL}
180 };
181
182-
183-PyMODINIT_FUNC
184-init_patiencediff_c(void)
185+PYMOD_INIT_FUNC(_patiencediff_c)
186 {
187 PyObject* m;
188
189 if (PyType_Ready(&PatienceSequenceMatcherType) < 0)
190- return;
191-
192- m = Py_InitModule3("_patiencediff_c", cpatiencediff_methods,
193- "C implementation of PatienceSequenceMatcher");
194- if (m == NULL)
195- return;
196-
197+ return PYMOD_ERROR;
198+
199+ PYMOD_CREATE(m, "_patiencediff_c",
200+ "C implementation of PatienceSequenceMatcher",
201+ cpatiencediff_methods);
202+ if (m == NULL) {
203+ return PYMOD_ERROR;
204+ }
205 Py_INCREF(&PatienceSequenceMatcherType);
206 PyModule_AddObject(m, "PatienceSequenceMatcher_c",
207 (PyObject *)&PatienceSequenceMatcherType);
208+ return PYMOD_SUCCESS(m);
209 }
210
211

Subscribers

People subscribed via source and target branches