##// END OF EJS Templates
parsers: cache the result of index_headrevs...
Bryan O'Sullivan -
r16787:bda96ce9 default
parent child Browse files
Show More
@@ -1,1368 +1,1399 b''
1 1 /*
2 2 parsers.c - efficient content parsing
3 3
4 4 Copyright 2008 Matt Mackall <mpm@selenic.com> and others
5 5
6 6 This software may be used and distributed according to the terms of
7 7 the GNU General Public License, incorporated herein by reference.
8 8 */
9 9
10 10 #include <Python.h>
11 11 #include <ctype.h>
12 12 #include <string.h>
13 13
14 14 #include "util.h"
15 15
16 16 static inline int hexdigit(const char *p, Py_ssize_t off)
17 17 {
18 18 char c = p[off];
19 19
20 20 if (c >= '0' && c <= '9')
21 21 return c - '0';
22 22 if (c >= 'a' && c <= 'f')
23 23 return c - 'a' + 10;
24 24 if (c >= 'A' && c <= 'F')
25 25 return c - 'A' + 10;
26 26
27 27 PyErr_SetString(PyExc_ValueError, "input contains non-hex character");
28 28 return 0;
29 29 }
30 30
31 31 /*
32 32 * Turn a hex-encoded string into binary.
33 33 */
34 34 static PyObject *unhexlify(const char *str, int len)
35 35 {
36 36 PyObject *ret;
37 37 char *d;
38 38 int i;
39 39
40 40 ret = PyBytes_FromStringAndSize(NULL, len / 2);
41 41
42 42 if (!ret)
43 43 return NULL;
44 44
45 45 d = PyBytes_AsString(ret);
46 46
47 47 for (i = 0; i < len;) {
48 48 int hi = hexdigit(str, i++);
49 49 int lo = hexdigit(str, i++);
50 50 *d++ = (hi << 4) | lo;
51 51 }
52 52
53 53 return ret;
54 54 }
55 55
56 56 /*
57 57 * This code assumes that a manifest is stitched together with newline
58 58 * ('\n') characters.
59 59 */
60 60 static PyObject *parse_manifest(PyObject *self, PyObject *args)
61 61 {
62 62 PyObject *mfdict, *fdict;
63 63 char *str, *cur, *start, *zero;
64 64 int len;
65 65
66 66 if (!PyArg_ParseTuple(args, "O!O!s#:parse_manifest",
67 67 &PyDict_Type, &mfdict,
68 68 &PyDict_Type, &fdict,
69 69 &str, &len))
70 70 goto quit;
71 71
72 72 for (start = cur = str, zero = NULL; cur < str + len; cur++) {
73 73 PyObject *file = NULL, *node = NULL;
74 74 PyObject *flags = NULL;
75 75 int nlen;
76 76
77 77 if (!*cur) {
78 78 zero = cur;
79 79 continue;
80 80 }
81 81 else if (*cur != '\n')
82 82 continue;
83 83
84 84 if (!zero) {
85 85 PyErr_SetString(PyExc_ValueError,
86 86 "manifest entry has no separator");
87 87 goto quit;
88 88 }
89 89
90 90 file = PyBytes_FromStringAndSize(start, zero - start);
91 91
92 92 if (!file)
93 93 goto bail;
94 94
95 95 nlen = cur - zero - 1;
96 96
97 97 node = unhexlify(zero + 1, nlen > 40 ? 40 : nlen);
98 98 if (!node)
99 99 goto bail;
100 100
101 101 if (nlen > 40) {
102 102 flags = PyBytes_FromStringAndSize(zero + 41,
103 103 nlen - 40);
104 104 if (!flags)
105 105 goto bail;
106 106
107 107 if (PyDict_SetItem(fdict, file, flags) == -1)
108 108 goto bail;
109 109 }
110 110
111 111 if (PyDict_SetItem(mfdict, file, node) == -1)
112 112 goto bail;
113 113
114 114 start = cur + 1;
115 115 zero = NULL;
116 116
117 117 Py_XDECREF(flags);
118 118 Py_XDECREF(node);
119 119 Py_XDECREF(file);
120 120 continue;
121 121 bail:
122 122 Py_XDECREF(flags);
123 123 Py_XDECREF(node);
124 124 Py_XDECREF(file);
125 125 goto quit;
126 126 }
127 127
128 128 if (len > 0 && *(cur - 1) != '\n') {
129 129 PyErr_SetString(PyExc_ValueError,
130 130 "manifest contains trailing garbage");
131 131 goto quit;
132 132 }
133 133
134 134 Py_INCREF(Py_None);
135 135 return Py_None;
136 136 quit:
137 137 return NULL;
138 138 }
139 139
140 140 static PyObject *parse_dirstate(PyObject *self, PyObject *args)
141 141 {
142 142 PyObject *dmap, *cmap, *parents = NULL, *ret = NULL;
143 143 PyObject *fname = NULL, *cname = NULL, *entry = NULL;
144 144 char *str, *cur, *end, *cpos;
145 145 int state, mode, size, mtime;
146 146 unsigned int flen;
147 147 int len;
148 148
149 149 if (!PyArg_ParseTuple(args, "O!O!s#:parse_dirstate",
150 150 &PyDict_Type, &dmap,
151 151 &PyDict_Type, &cmap,
152 152 &str, &len))
153 153 goto quit;
154 154
155 155 /* read parents */
156 156 if (len < 40)
157 157 goto quit;
158 158
159 159 parents = Py_BuildValue("s#s#", str, 20, str + 20, 20);
160 160 if (!parents)
161 161 goto quit;
162 162
163 163 /* read filenames */
164 164 cur = str + 40;
165 165 end = str + len;
166 166
167 167 while (cur < end - 17) {
168 168 /* unpack header */
169 169 state = *cur;
170 170 mode = getbe32(cur + 1);
171 171 size = getbe32(cur + 5);
172 172 mtime = getbe32(cur + 9);
173 173 flen = getbe32(cur + 13);
174 174 cur += 17;
175 175 if (cur + flen > end || cur + flen < cur) {
176 176 PyErr_SetString(PyExc_ValueError, "overflow in dirstate");
177 177 goto quit;
178 178 }
179 179
180 180 entry = Py_BuildValue("ciii", state, mode, size, mtime);
181 181 if (!entry)
182 182 goto quit;
183 183 PyObject_GC_UnTrack(entry); /* don't waste time with this */
184 184
185 185 cpos = memchr(cur, 0, flen);
186 186 if (cpos) {
187 187 fname = PyBytes_FromStringAndSize(cur, cpos - cur);
188 188 cname = PyBytes_FromStringAndSize(cpos + 1,
189 189 flen - (cpos - cur) - 1);
190 190 if (!fname || !cname ||
191 191 PyDict_SetItem(cmap, fname, cname) == -1 ||
192 192 PyDict_SetItem(dmap, fname, entry) == -1)
193 193 goto quit;
194 194 Py_DECREF(cname);
195 195 } else {
196 196 fname = PyBytes_FromStringAndSize(cur, flen);
197 197 if (!fname ||
198 198 PyDict_SetItem(dmap, fname, entry) == -1)
199 199 goto quit;
200 200 }
201 201 cur += flen;
202 202 Py_DECREF(fname);
203 203 Py_DECREF(entry);
204 204 fname = cname = entry = NULL;
205 205 }
206 206
207 207 ret = parents;
208 208 Py_INCREF(ret);
209 209 quit:
210 210 Py_XDECREF(fname);
211 211 Py_XDECREF(cname);
212 212 Py_XDECREF(entry);
213 213 Py_XDECREF(parents);
214 214 return ret;
215 215 }
216 216
217 217 /*
218 218 * A base-16 trie for fast node->rev mapping.
219 219 *
220 220 * Positive value is index of the next node in the trie
221 221 * Negative value is a leaf: -(rev + 1)
222 222 * Zero is empty
223 223 */
224 224 typedef struct {
225 225 int children[16];
226 226 } nodetree;
227 227
228 228 /*
229 229 * This class has two behaviours.
230 230 *
231 231 * When used in a list-like way (with integer keys), we decode an
232 232 * entry in a RevlogNG index file on demand. Our last entry is a
233 233 * sentinel, always a nullid. We have limited support for
234 234 * integer-keyed insert and delete, only at elements right before the
235 235 * sentinel.
236 236 *
237 237 * With string keys, we lazily perform a reverse mapping from node to
238 238 * rev, using a base-16 trie.
239 239 */
240 240 typedef struct {
241 241 PyObject_HEAD
242 242 /* Type-specific fields go here. */
243 243 PyObject *data; /* raw bytes of index */
244 244 PyObject **cache; /* cached tuples */
245 245 const char **offsets; /* populated on demand */
246 246 Py_ssize_t raw_length; /* original number of elements */
247 247 Py_ssize_t length; /* current number of elements */
248 248 PyObject *added; /* populated on demand */
249 PyObject *headrevs; /* cache, invalidated on changes */
249 250 nodetree *nt; /* base-16 trie */
250 251 int ntlength; /* # nodes in use */
251 252 int ntcapacity; /* # nodes allocated */
252 253 int ntdepth; /* maximum depth of tree */
253 254 int ntsplits; /* # splits performed */
254 255 int ntrev; /* last rev scanned */
255 256 int ntlookups; /* # lookups */
256 257 int ntmisses; /* # lookups that miss the cache */
257 258 int inlined;
258 259 } indexObject;
259 260
260 261 static Py_ssize_t index_length(const indexObject *self)
261 262 {
262 263 if (self->added == NULL)
263 264 return self->length;
264 265 return self->length + PyList_GET_SIZE(self->added);
265 266 }
266 267
267 268 static PyObject *nullentry;
268 269 static const char nullid[20];
269 270
270 271 static long inline_scan(indexObject *self, const char **offsets);
271 272
272 273 #if LONG_MAX == 0x7fffffffL
273 274 static char *tuple_format = "Kiiiiiis#";
274 275 #else
275 276 static char *tuple_format = "kiiiiiis#";
276 277 #endif
277 278
278 279 /*
279 280 * Return a pointer to the beginning of a RevlogNG record.
280 281 */
281 282 static const char *index_deref(indexObject *self, Py_ssize_t pos)
282 283 {
283 284 if (self->inlined && pos > 0) {
284 285 if (self->offsets == NULL) {
285 286 self->offsets = malloc(self->raw_length *
286 287 sizeof(*self->offsets));
287 288 if (self->offsets == NULL)
288 289 return (const char *)PyErr_NoMemory();
289 290 inline_scan(self, self->offsets);
290 291 }
291 292 return self->offsets[pos];
292 293 }
293 294
294 295 return PyString_AS_STRING(self->data) + pos * 64;
295 296 }
296 297
297 298 /*
298 299 * RevlogNG format (all in big endian, data may be inlined):
299 300 * 6 bytes: offset
300 301 * 2 bytes: flags
301 302 * 4 bytes: compressed length
302 303 * 4 bytes: uncompressed length
303 304 * 4 bytes: base revision
304 305 * 4 bytes: link revision
305 306 * 4 bytes: parent 1 revision
306 307 * 4 bytes: parent 2 revision
307 308 * 32 bytes: nodeid (only 20 bytes used)
308 309 */
309 310 static PyObject *index_get(indexObject *self, Py_ssize_t pos)
310 311 {
311 312 uint64_t offset_flags;
312 313 int comp_len, uncomp_len, base_rev, link_rev, parent_1, parent_2;
313 314 const char *c_node_id;
314 315 const char *data;
315 316 Py_ssize_t length = index_length(self);
316 317 PyObject *entry;
317 318
318 319 if (pos < 0)
319 320 pos += length;
320 321
321 322 if (pos < 0 || pos >= length) {
322 323 PyErr_SetString(PyExc_IndexError, "revlog index out of range");
323 324 return NULL;
324 325 }
325 326
326 327 if (pos == length - 1) {
327 328 Py_INCREF(nullentry);
328 329 return nullentry;
329 330 }
330 331
331 332 if (pos >= self->length - 1) {
332 333 PyObject *obj;
333 334 obj = PyList_GET_ITEM(self->added, pos - self->length + 1);
334 335 Py_INCREF(obj);
335 336 return obj;
336 337 }
337 338
338 339 if (self->cache) {
339 340 if (self->cache[pos]) {
340 341 Py_INCREF(self->cache[pos]);
341 342 return self->cache[pos];
342 343 }
343 344 } else {
344 345 self->cache = calloc(self->raw_length, sizeof(PyObject *));
345 346 if (self->cache == NULL)
346 347 return PyErr_NoMemory();
347 348 }
348 349
349 350 data = index_deref(self, pos);
350 351 if (data == NULL)
351 352 return NULL;
352 353
353 354 offset_flags = getbe32(data + 4);
354 355 if (pos == 0) /* mask out version number for the first entry */
355 356 offset_flags &= 0xFFFF;
356 357 else {
357 358 uint32_t offset_high = getbe32(data);
358 359 offset_flags |= ((uint64_t)offset_high) << 32;
359 360 }
360 361
361 362 comp_len = getbe32(data + 8);
362 363 uncomp_len = getbe32(data + 12);
363 364 base_rev = getbe32(data + 16);
364 365 link_rev = getbe32(data + 20);
365 366 parent_1 = getbe32(data + 24);
366 367 parent_2 = getbe32(data + 28);
367 368 c_node_id = data + 32;
368 369
369 370 entry = Py_BuildValue(tuple_format, offset_flags, comp_len,
370 371 uncomp_len, base_rev, link_rev,
371 372 parent_1, parent_2, c_node_id, 20);
372 373
373 374 if (entry)
374 375 PyObject_GC_UnTrack(entry);
375 376
376 377 self->cache[pos] = entry;
377 378 Py_INCREF(entry);
378 379
379 380 return entry;
380 381 }
381 382
382 383 /*
383 384 * Return the 20-byte SHA of the node corresponding to the given rev.
384 385 */
385 386 static const char *index_node(indexObject *self, Py_ssize_t pos)
386 387 {
387 388 Py_ssize_t length = index_length(self);
388 389 const char *data;
389 390
390 391 if (pos == length - 1 || pos == INT_MAX)
391 392 return nullid;
392 393
393 394 if (pos >= length)
394 395 return NULL;
395 396
396 397 if (pos >= self->length - 1) {
397 398 PyObject *tuple, *str;
398 399 tuple = PyList_GET_ITEM(self->added, pos - self->length + 1);
399 400 str = PyTuple_GetItem(tuple, 7);
400 401 return str ? PyString_AS_STRING(str) : NULL;
401 402 }
402 403
403 404 data = index_deref(self, pos);
404 405 return data ? data + 32 : NULL;
405 406 }
406 407
407 408 static int nt_insert(indexObject *self, const char *node, int rev);
408 409
409 410 static int node_check(PyObject *obj, char **node, Py_ssize_t *nodelen)
410 411 {
411 412 if (PyString_AsStringAndSize(obj, node, nodelen) == -1)
412 413 return -1;
413 414 if (*nodelen == 20)
414 415 return 0;
415 416 PyErr_SetString(PyExc_ValueError, "20-byte hash required");
416 417 return -1;
417 418 }
418 419
419 420 static PyObject *index_insert(indexObject *self, PyObject *args)
420 421 {
421 422 PyObject *obj;
422 423 char *node;
423 424 long offset;
424 425 Py_ssize_t len, nodelen;
425 426
426 427 if (!PyArg_ParseTuple(args, "lO", &offset, &obj))
427 428 return NULL;
428 429
429 430 if (!PyTuple_Check(obj) || PyTuple_GET_SIZE(obj) != 8) {
430 431 PyErr_SetString(PyExc_TypeError, "8-tuple required");
431 432 return NULL;
432 433 }
433 434
434 435 if (node_check(PyTuple_GET_ITEM(obj, 7), &node, &nodelen) == -1)
435 436 return NULL;
436 437
437 438 len = index_length(self);
438 439
439 440 if (offset < 0)
440 441 offset += len;
441 442
442 443 if (offset != len - 1) {
443 444 PyErr_SetString(PyExc_IndexError,
444 445 "insert only supported at index -1");
445 446 return NULL;
446 447 }
447 448
448 449 if (offset > INT_MAX) {
449 450 PyErr_SetString(PyExc_ValueError,
450 451 "currently only 2**31 revs supported");
451 452 return NULL;
452 453 }
453 454
454 455 if (self->added == NULL) {
455 456 self->added = PyList_New(0);
456 457 if (self->added == NULL)
457 458 return NULL;
458 459 }
459 460
460 461 if (PyList_Append(self->added, obj) == -1)
461 462 return NULL;
462 463
463 464 if (self->nt)
464 465 nt_insert(self, node, (int)offset);
465 466
467 Py_CLEAR(self->headrevs);
466 468 Py_RETURN_NONE;
467 469 }
468 470
469 471 static void _index_clearcaches(indexObject *self)
470 472 {
471 473 if (self->cache) {
472 474 Py_ssize_t i;
473 475
474 476 for (i = 0; i < self->raw_length; i++)
475 477 Py_CLEAR(self->cache[i]);
476 478 free(self->cache);
477 479 self->cache = NULL;
478 480 }
479 481 if (self->offsets) {
480 482 free(self->offsets);
481 483 self->offsets = NULL;
482 484 }
483 485 if (self->nt) {
484 486 free(self->nt);
485 487 self->nt = NULL;
486 488 }
489 Py_CLEAR(self->headrevs);
487 490 }
488 491
489 492 static PyObject *index_clearcaches(indexObject *self)
490 493 {
491 494 _index_clearcaches(self);
492 495 self->ntlength = self->ntcapacity = 0;
493 496 self->ntdepth = self->ntsplits = 0;
494 497 self->ntrev = -1;
495 498 self->ntlookups = self->ntmisses = 0;
496 499 Py_RETURN_NONE;
497 500 }
498 501
499 502 static PyObject *index_stats(indexObject *self)
500 503 {
501 504 PyObject *obj = PyDict_New();
502 505
503 506 if (obj == NULL)
504 507 return NULL;
505 508
506 509 #define istat(__n, __d) \
507 510 if (PyDict_SetItemString(obj, __d, PyInt_FromSsize_t(self->__n)) == -1) \
508 511 goto bail;
509 512
510 513 if (self->added) {
511 514 Py_ssize_t len = PyList_GET_SIZE(self->added);
512 515 if (PyDict_SetItemString(obj, "index entries added",
513 516 PyInt_FromSsize_t(len)) == -1)
514 517 goto bail;
515 518 }
516 519
517 520 if (self->raw_length != self->length - 1)
518 521 istat(raw_length, "revs on disk");
519 522 istat(length, "revs in memory");
520 523 istat(ntcapacity, "node trie capacity");
521 524 istat(ntdepth, "node trie depth");
522 525 istat(ntlength, "node trie count");
523 526 istat(ntlookups, "node trie lookups");
524 527 istat(ntmisses, "node trie misses");
525 528 istat(ntrev, "node trie last rev scanned");
526 529 istat(ntsplits, "node trie splits");
527 530
528 531 #undef istat
529 532
530 533 return obj;
531 534
532 535 bail:
533 536 Py_XDECREF(obj);
534 537 return NULL;
535 538 }
536 539
540 /*
541 * When we cache a list, we want to be sure the caller can't mutate
542 * the cached copy.
543 */
544 static PyObject *list_copy(PyObject *list)
545 {
546 Py_ssize_t len = PyList_GET_SIZE(list);
547 PyObject *newlist = PyList_New(len);
548 Py_ssize_t i;
549
550 if (newlist == NULL)
551 return NULL;
552
553 for (i = 0; i < len; i++) {
554 PyObject *obj = PyList_GET_ITEM(list, i);
555 Py_INCREF(obj);
556 PyList_SET_ITEM(newlist, i, obj);
557 }
558
559 return newlist;
560 }
561
537 562 static PyObject *index_headrevs(indexObject *self)
538 563 {
539 564 Py_ssize_t i, len, addlen;
540 565 char *nothead = NULL;
541 566 PyObject *heads;
542 567
568 if (self->headrevs)
569 return list_copy(self->headrevs);
570
543 571 len = index_length(self) - 1;
544 572 heads = PyList_New(0);
545 573 if (heads == NULL)
546 574 goto bail;
547 575 if (len == 0) {
548 576 PyObject *nullid = PyInt_FromLong(-1);
549 577 if (nullid == NULL || PyList_Append(heads, nullid) == -1) {
550 578 Py_XDECREF(nullid);
551 579 goto bail;
552 580 }
553 581 goto done;
554 582 }
555 583
556 584 nothead = calloc(len, 1);
557 585 if (nothead == NULL)
558 586 goto bail;
559 587
560 588 for (i = 0; i < self->raw_length; i++) {
561 589 const char *data = index_deref(self, i);
562 590 int parent_1 = getbe32(data + 24);
563 591 int parent_2 = getbe32(data + 28);
564 592 if (parent_1 >= 0)
565 593 nothead[parent_1] = 1;
566 594 if (parent_2 >= 0)
567 595 nothead[parent_2] = 1;
568 596 }
569 597
570 598 addlen = self->added ? PyList_GET_SIZE(self->added) : 0;
571 599
572 600 for (i = 0; i < addlen; i++) {
573 601 PyObject *rev = PyList_GET_ITEM(self->added, i);
574 602 PyObject *p1 = PyTuple_GET_ITEM(rev, 5);
575 603 PyObject *p2 = PyTuple_GET_ITEM(rev, 6);
576 604 long parent_1, parent_2;
577 605
578 606 if (!PyInt_Check(p1) || !PyInt_Check(p2)) {
579 607 PyErr_SetString(PyExc_TypeError,
580 608 "revlog parents are invalid");
581 609 goto bail;
582 610 }
583 611 parent_1 = PyInt_AS_LONG(p1);
584 612 parent_2 = PyInt_AS_LONG(p2);
585 613 if (parent_1 >= 0)
586 614 nothead[parent_1] = 1;
587 615 if (parent_2 >= 0)
588 616 nothead[parent_2] = 1;
589 617 }
590 618
591 619 for (i = 0; i < len; i++) {
592 620 PyObject *head;
593 621
594 622 if (nothead[i])
595 623 continue;
596 624 head = PyInt_FromLong(i);
597 625 if (head == NULL || PyList_Append(heads, head) == -1) {
598 626 Py_XDECREF(head);
599 627 goto bail;
600 628 }
601 629 }
602 630
603 631 done:
632 self->headrevs = heads;
604 633 free(nothead);
605 return heads;
634 return list_copy(self->headrevs);
606 635 bail:
607 636 Py_XDECREF(heads);
608 637 free(nothead);
609 638 return NULL;
610 639 }
611 640
612 641 static inline int nt_level(const char *node, Py_ssize_t level)
613 642 {
614 643 int v = node[level>>1];
615 644 if (!(level & 1))
616 645 v >>= 4;
617 646 return v & 0xf;
618 647 }
619 648
620 649 /*
621 650 * Return values:
622 651 *
623 652 * -4: match is ambiguous (multiple candidates)
624 653 * -2: not found
625 654 * rest: valid rev
626 655 */
627 656 static int nt_find(indexObject *self, const char *node, Py_ssize_t nodelen,
628 657 int hex)
629 658 {
630 659 int (*getnybble)(const char *, Py_ssize_t) = hex ? hexdigit : nt_level;
631 660 int level, maxlevel, off;
632 661
633 662 if (nodelen == 20 && node[0] == '\0' && memcmp(node, nullid, 20) == 0)
634 663 return -1;
635 664
636 665 if (self->nt == NULL)
637 666 return -2;
638 667
639 668 if (hex)
640 669 maxlevel = nodelen > 40 ? 40 : (int)nodelen;
641 670 else
642 671 maxlevel = nodelen > 20 ? 40 : ((int)nodelen * 2);
643 672
644 673 for (level = off = 0; level < maxlevel; level++) {
645 674 int k = getnybble(node, level);
646 675 nodetree *n = &self->nt[off];
647 676 int v = n->children[k];
648 677
649 678 if (v < 0) {
650 679 const char *n;
651 680 Py_ssize_t i;
652 681
653 682 v = -v - 1;
654 683 n = index_node(self, v);
655 684 if (n == NULL)
656 685 return -2;
657 686 for (i = level; i < maxlevel; i++)
658 687 if (getnybble(node, i) != nt_level(n, i))
659 688 return -2;
660 689 return v;
661 690 }
662 691 if (v == 0)
663 692 return -2;
664 693 off = v;
665 694 }
666 695 /* multiple matches against an ambiguous prefix */
667 696 return -4;
668 697 }
669 698
670 699 static int nt_new(indexObject *self)
671 700 {
672 701 if (self->ntlength == self->ntcapacity) {
673 702 self->ntcapacity *= 2;
674 703 self->nt = realloc(self->nt,
675 704 self->ntcapacity * sizeof(nodetree));
676 705 if (self->nt == NULL) {
677 706 PyErr_SetString(PyExc_MemoryError, "out of memory");
678 707 return -1;
679 708 }
680 709 memset(&self->nt[self->ntlength], 0,
681 710 sizeof(nodetree) * (self->ntcapacity - self->ntlength));
682 711 }
683 712 return self->ntlength++;
684 713 }
685 714
686 715 static int nt_insert(indexObject *self, const char *node, int rev)
687 716 {
688 717 int level = 0;
689 718 int off = 0;
690 719
691 720 while (level < 40) {
692 721 int k = nt_level(node, level);
693 722 nodetree *n;
694 723 int v;
695 724
696 725 n = &self->nt[off];
697 726 v = n->children[k];
698 727
699 728 if (v == 0) {
700 729 n->children[k] = -rev - 1;
701 730 return 0;
702 731 }
703 732 if (v < 0) {
704 733 const char *oldnode = index_node(self, -v - 1);
705 734 int noff;
706 735
707 736 if (!oldnode || !memcmp(oldnode, node, 20)) {
708 737 n->children[k] = -rev - 1;
709 738 return 0;
710 739 }
711 740 noff = nt_new(self);
712 741 if (noff == -1)
713 742 return -1;
714 743 /* self->nt may have been changed by realloc */
715 744 self->nt[off].children[k] = noff;
716 745 off = noff;
717 746 n = &self->nt[off];
718 747 n->children[nt_level(oldnode, ++level)] = v;
719 748 if (level > self->ntdepth)
720 749 self->ntdepth = level;
721 750 self->ntsplits += 1;
722 751 } else {
723 752 level += 1;
724 753 off = v;
725 754 }
726 755 }
727 756
728 757 return -1;
729 758 }
730 759
731 760 static int nt_init(indexObject *self)
732 761 {
733 762 if (self->nt == NULL) {
734 763 self->ntcapacity = self->raw_length < 4
735 764 ? 4 : self->raw_length / 2;
736 765 self->nt = calloc(self->ntcapacity, sizeof(nodetree));
737 766 if (self->nt == NULL) {
738 767 PyErr_NoMemory();
739 768 return -1;
740 769 }
741 770 self->ntlength = 1;
742 771 self->ntrev = (int)index_length(self) - 1;
743 772 self->ntlookups = 1;
744 773 self->ntmisses = 0;
745 774 if (nt_insert(self, nullid, INT_MAX) == -1)
746 775 return -1;
747 776 }
748 777 return 0;
749 778 }
750 779
751 780 /*
752 781 * Return values:
753 782 *
754 783 * -3: error (exception set)
755 784 * -2: not found (no exception set)
756 785 * rest: valid rev
757 786 */
758 787 static int index_find_node(indexObject *self,
759 788 const char *node, Py_ssize_t nodelen)
760 789 {
761 790 int rev;
762 791
763 792 self->ntlookups++;
764 793 rev = nt_find(self, node, nodelen, 0);
765 794 if (rev >= -1)
766 795 return rev;
767 796
768 797 if (nt_init(self) == -1)
769 798 return -3;
770 799
771 800 /*
772 801 * For the first handful of lookups, we scan the entire index,
773 802 * and cache only the matching nodes. This optimizes for cases
774 803 * like "hg tip", where only a few nodes are accessed.
775 804 *
776 805 * After that, we cache every node we visit, using a single
777 806 * scan amortized over multiple lookups. This gives the best
778 807 * bulk performance, e.g. for "hg log".
779 808 */
780 809 if (self->ntmisses++ < 4) {
781 810 for (rev = self->ntrev - 1; rev >= 0; rev--) {
782 811 const char *n = index_node(self, rev);
783 812 if (n == NULL)
784 813 return -2;
785 814 if (memcmp(node, n, nodelen > 20 ? 20 : nodelen) == 0) {
786 815 if (nt_insert(self, n, rev) == -1)
787 816 return -3;
788 817 break;
789 818 }
790 819 }
791 820 } else {
792 821 for (rev = self->ntrev - 1; rev >= 0; rev--) {
793 822 const char *n = index_node(self, rev);
794 823 if (n == NULL) {
795 824 self->ntrev = rev + 1;
796 825 return -2;
797 826 }
798 827 if (nt_insert(self, n, rev) == -1) {
799 828 self->ntrev = rev + 1;
800 829 return -3;
801 830 }
802 831 if (memcmp(node, n, nodelen > 20 ? 20 : nodelen) == 0) {
803 832 break;
804 833 }
805 834 }
806 835 self->ntrev = rev;
807 836 }
808 837
809 838 if (rev >= 0)
810 839 return rev;
811 840 return -2;
812 841 }
813 842
814 843 static PyObject *raise_revlog_error(void)
815 844 {
816 845 static PyObject *errclass;
817 846 PyObject *mod = NULL, *errobj;
818 847
819 848 if (errclass == NULL) {
820 849 PyObject *dict;
821 850
822 851 mod = PyImport_ImportModule("mercurial.error");
823 852 if (mod == NULL)
824 853 goto classfail;
825 854
826 855 dict = PyModule_GetDict(mod);
827 856 if (dict == NULL)
828 857 goto classfail;
829 858
830 859 errclass = PyDict_GetItemString(dict, "RevlogError");
831 860 if (errclass == NULL) {
832 861 PyErr_SetString(PyExc_SystemError,
833 862 "could not find RevlogError");
834 863 goto classfail;
835 864 }
836 865 Py_INCREF(errclass);
837 866 }
838 867
839 868 errobj = PyObject_CallFunction(errclass, NULL);
840 869 if (errobj == NULL)
841 870 return NULL;
842 871 PyErr_SetObject(errclass, errobj);
843 872 return errobj;
844 873
845 874 classfail:
846 875 Py_XDECREF(mod);
847 876 return NULL;
848 877 }
849 878
850 879 static PyObject *index_getitem(indexObject *self, PyObject *value)
851 880 {
852 881 char *node;
853 882 Py_ssize_t nodelen;
854 883 int rev;
855 884
856 885 if (PyInt_Check(value))
857 886 return index_get(self, PyInt_AS_LONG(value));
858 887
859 888 if (node_check(value, &node, &nodelen) == -1)
860 889 return NULL;
861 890 rev = index_find_node(self, node, nodelen);
862 891 if (rev >= -1)
863 892 return PyInt_FromLong(rev);
864 893 if (rev == -2)
865 894 raise_revlog_error();
866 895 return NULL;
867 896 }
868 897
869 898 static int nt_partialmatch(indexObject *self, const char *node,
870 899 Py_ssize_t nodelen)
871 900 {
872 901 int rev;
873 902
874 903 if (nt_init(self) == -1)
875 904 return -3;
876 905
877 906 if (self->ntrev > 0) {
878 907 /* ensure that the radix tree is fully populated */
879 908 for (rev = self->ntrev - 1; rev >= 0; rev--) {
880 909 const char *n = index_node(self, rev);
881 910 if (n == NULL)
882 911 return -2;
883 912 if (nt_insert(self, n, rev) == -1)
884 913 return -3;
885 914 }
886 915 self->ntrev = rev;
887 916 }
888 917
889 918 return nt_find(self, node, nodelen, 1);
890 919 }
891 920
892 921 static PyObject *index_partialmatch(indexObject *self, PyObject *args)
893 922 {
894 923 const char *fullnode;
895 924 int nodelen;
896 925 char *node;
897 926 int rev, i;
898 927
899 928 if (!PyArg_ParseTuple(args, "s#", &node, &nodelen))
900 929 return NULL;
901 930
902 931 if (nodelen < 4) {
903 932 PyErr_SetString(PyExc_ValueError, "key too short");
904 933 return NULL;
905 934 }
906 935
907 936 if (nodelen > 40)
908 937 nodelen = 40;
909 938
910 939 for (i = 0; i < nodelen; i++)
911 940 hexdigit(node, i);
912 941 if (PyErr_Occurred()) {
913 942 /* input contains non-hex characters */
914 943 PyErr_Clear();
915 944 Py_RETURN_NONE;
916 945 }
917 946
918 947 rev = nt_partialmatch(self, node, nodelen);
919 948
920 949 switch (rev) {
921 950 case -4:
922 951 raise_revlog_error();
923 952 case -3:
924 953 return NULL;
925 954 case -2:
926 955 Py_RETURN_NONE;
927 956 case -1:
928 957 return PyString_FromStringAndSize(nullid, 20);
929 958 }
930 959
931 960 fullnode = index_node(self, rev);
932 961 if (fullnode == NULL) {
933 962 PyErr_Format(PyExc_IndexError,
934 963 "could not access rev %d", rev);
935 964 return NULL;
936 965 }
937 966 return PyString_FromStringAndSize(fullnode, 20);
938 967 }
939 968
940 969 static PyObject *index_m_get(indexObject *self, PyObject *args)
941 970 {
942 971 Py_ssize_t nodelen;
943 972 PyObject *val;
944 973 char *node;
945 974 int rev;
946 975
947 976 if (!PyArg_ParseTuple(args, "O", &val))
948 977 return NULL;
949 978 if (node_check(val, &node, &nodelen) == -1)
950 979 return NULL;
951 980 rev = index_find_node(self, node, nodelen);
952 981 if (rev == -3)
953 982 return NULL;
954 983 if (rev == -2)
955 984 Py_RETURN_NONE;
956 985 return PyInt_FromLong(rev);
957 986 }
958 987
959 988 static int index_contains(indexObject *self, PyObject *value)
960 989 {
961 990 char *node;
962 991 Py_ssize_t nodelen;
963 992
964 993 if (PyInt_Check(value)) {
965 994 long rev = PyInt_AS_LONG(value);
966 995 return rev >= -1 && rev < index_length(self);
967 996 }
968 997
969 998 if (node_check(value, &node, &nodelen) == -1)
970 999 return -1;
971 1000
972 1001 switch (index_find_node(self, node, nodelen)) {
973 1002 case -3:
974 1003 return -1;
975 1004 case -2:
976 1005 return 0;
977 1006 default:
978 1007 return 1;
979 1008 }
980 1009 }
981 1010
982 1011 /*
983 1012 * Invalidate any trie entries introduced by added revs.
984 1013 */
985 1014 static void nt_invalidate_added(indexObject *self, Py_ssize_t start)
986 1015 {
987 1016 Py_ssize_t i, len = PyList_GET_SIZE(self->added);
988 1017
989 1018 for (i = start; i < len; i++) {
990 1019 PyObject *tuple = PyList_GET_ITEM(self->added, i);
991 1020 PyObject *node = PyTuple_GET_ITEM(tuple, 7);
992 1021
993 1022 nt_insert(self, PyString_AS_STRING(node), -1);
994 1023 }
995 1024
996 1025 if (start == 0)
997 1026 Py_CLEAR(self->added);
998 1027 }
999 1028
1000 1029 /*
1001 1030 * Delete a numeric range of revs, which must be at the end of the
1002 1031 * range, but exclude the sentinel nullid entry.
1003 1032 */
1004 1033 static int index_slice_del(indexObject *self, PyObject *item)
1005 1034 {
1006 1035 Py_ssize_t start, stop, step, slicelength;
1007 1036 Py_ssize_t length = index_length(self);
1008 1037 int ret = 0;
1009 1038
1010 1039 if (PySlice_GetIndicesEx((PySliceObject*)item, length,
1011 1040 &start, &stop, &step, &slicelength) < 0)
1012 1041 return -1;
1013 1042
1014 1043 if (slicelength <= 0)
1015 1044 return 0;
1016 1045
1017 1046 if ((step < 0 && start < stop) || (step > 0 && start > stop))
1018 1047 stop = start;
1019 1048
1020 1049 if (step < 0) {
1021 1050 stop = start + 1;
1022 1051 start = stop + step*(slicelength - 1) - 1;
1023 1052 step = -step;
1024 1053 }
1025 1054
1026 1055 if (step != 1) {
1027 1056 PyErr_SetString(PyExc_ValueError,
1028 1057 "revlog index delete requires step size of 1");
1029 1058 return -1;
1030 1059 }
1031 1060
1032 1061 if (stop != length - 1) {
1033 1062 PyErr_SetString(PyExc_IndexError,
1034 1063 "revlog index deletion indices are invalid");
1035 1064 return -1;
1036 1065 }
1037 1066
1038 1067 if (start < self->length - 1) {
1039 1068 if (self->nt) {
1040 1069 Py_ssize_t i;
1041 1070
1042 1071 for (i = start + 1; i < self->length - 1; i++) {
1043 1072 const char *node = index_node(self, i);
1044 1073
1045 1074 if (node)
1046 1075 nt_insert(self, node, -1);
1047 1076 }
1048 1077 if (self->added)
1049 1078 nt_invalidate_added(self, 0);
1050 1079 if (self->ntrev > start)
1051 1080 self->ntrev = (int)start;
1052 1081 }
1053 1082 self->length = start + 1;
1054 1083 if (start < self->raw_length)
1055 1084 self->raw_length = start;
1056 1085 goto done;
1057 1086 }
1058 1087
1059 1088 if (self->nt) {
1060 1089 nt_invalidate_added(self, start - self->length + 1);
1061 1090 if (self->ntrev > start)
1062 1091 self->ntrev = (int)start;
1063 1092 }
1064 1093 if (self->added)
1065 1094 ret = PyList_SetSlice(self->added, start - self->length + 1,
1066 1095 PyList_GET_SIZE(self->added), NULL);
1067 1096 done:
1097 Py_CLEAR(self->headrevs);
1068 1098 return ret;
1069 1099 }
1070 1100
1071 1101 /*
1072 1102 * Supported ops:
1073 1103 *
1074 1104 * slice deletion
1075 1105 * string assignment (extend node->rev mapping)
1076 1106 * string deletion (shrink node->rev mapping)
1077 1107 */
1078 1108 static int index_assign_subscript(indexObject *self, PyObject *item,
1079 1109 PyObject *value)
1080 1110 {
1081 1111 char *node;
1082 1112 Py_ssize_t nodelen;
1083 1113 long rev;
1084 1114
1085 1115 if (PySlice_Check(item) && value == NULL)
1086 1116 return index_slice_del(self, item);
1087 1117
1088 1118 if (node_check(item, &node, &nodelen) == -1)
1089 1119 return -1;
1090 1120
1091 1121 if (value == NULL)
1092 1122 return self->nt ? nt_insert(self, node, -1) : 0;
1093 1123 rev = PyInt_AsLong(value);
1094 1124 if (rev > INT_MAX || rev < 0) {
1095 1125 if (!PyErr_Occurred())
1096 1126 PyErr_SetString(PyExc_ValueError, "rev out of range");
1097 1127 return -1;
1098 1128 }
1099 1129 return nt_insert(self, node, (int)rev);
1100 1130 }
1101 1131
1102 1132 /*
1103 1133 * Find all RevlogNG entries in an index that has inline data. Update
1104 1134 * the optional "offsets" table with those entries.
1105 1135 */
1106 1136 static long inline_scan(indexObject *self, const char **offsets)
1107 1137 {
1108 1138 const char *data = PyString_AS_STRING(self->data);
1109 1139 const char *end = data + PyString_GET_SIZE(self->data);
1110 1140 const long hdrsize = 64;
1111 1141 long incr = hdrsize;
1112 1142 Py_ssize_t len = 0;
1113 1143
1114 1144 while (data + hdrsize <= end) {
1115 1145 uint32_t comp_len;
1116 1146 const char *old_data;
1117 1147 /* 3rd element of header is length of compressed inline data */
1118 1148 comp_len = getbe32(data + 8);
1119 1149 incr = hdrsize + comp_len;
1120 1150 if (incr < hdrsize)
1121 1151 break;
1122 1152 if (offsets)
1123 1153 offsets[len] = data;
1124 1154 len++;
1125 1155 old_data = data;
1126 1156 data += incr;
1127 1157 if (data <= old_data)
1128 1158 break;
1129 1159 }
1130 1160
1131 1161 if (data != end && data + hdrsize != end) {
1132 1162 if (!PyErr_Occurred())
1133 1163 PyErr_SetString(PyExc_ValueError, "corrupt index file");
1134 1164 return -1;
1135 1165 }
1136 1166
1137 1167 return len;
1138 1168 }
1139 1169
1140 1170 static int index_init(indexObject *self, PyObject *args)
1141 1171 {
1142 1172 PyObject *data_obj, *inlined_obj;
1143 1173 Py_ssize_t size;
1144 1174
1145 1175 if (!PyArg_ParseTuple(args, "OO", &data_obj, &inlined_obj))
1146 1176 return -1;
1147 1177 if (!PyString_Check(data_obj)) {
1148 1178 PyErr_SetString(PyExc_TypeError, "data is not a string");
1149 1179 return -1;
1150 1180 }
1151 1181 size = PyString_GET_SIZE(data_obj);
1152 1182
1153 1183 self->inlined = inlined_obj && PyObject_IsTrue(inlined_obj);
1154 1184 self->data = data_obj;
1155 1185 self->cache = NULL;
1156 1186
1157 1187 self->added = NULL;
1188 self->headrevs = NULL;
1158 1189 self->offsets = NULL;
1159 1190 self->nt = NULL;
1160 1191 self->ntlength = self->ntcapacity = 0;
1161 1192 self->ntdepth = self->ntsplits = 0;
1162 1193 self->ntlookups = self->ntmisses = 0;
1163 1194 self->ntrev = -1;
1164 1195 Py_INCREF(self->data);
1165 1196
1166 1197 if (self->inlined) {
1167 1198 long len = inline_scan(self, NULL);
1168 1199 if (len == -1)
1169 1200 goto bail;
1170 1201 self->raw_length = len;
1171 1202 self->length = len + 1;
1172 1203 } else {
1173 1204 if (size % 64) {
1174 1205 PyErr_SetString(PyExc_ValueError, "corrupt index file");
1175 1206 goto bail;
1176 1207 }
1177 1208 self->raw_length = size / 64;
1178 1209 self->length = self->raw_length + 1;
1179 1210 }
1180 1211
1181 1212 return 0;
1182 1213 bail:
1183 1214 return -1;
1184 1215 }
1185 1216
1186 1217 static PyObject *index_nodemap(indexObject *self)
1187 1218 {
1188 1219 Py_INCREF(self);
1189 1220 return (PyObject *)self;
1190 1221 }
1191 1222
1192 1223 static void index_dealloc(indexObject *self)
1193 1224 {
1194 1225 _index_clearcaches(self);
1195 1226 Py_DECREF(self->data);
1196 1227 Py_XDECREF(self->added);
1197 1228 PyObject_Del(self);
1198 1229 }
1199 1230
1200 1231 static PySequenceMethods index_sequence_methods = {
1201 1232 (lenfunc)index_length, /* sq_length */
1202 1233 0, /* sq_concat */
1203 1234 0, /* sq_repeat */
1204 1235 (ssizeargfunc)index_get, /* sq_item */
1205 1236 0, /* sq_slice */
1206 1237 0, /* sq_ass_item */
1207 1238 0, /* sq_ass_slice */
1208 1239 (objobjproc)index_contains, /* sq_contains */
1209 1240 };
1210 1241
1211 1242 static PyMappingMethods index_mapping_methods = {
1212 1243 (lenfunc)index_length, /* mp_length */
1213 1244 (binaryfunc)index_getitem, /* mp_subscript */
1214 1245 (objobjargproc)index_assign_subscript, /* mp_ass_subscript */
1215 1246 };
1216 1247
1217 1248 static PyMethodDef index_methods[] = {
1218 1249 {"clearcaches", (PyCFunction)index_clearcaches, METH_NOARGS,
1219 1250 "clear the index caches"},
1220 1251 {"get", (PyCFunction)index_m_get, METH_VARARGS,
1221 1252 "get an index entry"},
1222 1253 {"headrevs", (PyCFunction)index_headrevs, METH_NOARGS,
1223 1254 "get head revisions"},
1224 1255 {"insert", (PyCFunction)index_insert, METH_VARARGS,
1225 1256 "insert an index entry"},
1226 1257 {"partialmatch", (PyCFunction)index_partialmatch, METH_VARARGS,
1227 1258 "match a potentially ambiguous node ID"},
1228 1259 {"stats", (PyCFunction)index_stats, METH_NOARGS,
1229 1260 "stats for the index"},
1230 1261 {NULL} /* Sentinel */
1231 1262 };
1232 1263
1233 1264 static PyGetSetDef index_getset[] = {
1234 1265 {"nodemap", (getter)index_nodemap, NULL, "nodemap", NULL},
1235 1266 {NULL} /* Sentinel */
1236 1267 };
1237 1268
1238 1269 static PyTypeObject indexType = {
1239 1270 PyObject_HEAD_INIT(NULL)
1240 1271 0, /* ob_size */
1241 1272 "parsers.index", /* tp_name */
1242 1273 sizeof(indexObject), /* tp_basicsize */
1243 1274 0, /* tp_itemsize */
1244 1275 (destructor)index_dealloc, /* tp_dealloc */
1245 1276 0, /* tp_print */
1246 1277 0, /* tp_getattr */
1247 1278 0, /* tp_setattr */
1248 1279 0, /* tp_compare */
1249 1280 0, /* tp_repr */
1250 1281 0, /* tp_as_number */
1251 1282 &index_sequence_methods, /* tp_as_sequence */
1252 1283 &index_mapping_methods, /* tp_as_mapping */
1253 1284 0, /* tp_hash */
1254 1285 0, /* tp_call */
1255 1286 0, /* tp_str */
1256 1287 0, /* tp_getattro */
1257 1288 0, /* tp_setattro */
1258 1289 0, /* tp_as_buffer */
1259 1290 Py_TPFLAGS_DEFAULT, /* tp_flags */
1260 1291 "revlog index", /* tp_doc */
1261 1292 0, /* tp_traverse */
1262 1293 0, /* tp_clear */
1263 1294 0, /* tp_richcompare */
1264 1295 0, /* tp_weaklistoffset */
1265 1296 0, /* tp_iter */
1266 1297 0, /* tp_iternext */
1267 1298 index_methods, /* tp_methods */
1268 1299 0, /* tp_members */
1269 1300 index_getset, /* tp_getset */
1270 1301 0, /* tp_base */
1271 1302 0, /* tp_dict */
1272 1303 0, /* tp_descr_get */
1273 1304 0, /* tp_descr_set */
1274 1305 0, /* tp_dictoffset */
1275 1306 (initproc)index_init, /* tp_init */
1276 1307 0, /* tp_alloc */
1277 1308 };
1278 1309
1279 1310 /*
1280 1311 * returns a tuple of the form (index, index, cache) with elements as
1281 1312 * follows:
1282 1313 *
1283 1314 * index: an index object that lazily parses RevlogNG records
1284 1315 * cache: if data is inlined, a tuple (index_file_content, 0), else None
1285 1316 *
1286 1317 * added complications are for backwards compatibility
1287 1318 */
1288 1319 static PyObject *parse_index2(PyObject *self, PyObject *args)
1289 1320 {
1290 1321 PyObject *tuple = NULL, *cache = NULL;
1291 1322 indexObject *idx;
1292 1323 int ret;
1293 1324
1294 1325 idx = PyObject_New(indexObject, &indexType);
1295 1326 if (idx == NULL)
1296 1327 goto bail;
1297 1328
1298 1329 ret = index_init(idx, args);
1299 1330 if (ret == -1)
1300 1331 goto bail;
1301 1332
1302 1333 if (idx->inlined) {
1303 1334 cache = Py_BuildValue("iO", 0, idx->data);
1304 1335 if (cache == NULL)
1305 1336 goto bail;
1306 1337 } else {
1307 1338 cache = Py_None;
1308 1339 Py_INCREF(cache);
1309 1340 }
1310 1341
1311 1342 tuple = Py_BuildValue("NN", idx, cache);
1312 1343 if (!tuple)
1313 1344 goto bail;
1314 1345 return tuple;
1315 1346
1316 1347 bail:
1317 1348 Py_XDECREF(idx);
1318 1349 Py_XDECREF(cache);
1319 1350 Py_XDECREF(tuple);
1320 1351 return NULL;
1321 1352 }
1322 1353
1323 1354 static char parsers_doc[] = "Efficient content parsing.";
1324 1355
1325 1356 static PyMethodDef methods[] = {
1326 1357 {"parse_manifest", parse_manifest, METH_VARARGS, "parse a manifest\n"},
1327 1358 {"parse_dirstate", parse_dirstate, METH_VARARGS, "parse a dirstate\n"},
1328 1359 {"parse_index2", parse_index2, METH_VARARGS, "parse a revlog index\n"},
1329 1360 {NULL, NULL}
1330 1361 };
1331 1362
1332 1363 static void module_init(PyObject *mod)
1333 1364 {
1334 1365 indexType.tp_new = PyType_GenericNew;
1335 1366 if (PyType_Ready(&indexType) < 0)
1336 1367 return;
1337 1368 Py_INCREF(&indexType);
1338 1369
1339 1370 PyModule_AddObject(mod, "index", (PyObject *)&indexType);
1340 1371
1341 1372 nullentry = Py_BuildValue("iiiiiiis#", 0, 0, 0,
1342 1373 -1, -1, -1, -1, nullid, 20);
1343 1374 if (nullentry)
1344 1375 PyObject_GC_UnTrack(nullentry);
1345 1376 }
1346 1377
1347 1378 #ifdef IS_PY3K
1348 1379 static struct PyModuleDef parsers_module = {
1349 1380 PyModuleDef_HEAD_INIT,
1350 1381 "parsers",
1351 1382 parsers_doc,
1352 1383 -1,
1353 1384 methods
1354 1385 };
1355 1386
1356 1387 PyMODINIT_FUNC PyInit_parsers(void)
1357 1388 {
1358 1389 PyObject *mod = PyModule_Create(&parsers_module);
1359 1390 module_init(mod);
1360 1391 return mod;
1361 1392 }
1362 1393 #else
1363 1394 PyMODINIT_FUNC initparsers(void)
1364 1395 {
1365 1396 PyObject *mod = Py_InitModule3("parsers", methods, parsers_doc);
1366 1397 module_init(mod);
1367 1398 }
1368 1399 #endif
General Comments 0
You need to be logged in to leave comments. Login now