Mercurial > hg
annotate mercurial/cext/manifest.c @ 45350:1c8e3c17c702
makefile: stop setting unused HGEXTDIR variable during osx build
The variable was added in a38ed42cd23c (osx: include chg by default,
2017-03-20), but I can't find any others references to the variable in
that commit or in any other commits.
Differential Revision: https://phab.mercurial-scm.org/D8915
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 07 Aug 2020 21:59:43 -0700 |
parents | 9719e118e4af |
children | 12450fbea288 |
rev | line source |
---|---|
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1 /* |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
2 * manifest.c - manifest type that does on-demand parsing. |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
3 * |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
4 * Copyright 2015, Google Inc. |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
5 * |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
6 * This software may be used and distributed according to the terms of |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
7 * the GNU General Public License, incorporated herein by reference. |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
8 */ |
24352
d6dbe4d1c9bc
manifest: include Python.h before standard headers
Drew Gottlieb <drgott@google.com>
parents:
24312
diff
changeset
|
9 #include <Python.h> |
d6dbe4d1c9bc
manifest: include Python.h before standard headers
Drew Gottlieb <drgott@google.com>
parents:
24312
diff
changeset
|
10 |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
11 #include <assert.h> |
34438
b90e8da190da
cext: reorder #include
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33758
diff
changeset
|
12 #include <stdlib.h> |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
13 #include <string.h> |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
14 |
33758
0f4ac3b6dee4
cext: factor out header for charencode.c
Yuya Nishihara <yuya@tcha.org>
parents:
33757
diff
changeset
|
15 #include "charencode.h" |
24441
e2ed40f0eb2e
manifest: use util.h to get Py_ssize_t
Matt Mackall <mpm@selenic.com>
parents:
24352
diff
changeset
|
16 #include "util.h" |
e2ed40f0eb2e
manifest: use util.h to get Py_ssize_t
Matt Mackall <mpm@selenic.com>
parents:
24352
diff
changeset
|
17 |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
18 #define DEFAULT_LINES 100000 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
19 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
20 typedef struct { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
21 char *start; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
22 Py_ssize_t len; /* length of line including terminal newline */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
23 char hash_suffix; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
24 bool from_malloc; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
25 bool deleted; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
26 } line; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
27 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
28 typedef struct { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
29 PyObject_HEAD |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
30 PyObject *pydata; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
31 line *lines; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
32 int numlines; /* number of line entries */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
33 int livelines; /* number of non-deleted lines */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
34 int maxlines; /* allocated number of lines */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
35 bool dirty; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
36 } lazymanifest; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
37 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
38 #define MANIFEST_OOM -1 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
39 #define MANIFEST_NOT_SORTED -2 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
40 #define MANIFEST_MALFORMED -3 |
40599
9eeda7199181
manifest: make sure there's a filename before bothering to look for newline
Augie Fackler <augie@google.com>
parents:
39940
diff
changeset
|
41 #define MANIFEST_BOGUS_FILENAME -4 |
40600
f27f8e9ef1e7
manifest: also reject obviously-too-short lines when parsing lines
Augie Fackler <augie@google.com>
parents:
40599
diff
changeset
|
42 #define MANIFEST_TOO_SHORT_LINE -5 |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
43 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
44 /* get the length of the path for a line */ |
44100
969527ac7b44
cext: fix compiler warning about sign changing
Kyle Lippincott <spectral@google.com>
parents:
40765
diff
changeset
|
45 static Py_ssize_t pathlen(line *l) |
34440
7ed0750c71a1
cext: wrap before brace for functions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34438
diff
changeset
|
46 { |
39939
e85462d48cb3
manifest: rewrite pathlen() to not cross entry boundary
Yuya Nishihara <yuya@tcha.org>
parents:
39424
diff
changeset
|
47 const char *end = memchr(l->start, '\0', l->len); |
44100
969527ac7b44
cext: fix compiler warning about sign changing
Kyle Lippincott <spectral@google.com>
parents:
40765
diff
changeset
|
48 return (end) ? (Py_ssize_t)(end - l->start) : l->len; |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
49 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
50 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
51 /* get the node value of a single line */ |
45118
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
52 static PyObject *nodeof(line *l, char *flag) |
34440
7ed0750c71a1
cext: wrap before brace for functions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34438
diff
changeset
|
53 { |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
54 char *s = l->start; |
44100
969527ac7b44
cext: fix compiler warning about sign changing
Kyle Lippincott <spectral@google.com>
parents:
40765
diff
changeset
|
55 Py_ssize_t llen = pathlen(l); |
44702
0b0e72b5d551
manifest: start removing 40-byte hash restrictions from C code
Augie Fackler <augie@google.com>
parents:
44132
diff
changeset
|
56 Py_ssize_t hlen = l->len - llen - 2; |
45118
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
57 Py_ssize_t hlen_raw; |
39940
5405cb1a7901
manifest: fix out-of-bounds read of corrupted manifest entry
Yuya Nishihara <yuya@tcha.org>
parents:
39939
diff
changeset
|
58 PyObject *hash; |
5405cb1a7901
manifest: fix out-of-bounds read of corrupted manifest entry
Yuya Nishihara <yuya@tcha.org>
parents:
39939
diff
changeset
|
59 if (llen + 1 + 40 + 1 > l->len) { /* path '\0' hash '\n' */ |
5405cb1a7901
manifest: fix out-of-bounds read of corrupted manifest entry
Yuya Nishihara <yuya@tcha.org>
parents:
39939
diff
changeset
|
60 PyErr_SetString(PyExc_ValueError, "manifest line too short"); |
5405cb1a7901
manifest: fix out-of-bounds read of corrupted manifest entry
Yuya Nishihara <yuya@tcha.org>
parents:
39939
diff
changeset
|
61 return NULL; |
5405cb1a7901
manifest: fix out-of-bounds read of corrupted manifest entry
Yuya Nishihara <yuya@tcha.org>
parents:
39939
diff
changeset
|
62 } |
45118
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
63 /* Detect flags after the hash first. */ |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
64 switch (s[llen + hlen]) { |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
65 case 'l': |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
66 case 't': |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
67 case 'x': |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
68 *flag = s[llen + hlen]; |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
69 --hlen; |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
70 break; |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
71 default: |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
72 *flag = '\0'; |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
73 break; |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
74 } |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
75 |
44702
0b0e72b5d551
manifest: start removing 40-byte hash restrictions from C code
Augie Fackler <augie@google.com>
parents:
44132
diff
changeset
|
76 switch (hlen) { |
0b0e72b5d551
manifest: start removing 40-byte hash restrictions from C code
Augie Fackler <augie@google.com>
parents:
44132
diff
changeset
|
77 case 40: /* sha1 */ |
45118
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
78 hlen_raw = 20; |
44702
0b0e72b5d551
manifest: start removing 40-byte hash restrictions from C code
Augie Fackler <augie@google.com>
parents:
44132
diff
changeset
|
79 break; |
0b0e72b5d551
manifest: start removing 40-byte hash restrictions from C code
Augie Fackler <augie@google.com>
parents:
44132
diff
changeset
|
80 case 64: /* new hash */ |
0b0e72b5d551
manifest: start removing 40-byte hash restrictions from C code
Augie Fackler <augie@google.com>
parents:
44132
diff
changeset
|
81 hlen_raw = 32; |
0b0e72b5d551
manifest: start removing 40-byte hash restrictions from C code
Augie Fackler <augie@google.com>
parents:
44132
diff
changeset
|
82 break; |
0b0e72b5d551
manifest: start removing 40-byte hash restrictions from C code
Augie Fackler <augie@google.com>
parents:
44132
diff
changeset
|
83 default: |
0b0e72b5d551
manifest: start removing 40-byte hash restrictions from C code
Augie Fackler <augie@google.com>
parents:
44132
diff
changeset
|
84 PyErr_SetString(PyExc_ValueError, "invalid node length in manifest"); |
0b0e72b5d551
manifest: start removing 40-byte hash restrictions from C code
Augie Fackler <augie@google.com>
parents:
44132
diff
changeset
|
85 return NULL; |
0b0e72b5d551
manifest: start removing 40-byte hash restrictions from C code
Augie Fackler <augie@google.com>
parents:
44132
diff
changeset
|
86 } |
0b0e72b5d551
manifest: start removing 40-byte hash restrictions from C code
Augie Fackler <augie@google.com>
parents:
44132
diff
changeset
|
87 hash = unhexlify(s + llen + 1, hlen_raw * 2); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
88 if (!hash) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
89 return NULL; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
90 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
91 if (l->hash_suffix != '\0') { |
44702
0b0e72b5d551
manifest: start removing 40-byte hash restrictions from C code
Augie Fackler <augie@google.com>
parents:
44132
diff
changeset
|
92 char newhash[33]; |
0b0e72b5d551
manifest: start removing 40-byte hash restrictions from C code
Augie Fackler <augie@google.com>
parents:
44132
diff
changeset
|
93 memcpy(newhash, PyBytes_AsString(hash), hlen_raw); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
94 Py_DECREF(hash); |
44702
0b0e72b5d551
manifest: start removing 40-byte hash restrictions from C code
Augie Fackler <augie@google.com>
parents:
44132
diff
changeset
|
95 newhash[hlen_raw] = l->hash_suffix; |
0b0e72b5d551
manifest: start removing 40-byte hash restrictions from C code
Augie Fackler <augie@google.com>
parents:
44132
diff
changeset
|
96 hash = PyBytes_FromStringAndSize(newhash, hlen_raw+1); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
97 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
98 return hash; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
99 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
100 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
101 /* get the node hash and flags of a line as a tuple */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
102 static PyObject *hashflags(line *l) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
103 { |
45118
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
104 char flag; |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
105 PyObject *hash = nodeof(l, &flag); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
106 PyObject *flags; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
107 PyObject *tup; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
108 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
109 if (!hash) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
110 return NULL; |
45118
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
111 flags = PyBytes_FromStringAndSize(&flag, flag ? 1 : 0); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
112 if (!flags) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
113 Py_DECREF(hash); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
114 return NULL; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
115 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
116 tup = PyTuple_Pack(2, hash, flags); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
117 Py_DECREF(flags); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
118 Py_DECREF(hash); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
119 return tup; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
120 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
121 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
122 /* if we're about to run out of space in the line index, add more */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
123 static bool realloc_if_full(lazymanifest *self) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
124 { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
125 if (self->numlines == self->maxlines) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
126 self->maxlines *= 2; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
127 self->lines = realloc(self->lines, self->maxlines * sizeof(line)); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
128 } |
24312
f208ce59a6e5
manifest.c: ensure realloc_if_full() returns 1 or 0
Matt Harbison <matt_harbison@yahoo.com>
parents:
24298
diff
changeset
|
129 return !!self->lines; |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
130 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
131 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
132 /* |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
133 * Find the line boundaries in the manifest that 'data' points to and store |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
134 * information about each line in 'self'. |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
135 */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
136 static int find_lines(lazymanifest *self, char *data, Py_ssize_t len) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
137 { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
138 char *prev = NULL; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
139 while (len > 0) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
140 line *l; |
40599
9eeda7199181
manifest: make sure there's a filename before bothering to look for newline
Augie Fackler <augie@google.com>
parents:
39940
diff
changeset
|
141 char *next; |
9eeda7199181
manifest: make sure there's a filename before bothering to look for newline
Augie Fackler <augie@google.com>
parents:
39940
diff
changeset
|
142 if (*data == '\0') { |
9eeda7199181
manifest: make sure there's a filename before bothering to look for newline
Augie Fackler <augie@google.com>
parents:
39940
diff
changeset
|
143 /* It's implausible there's no filename, don't |
9eeda7199181
manifest: make sure there's a filename before bothering to look for newline
Augie Fackler <augie@google.com>
parents:
39940
diff
changeset
|
144 * even bother looking for the newline. */ |
9eeda7199181
manifest: make sure there's a filename before bothering to look for newline
Augie Fackler <augie@google.com>
parents:
39940
diff
changeset
|
145 return MANIFEST_BOGUS_FILENAME; |
9eeda7199181
manifest: make sure there's a filename before bothering to look for newline
Augie Fackler <augie@google.com>
parents:
39940
diff
changeset
|
146 } |
9eeda7199181
manifest: make sure there's a filename before bothering to look for newline
Augie Fackler <augie@google.com>
parents:
39940
diff
changeset
|
147 next = memchr(data, '\n', len); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
148 if (!next) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
149 return MANIFEST_MALFORMED; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
150 } |
40765
7e6834ade51d
manifest: reject lines shorter than 42 bytes, not 22
Augie Fackler <augie@google.com>
parents:
40601
diff
changeset
|
151 if ((next - data) < 42) { |
7e6834ade51d
manifest: reject lines shorter than 42 bytes, not 22
Augie Fackler <augie@google.com>
parents:
40601
diff
changeset
|
152 /* We should have at least 42 bytes in a line: |
40600
f27f8e9ef1e7
manifest: also reject obviously-too-short lines when parsing lines
Augie Fackler <augie@google.com>
parents:
40599
diff
changeset
|
153 1 byte filename |
f27f8e9ef1e7
manifest: also reject obviously-too-short lines when parsing lines
Augie Fackler <augie@google.com>
parents:
40599
diff
changeset
|
154 1 NUL |
40765
7e6834ade51d
manifest: reject lines shorter than 42 bytes, not 22
Augie Fackler <augie@google.com>
parents:
40601
diff
changeset
|
155 40 bytes of hash |
40600
f27f8e9ef1e7
manifest: also reject obviously-too-short lines when parsing lines
Augie Fackler <augie@google.com>
parents:
40599
diff
changeset
|
156 so we can give up here. |
f27f8e9ef1e7
manifest: also reject obviously-too-short lines when parsing lines
Augie Fackler <augie@google.com>
parents:
40599
diff
changeset
|
157 */ |
f27f8e9ef1e7
manifest: also reject obviously-too-short lines when parsing lines
Augie Fackler <augie@google.com>
parents:
40599
diff
changeset
|
158 return MANIFEST_TOO_SHORT_LINE; |
f27f8e9ef1e7
manifest: also reject obviously-too-short lines when parsing lines
Augie Fackler <augie@google.com>
parents:
40599
diff
changeset
|
159 } |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
160 next++; /* advance past newline */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
161 if (prev && strcmp(prev, data) > -1) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
162 /* This data isn't sorted, so we have to abort. */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
163 return MANIFEST_NOT_SORTED; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
164 } |
40601
da4478ca0e32
manifest: perform cheap checks before potentially allocating memory
Augie Fackler <augie@google.com>
parents:
40600
diff
changeset
|
165 if (!realloc_if_full(self)) { |
da4478ca0e32
manifest: perform cheap checks before potentially allocating memory
Augie Fackler <augie@google.com>
parents:
40600
diff
changeset
|
166 return MANIFEST_OOM; /* no memory */ |
da4478ca0e32
manifest: perform cheap checks before potentially allocating memory
Augie Fackler <augie@google.com>
parents:
40600
diff
changeset
|
167 } |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
168 l = self->lines + ((self->numlines)++); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
169 l->start = data; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
170 l->len = next - data; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
171 l->hash_suffix = '\0'; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
172 l->from_malloc = false; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
173 l->deleted = false; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
174 len = len - l->len; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
175 prev = data; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
176 data = next; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
177 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
178 self->livelines = self->numlines; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
179 return 0; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
180 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
181 |
38335
ae7f27867c2a
manifest: fix possible SEGV caused by uninitialized lazymanifest fields
Yuya Nishihara <yuya@tcha.org>
parents:
38302
diff
changeset
|
182 static void lazymanifest_init_early(lazymanifest *self) |
ae7f27867c2a
manifest: fix possible SEGV caused by uninitialized lazymanifest fields
Yuya Nishihara <yuya@tcha.org>
parents:
38302
diff
changeset
|
183 { |
ae7f27867c2a
manifest: fix possible SEGV caused by uninitialized lazymanifest fields
Yuya Nishihara <yuya@tcha.org>
parents:
38302
diff
changeset
|
184 self->pydata = NULL; |
ae7f27867c2a
manifest: fix possible SEGV caused by uninitialized lazymanifest fields
Yuya Nishihara <yuya@tcha.org>
parents:
38302
diff
changeset
|
185 self->lines = NULL; |
ae7f27867c2a
manifest: fix possible SEGV caused by uninitialized lazymanifest fields
Yuya Nishihara <yuya@tcha.org>
parents:
38302
diff
changeset
|
186 self->numlines = 0; |
ae7f27867c2a
manifest: fix possible SEGV caused by uninitialized lazymanifest fields
Yuya Nishihara <yuya@tcha.org>
parents:
38302
diff
changeset
|
187 self->maxlines = 0; |
ae7f27867c2a
manifest: fix possible SEGV caused by uninitialized lazymanifest fields
Yuya Nishihara <yuya@tcha.org>
parents:
38302
diff
changeset
|
188 } |
ae7f27867c2a
manifest: fix possible SEGV caused by uninitialized lazymanifest fields
Yuya Nishihara <yuya@tcha.org>
parents:
38302
diff
changeset
|
189 |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
190 static int lazymanifest_init(lazymanifest *self, PyObject *args) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
191 { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
192 char *data; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
193 Py_ssize_t len; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
194 int err, ret; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
195 PyObject *pydata; |
38335
ae7f27867c2a
manifest: fix possible SEGV caused by uninitialized lazymanifest fields
Yuya Nishihara <yuya@tcha.org>
parents:
38302
diff
changeset
|
196 |
ae7f27867c2a
manifest: fix possible SEGV caused by uninitialized lazymanifest fields
Yuya Nishihara <yuya@tcha.org>
parents:
38302
diff
changeset
|
197 lazymanifest_init_early(self); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
198 if (!PyArg_ParseTuple(args, "S", &pydata)) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
199 return -1; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
200 } |
30097
3bf4b762537e
manifest: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30079
diff
changeset
|
201 err = PyBytes_AsStringAndSize(pydata, &data, &len); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
202 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
203 self->dirty = false; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
204 if (err == -1) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
205 return -1; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
206 self->pydata = pydata; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
207 Py_INCREF(self->pydata); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
208 Py_BEGIN_ALLOW_THREADS |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
209 self->lines = malloc(DEFAULT_LINES * sizeof(line)); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
210 self->maxlines = DEFAULT_LINES; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
211 self->numlines = 0; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
212 if (!self->lines) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
213 ret = MANIFEST_OOM; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
214 else |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
215 ret = find_lines(self, data, len); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
216 Py_END_ALLOW_THREADS |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
217 switch (ret) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
218 case 0: |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
219 break; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
220 case MANIFEST_OOM: |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
221 PyErr_NoMemory(); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
222 break; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
223 case MANIFEST_NOT_SORTED: |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
224 PyErr_Format(PyExc_ValueError, |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
225 "Manifest lines not in sorted order."); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
226 break; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
227 case MANIFEST_MALFORMED: |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
228 PyErr_Format(PyExc_ValueError, |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
229 "Manifest did not end in a newline."); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
230 break; |
40599
9eeda7199181
manifest: make sure there's a filename before bothering to look for newline
Augie Fackler <augie@google.com>
parents:
39940
diff
changeset
|
231 case MANIFEST_BOGUS_FILENAME: |
9eeda7199181
manifest: make sure there's a filename before bothering to look for newline
Augie Fackler <augie@google.com>
parents:
39940
diff
changeset
|
232 PyErr_Format( |
9eeda7199181
manifest: make sure there's a filename before bothering to look for newline
Augie Fackler <augie@google.com>
parents:
39940
diff
changeset
|
233 PyExc_ValueError, |
9eeda7199181
manifest: make sure there's a filename before bothering to look for newline
Augie Fackler <augie@google.com>
parents:
39940
diff
changeset
|
234 "Manifest had an entry with a zero-length filename."); |
9eeda7199181
manifest: make sure there's a filename before bothering to look for newline
Augie Fackler <augie@google.com>
parents:
39940
diff
changeset
|
235 break; |
40600
f27f8e9ef1e7
manifest: also reject obviously-too-short lines when parsing lines
Augie Fackler <augie@google.com>
parents:
40599
diff
changeset
|
236 case MANIFEST_TOO_SHORT_LINE: |
f27f8e9ef1e7
manifest: also reject obviously-too-short lines when parsing lines
Augie Fackler <augie@google.com>
parents:
40599
diff
changeset
|
237 PyErr_Format( |
f27f8e9ef1e7
manifest: also reject obviously-too-short lines when parsing lines
Augie Fackler <augie@google.com>
parents:
40599
diff
changeset
|
238 PyExc_ValueError, |
f27f8e9ef1e7
manifest: also reject obviously-too-short lines when parsing lines
Augie Fackler <augie@google.com>
parents:
40599
diff
changeset
|
239 "Manifest had implausibly-short line."); |
f27f8e9ef1e7
manifest: also reject obviously-too-short lines when parsing lines
Augie Fackler <augie@google.com>
parents:
40599
diff
changeset
|
240 break; |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
241 default: |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
242 PyErr_Format(PyExc_ValueError, |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
243 "Unknown problem parsing manifest."); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
244 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
245 return ret == 0 ? 0 : -1; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
246 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
247 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
248 static void lazymanifest_dealloc(lazymanifest *self) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
249 { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
250 /* free any extra lines we had to allocate */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
251 int i; |
38302
6caca2a7d37f
lazymanifest: don't crash when out of memory (issue5916)
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
38301
diff
changeset
|
252 for (i = 0; self->lines && (i < self->numlines); i++) { |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
253 if (self->lines[i].from_malloc) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
254 free(self->lines[i].start); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
255 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
256 } |
38301
d9e87566f879
cext: stop worrying and love the free(NULL)
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
36619
diff
changeset
|
257 free(self->lines); |
d9e87566f879
cext: stop worrying and love the free(NULL)
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents:
36619
diff
changeset
|
258 self->lines = NULL; |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
259 if (self->pydata) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
260 Py_DECREF(self->pydata); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
261 self->pydata = NULL; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
262 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
263 PyObject_Del(self); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
264 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
265 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
266 /* iteration support */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
267 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
268 typedef struct { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
269 PyObject_HEAD lazymanifest *m; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
270 Py_ssize_t pos; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
271 } lmIter; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
272 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
273 static void lmiter_dealloc(PyObject *o) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
274 { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
275 lmIter *self = (lmIter *)o; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
276 Py_DECREF(self->m); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
277 PyObject_Del(self); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
278 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
279 |
24294
3d485727e45e
lazymanifest: extract function for iterating to next line
Martin von Zweigbergk <martinvonz@google.com>
parents:
24293
diff
changeset
|
280 static line *lmiter_nextline(lmIter *self) |
3d485727e45e
lazymanifest: extract function for iterating to next line
Martin von Zweigbergk <martinvonz@google.com>
parents:
24293
diff
changeset
|
281 { |
3d485727e45e
lazymanifest: extract function for iterating to next line
Martin von Zweigbergk <martinvonz@google.com>
parents:
24293
diff
changeset
|
282 do { |
3d485727e45e
lazymanifest: extract function for iterating to next line
Martin von Zweigbergk <martinvonz@google.com>
parents:
24293
diff
changeset
|
283 self->pos++; |
3d485727e45e
lazymanifest: extract function for iterating to next line
Martin von Zweigbergk <martinvonz@google.com>
parents:
24293
diff
changeset
|
284 if (self->pos >= self->m->numlines) { |
3d485727e45e
lazymanifest: extract function for iterating to next line
Martin von Zweigbergk <martinvonz@google.com>
parents:
24293
diff
changeset
|
285 return NULL; |
3d485727e45e
lazymanifest: extract function for iterating to next line
Martin von Zweigbergk <martinvonz@google.com>
parents:
24293
diff
changeset
|
286 } |
3d485727e45e
lazymanifest: extract function for iterating to next line
Martin von Zweigbergk <martinvonz@google.com>
parents:
24293
diff
changeset
|
287 /* skip over deleted manifest entries */ |
3d485727e45e
lazymanifest: extract function for iterating to next line
Martin von Zweigbergk <martinvonz@google.com>
parents:
24293
diff
changeset
|
288 } while (self->m->lines[self->pos].deleted); |
3d485727e45e
lazymanifest: extract function for iterating to next line
Martin von Zweigbergk <martinvonz@google.com>
parents:
24293
diff
changeset
|
289 return self->m->lines + self->pos; |
3d485727e45e
lazymanifest: extract function for iterating to next line
Martin von Zweigbergk <martinvonz@google.com>
parents:
24293
diff
changeset
|
290 } |
3d485727e45e
lazymanifest: extract function for iterating to next line
Martin von Zweigbergk <martinvonz@google.com>
parents:
24293
diff
changeset
|
291 |
24298
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24295
diff
changeset
|
292 static PyObject *lmiter_iterentriesnext(PyObject *o) |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
293 { |
44100
969527ac7b44
cext: fix compiler warning about sign changing
Kyle Lippincott <spectral@google.com>
parents:
40765
diff
changeset
|
294 Py_ssize_t pl; |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
295 line *l; |
45118
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
296 char flag; |
24699
64cd23a1bc13
lazymanifest: fix memory leak in lmiter_iterentriesnext() after 3d485727e45e
Mike Hommey <mh@glandium.org>
parents:
24442
diff
changeset
|
297 PyObject *ret = NULL, *path = NULL, *hash = NULL, *flags = NULL; |
24294
3d485727e45e
lazymanifest: extract function for iterating to next line
Martin von Zweigbergk <martinvonz@google.com>
parents:
24293
diff
changeset
|
298 l = lmiter_nextline((lmIter *)o); |
3d485727e45e
lazymanifest: extract function for iterating to next line
Martin von Zweigbergk <martinvonz@google.com>
parents:
24293
diff
changeset
|
299 if (!l) { |
24974
46408b80c3a1
lazymanifest: avoid 'bail' label when used on success path
Martin von Zweigbergk <martinvonz@google.com>
parents:
24710
diff
changeset
|
300 goto done; |
24294
3d485727e45e
lazymanifest: extract function for iterating to next line
Martin von Zweigbergk <martinvonz@google.com>
parents:
24293
diff
changeset
|
301 } |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
302 pl = pathlen(l); |
30097
3bf4b762537e
manifest: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30079
diff
changeset
|
303 path = PyBytes_FromStringAndSize(l->start, pl); |
45118
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
304 hash = nodeof(l, &flag); |
39940
5405cb1a7901
manifest: fix out-of-bounds read of corrupted manifest entry
Yuya Nishihara <yuya@tcha.org>
parents:
39939
diff
changeset
|
305 if (!path || !hash) { |
5405cb1a7901
manifest: fix out-of-bounds read of corrupted manifest entry
Yuya Nishihara <yuya@tcha.org>
parents:
39939
diff
changeset
|
306 goto done; |
5405cb1a7901
manifest: fix out-of-bounds read of corrupted manifest entry
Yuya Nishihara <yuya@tcha.org>
parents:
39939
diff
changeset
|
307 } |
45118
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
308 flags = PyBytes_FromStringAndSize(&flag, flag ? 1 : 0); |
39940
5405cb1a7901
manifest: fix out-of-bounds read of corrupted manifest entry
Yuya Nishihara <yuya@tcha.org>
parents:
39939
diff
changeset
|
309 if (!flags) { |
24974
46408b80c3a1
lazymanifest: avoid 'bail' label when used on success path
Martin von Zweigbergk <martinvonz@google.com>
parents:
24710
diff
changeset
|
310 goto done; |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
311 } |
24699
64cd23a1bc13
lazymanifest: fix memory leak in lmiter_iterentriesnext() after 3d485727e45e
Mike Hommey <mh@glandium.org>
parents:
24442
diff
changeset
|
312 ret = PyTuple_Pack(3, path, hash, flags); |
24975
89c2bf63a83b
lazymanifest: drop SP before some labels
Martin von Zweigbergk <martinvonz@google.com>
parents:
24974
diff
changeset
|
313 done: |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
314 Py_XDECREF(path); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
315 Py_XDECREF(hash); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
316 Py_XDECREF(flags); |
24699
64cd23a1bc13
lazymanifest: fix memory leak in lmiter_iterentriesnext() after 3d485727e45e
Mike Hommey <mh@glandium.org>
parents:
24442
diff
changeset
|
317 return ret; |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
318 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
319 |
30079
84debea79903
manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29254
diff
changeset
|
320 #ifdef IS_PY3K |
84debea79903
manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29254
diff
changeset
|
321 #define LAZYMANIFESTENTRIESITERATOR_TPFLAGS Py_TPFLAGS_DEFAULT |
84debea79903
manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29254
diff
changeset
|
322 #else |
84debea79903
manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29254
diff
changeset
|
323 #define LAZYMANIFESTENTRIESITERATOR_TPFLAGS Py_TPFLAGS_DEFAULT \ |
84debea79903
manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29254
diff
changeset
|
324 | Py_TPFLAGS_HAVE_ITER |
84debea79903
manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29254
diff
changeset
|
325 #endif |
84debea79903
manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29254
diff
changeset
|
326 |
24298
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24295
diff
changeset
|
327 static PyTypeObject lazymanifestEntriesIterator = { |
34861
6ece4a85c350
cext: add /* header */ comment to all PyVarObject_HEAD_INIT() calls
Augie Fackler <augie@google.com>
parents:
34440
diff
changeset
|
328 PyVarObject_HEAD_INIT(NULL, 0) /* header */ |
24298
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24295
diff
changeset
|
329 "parsers.lazymanifest.entriesiterator", /*tp_name */ |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
330 sizeof(lmIter), /*tp_basicsize */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
331 0, /*tp_itemsize */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
332 lmiter_dealloc, /*tp_dealloc */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
333 0, /*tp_print */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
334 0, /*tp_getattr */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
335 0, /*tp_setattr */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
336 0, /*tp_compare */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
337 0, /*tp_repr */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
338 0, /*tp_as_number */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
339 0, /*tp_as_sequence */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
340 0, /*tp_as_mapping */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
341 0, /*tp_hash */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
342 0, /*tp_call */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
343 0, /*tp_str */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
344 0, /*tp_getattro */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
345 0, /*tp_setattro */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
346 0, /*tp_as_buffer */ |
30079
84debea79903
manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29254
diff
changeset
|
347 LAZYMANIFESTENTRIESITERATOR_TPFLAGS, /* tp_flags */ |
24298
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24295
diff
changeset
|
348 "Iterator for 3-tuples in a lazymanifest.", /* tp_doc */ |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
349 0, /* tp_traverse */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
350 0, /* tp_clear */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
351 0, /* tp_richcompare */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
352 0, /* tp_weaklistoffset */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
353 PyObject_SelfIter, /* tp_iter: __iter__() method */ |
24298
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24295
diff
changeset
|
354 lmiter_iterentriesnext, /* tp_iternext: next() method */ |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
355 }; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
356 |
24295
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
357 static PyObject *lmiter_iterkeysnext(PyObject *o) |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
358 { |
44100
969527ac7b44
cext: fix compiler warning about sign changing
Kyle Lippincott <spectral@google.com>
parents:
40765
diff
changeset
|
359 Py_ssize_t pl; |
24295
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
360 line *l = lmiter_nextline((lmIter *)o); |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
361 if (!l) { |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
362 return NULL; |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
363 } |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
364 pl = pathlen(l); |
30097
3bf4b762537e
manifest: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30079
diff
changeset
|
365 return PyBytes_FromStringAndSize(l->start, pl); |
24295
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
366 } |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
367 |
30079
84debea79903
manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29254
diff
changeset
|
368 #ifdef IS_PY3K |
84debea79903
manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29254
diff
changeset
|
369 #define LAZYMANIFESTKEYSITERATOR_TPFLAGS Py_TPFLAGS_DEFAULT |
84debea79903
manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29254
diff
changeset
|
370 #else |
84debea79903
manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29254
diff
changeset
|
371 #define LAZYMANIFESTKEYSITERATOR_TPFLAGS Py_TPFLAGS_DEFAULT \ |
84debea79903
manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29254
diff
changeset
|
372 | Py_TPFLAGS_HAVE_ITER |
84debea79903
manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29254
diff
changeset
|
373 #endif |
84debea79903
manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29254
diff
changeset
|
374 |
24295
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
375 static PyTypeObject lazymanifestKeysIterator = { |
34861
6ece4a85c350
cext: add /* header */ comment to all PyVarObject_HEAD_INIT() calls
Augie Fackler <augie@google.com>
parents:
34440
diff
changeset
|
376 PyVarObject_HEAD_INIT(NULL, 0) /* header */ |
24295
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
377 "parsers.lazymanifest.keysiterator", /*tp_name */ |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
378 sizeof(lmIter), /*tp_basicsize */ |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
379 0, /*tp_itemsize */ |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
380 lmiter_dealloc, /*tp_dealloc */ |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
381 0, /*tp_print */ |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
382 0, /*tp_getattr */ |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
383 0, /*tp_setattr */ |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
384 0, /*tp_compare */ |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
385 0, /*tp_repr */ |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
386 0, /*tp_as_number */ |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
387 0, /*tp_as_sequence */ |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
388 0, /*tp_as_mapping */ |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
389 0, /*tp_hash */ |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
390 0, /*tp_call */ |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
391 0, /*tp_str */ |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
392 0, /*tp_getattro */ |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
393 0, /*tp_setattro */ |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
394 0, /*tp_as_buffer */ |
30079
84debea79903
manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29254
diff
changeset
|
395 LAZYMANIFESTKEYSITERATOR_TPFLAGS, /* tp_flags */ |
24295
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
396 "Keys iterator for a lazymanifest.", /* tp_doc */ |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
397 0, /* tp_traverse */ |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
398 0, /* tp_clear */ |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
399 0, /* tp_richcompare */ |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
400 0, /* tp_weaklistoffset */ |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
401 PyObject_SelfIter, /* tp_iter: __iter__() method */ |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
402 lmiter_iterkeysnext, /* tp_iternext: next() method */ |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
403 }; |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
404 |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
405 static lazymanifest *lazymanifest_copy(lazymanifest *self); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
406 |
24298
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24295
diff
changeset
|
407 static PyObject *lazymanifest_getentriesiter(lazymanifest *self) |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
408 { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
409 lmIter *i = NULL; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
410 lazymanifest *t = lazymanifest_copy(self); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
411 if (!t) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
412 PyErr_NoMemory(); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
413 return NULL; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
414 } |
24298
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24295
diff
changeset
|
415 i = PyObject_New(lmIter, &lazymanifestEntriesIterator); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
416 if (i) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
417 i->m = t; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
418 i->pos = -1; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
419 } else { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
420 Py_DECREF(t); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
421 PyErr_NoMemory(); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
422 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
423 return (PyObject *)i; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
424 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
425 |
24295
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
426 static PyObject *lazymanifest_getkeysiter(lazymanifest *self) |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
427 { |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
428 lmIter *i = NULL; |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
429 lazymanifest *t = lazymanifest_copy(self); |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
430 if (!t) { |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
431 PyErr_NoMemory(); |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
432 return NULL; |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
433 } |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
434 i = PyObject_New(lmIter, &lazymanifestKeysIterator); |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
435 if (i) { |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
436 i->m = t; |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
437 i->pos = -1; |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
438 } else { |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
439 Py_DECREF(t); |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
440 PyErr_NoMemory(); |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
441 } |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
442 return (PyObject *)i; |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
443 } |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
444 |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
445 /* __getitem__ and __setitem__ support */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
446 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
447 static Py_ssize_t lazymanifest_size(lazymanifest *self) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
448 { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
449 return self->livelines; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
450 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
451 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
452 static int linecmp(const void *left, const void *right) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
453 { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
454 return strcmp(((const line *)left)->start, |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
455 ((const line *)right)->start); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
456 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
457 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
458 static PyObject *lazymanifest_getitem(lazymanifest *self, PyObject *key) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
459 { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
460 line needle; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
461 line *hit; |
30097
3bf4b762537e
manifest: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30079
diff
changeset
|
462 if (!PyBytes_Check(key)) { |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
463 PyErr_Format(PyExc_TypeError, |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
464 "getitem: manifest keys must be a string."); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
465 return NULL; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
466 } |
30097
3bf4b762537e
manifest: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30079
diff
changeset
|
467 needle.start = PyBytes_AsString(key); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
468 hit = bsearch(&needle, self->lines, self->numlines, sizeof(line), |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
469 &linecmp); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
470 if (!hit || hit->deleted) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
471 PyErr_Format(PyExc_KeyError, "No such manifest entry."); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
472 return NULL; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
473 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
474 return hashflags(hit); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
475 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
476 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
477 static int lazymanifest_delitem(lazymanifest *self, PyObject *key) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
478 { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
479 line needle; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
480 line *hit; |
30097
3bf4b762537e
manifest: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30079
diff
changeset
|
481 if (!PyBytes_Check(key)) { |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
482 PyErr_Format(PyExc_TypeError, |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
483 "delitem: manifest keys must be a string."); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
484 return -1; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
485 } |
30097
3bf4b762537e
manifest: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30079
diff
changeset
|
486 needle.start = PyBytes_AsString(key); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
487 hit = bsearch(&needle, self->lines, self->numlines, sizeof(line), |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
488 &linecmp); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
489 if (!hit || hit->deleted) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
490 PyErr_Format(PyExc_KeyError, |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
491 "Tried to delete nonexistent manifest entry."); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
492 return -1; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
493 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
494 self->dirty = true; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
495 hit->deleted = true; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
496 self->livelines--; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
497 return 0; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
498 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
499 |
24228
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
500 /* Do a binary search for the insertion point for new, creating the |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
501 * new entry if needed. */ |
34440
7ed0750c71a1
cext: wrap before brace for functions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34438
diff
changeset
|
502 static int internalsetitem(lazymanifest *self, line *new) |
7ed0750c71a1
cext: wrap before brace for functions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34438
diff
changeset
|
503 { |
24228
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
504 int start = 0, end = self->numlines; |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
505 while (start < end) { |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
506 int pos = start + (end - start) / 2; |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
507 int c = linecmp(new, self->lines + pos); |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
508 if (c < 0) |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
509 end = pos; |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
510 else if (c > 0) |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
511 start = pos + 1; |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
512 else { |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
513 if (self->lines[pos].deleted) |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
514 self->livelines++; |
24710
909ee6b2a024
lazymanifest: prevent leak when updating an entry more than once
Augie Fackler <augie@google.com>
parents:
24699
diff
changeset
|
515 if (self->lines[pos].from_malloc) |
909ee6b2a024
lazymanifest: prevent leak when updating an entry more than once
Augie Fackler <augie@google.com>
parents:
24699
diff
changeset
|
516 free(self->lines[pos].start); |
24228
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
517 start = pos; |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
518 goto finish; |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
519 } |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
520 } |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
521 /* being here means we need to do an insert */ |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
522 if (!realloc_if_full(self)) { |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
523 PyErr_NoMemory(); |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
524 return -1; |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
525 } |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
526 memmove(self->lines + start + 1, self->lines + start, |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
527 (self->numlines - start) * sizeof(line)); |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
528 self->numlines++; |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
529 self->livelines++; |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
530 finish: |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
531 self->lines[start] = *new; |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
532 self->dirty = true; |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
533 return 0; |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
534 } |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
535 |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
536 static int lazymanifest_setitem( |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
537 lazymanifest *self, PyObject *key, PyObject *value) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
538 { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
539 char *path; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
540 Py_ssize_t plen; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
541 PyObject *pyhash; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
542 Py_ssize_t hlen; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
543 char *hash; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
544 PyObject *pyflags; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
545 char *flags; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
546 Py_ssize_t flen; |
44132
f0a4084f82d6
cext: change two more vars to Py_ssize_t in manifest.c
Kyle Lippincott <spectral@google.com>
parents:
44100
diff
changeset
|
547 Py_ssize_t dlen; |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
548 char *dest; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
549 int i; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
550 line new; |
30097
3bf4b762537e
manifest: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30079
diff
changeset
|
551 if (!PyBytes_Check(key)) { |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
552 PyErr_Format(PyExc_TypeError, |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
553 "setitem: manifest keys must be a string."); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
554 return -1; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
555 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
556 if (!value) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
557 return lazymanifest_delitem(self, key); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
558 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
559 if (!PyTuple_Check(value) || PyTuple_Size(value) != 2) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
560 PyErr_Format(PyExc_TypeError, |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
561 "Manifest values must be a tuple of (node, flags)."); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
562 return -1; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
563 } |
30097
3bf4b762537e
manifest: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30079
diff
changeset
|
564 if (PyBytes_AsStringAndSize(key, &path, &plen) == -1) { |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
565 return -1; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
566 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
567 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
568 pyhash = PyTuple_GetItem(value, 0); |
30097
3bf4b762537e
manifest: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30079
diff
changeset
|
569 if (!PyBytes_Check(pyhash)) { |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
570 PyErr_Format(PyExc_TypeError, |
45118
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
571 "node must be a 20 or 32 bytes string"); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
572 return -1; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
573 } |
30097
3bf4b762537e
manifest: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30079
diff
changeset
|
574 hlen = PyBytes_Size(pyhash); |
45118
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
575 if (hlen != 20 && hlen != 32) { |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
576 PyErr_Format(PyExc_TypeError, |
45118
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
577 "node must be a 20 or 32 bytes string"); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
578 return -1; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
579 } |
30097
3bf4b762537e
manifest: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30079
diff
changeset
|
580 hash = PyBytes_AsString(pyhash); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
581 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
582 pyflags = PyTuple_GetItem(value, 1); |
30097
3bf4b762537e
manifest: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30079
diff
changeset
|
583 if (!PyBytes_Check(pyflags) || PyBytes_Size(pyflags) > 1) { |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
584 PyErr_Format(PyExc_TypeError, |
45118
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
585 "flags must a 0 or 1 bytes string"); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
586 return -1; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
587 } |
30097
3bf4b762537e
manifest: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30079
diff
changeset
|
588 if (PyBytes_AsStringAndSize(pyflags, &flags, &flen) == -1) { |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
589 return -1; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
590 } |
45118
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
591 if (flen == 1) { |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
592 switch (*flags) { |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
593 case 'l': |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
594 case 't': |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
595 case 'x': |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
596 break; |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
597 default: |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
598 PyErr_Format(PyExc_TypeError, "invalid manifest flag"); |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
599 return -1; |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
600 } |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
601 } |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
602 /* one null byte and one newline */ |
45118
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
603 dlen = plen + hlen * 2 + 1 + flen + 1; |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
604 dest = malloc(dlen); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
605 if (!dest) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
606 PyErr_NoMemory(); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
607 return -1; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
608 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
609 memcpy(dest, path, plen + 1); |
45118
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
610 for (i = 0; i < hlen; i++) { |
24286
40528ad1b1e8
lazymanifest: don't depend on printf's 'hh' format to work
Martin von Zweigbergk <martinvonz@google.com>
parents:
24228
diff
changeset
|
611 /* Cast to unsigned, so it will not get sign-extended when promoted |
40528ad1b1e8
lazymanifest: don't depend on printf's 'hh' format to work
Martin von Zweigbergk <martinvonz@google.com>
parents:
24228
diff
changeset
|
612 * to int (as is done when passing to a variadic function) |
40528ad1b1e8
lazymanifest: don't depend on printf's 'hh' format to work
Martin von Zweigbergk <martinvonz@google.com>
parents:
24228
diff
changeset
|
613 */ |
40528ad1b1e8
lazymanifest: don't depend on printf's 'hh' format to work
Martin von Zweigbergk <martinvonz@google.com>
parents:
24228
diff
changeset
|
614 sprintf(dest + plen + 1 + (i * 2), "%02x", (unsigned char)hash[i]); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
615 } |
45118
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
616 memcpy(dest + plen + 2 * hlen + 1, flags, flen); |
d0ef8c1dddd4
manifest: tigher manifest parsing and flag use
Joerg Sonnenberger <joerg@bec.de>
parents:
44702
diff
changeset
|
617 dest[plen + 2 * hlen + 1 + flen] = '\n'; |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
618 new.start = dest; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
619 new.len = dlen; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
620 new.hash_suffix = '\0'; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
621 if (hlen > 20) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
622 new.hash_suffix = hash[20]; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
623 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
624 new.from_malloc = true; /* is `start` a pointer we allocated? */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
625 new.deleted = false; /* is this entry deleted? */ |
24228
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
626 if (internalsetitem(self, &new)) { |
542c891274b2
lazymanifest: use a binary search to do an insertion
Augie Fackler <augie@google.com>
parents:
24214
diff
changeset
|
627 return -1; |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
628 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
629 return 0; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
630 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
631 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
632 static PyMappingMethods lazymanifest_mapping_methods = { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
633 (lenfunc)lazymanifest_size, /* mp_length */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
634 (binaryfunc)lazymanifest_getitem, /* mp_subscript */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
635 (objobjargproc)lazymanifest_setitem, /* mp_ass_subscript */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
636 }; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
637 |
27608
d6aa1a8c8d7c
lazymanifest: add missing closing parenthesis in comment
Augie Fackler <raf@durin42.com>
parents:
27340
diff
changeset
|
638 /* sequence methods (important or __contains__ builds an iterator) */ |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
639 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
640 static int lazymanifest_contains(lazymanifest *self, PyObject *key) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
641 { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
642 line needle; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
643 line *hit; |
30097
3bf4b762537e
manifest: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30079
diff
changeset
|
644 if (!PyBytes_Check(key)) { |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
645 /* Our keys are always strings, so if the contains |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
646 * check is for a non-string, just return false. */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
647 return 0; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
648 } |
30097
3bf4b762537e
manifest: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30079
diff
changeset
|
649 needle.start = PyBytes_AsString(key); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
650 hit = bsearch(&needle, self->lines, self->numlines, sizeof(line), |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
651 &linecmp); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
652 if (!hit || hit->deleted) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
653 return 0; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
654 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
655 return 1; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
656 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
657 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
658 static PySequenceMethods lazymanifest_seq_meths = { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
659 (lenfunc)lazymanifest_size, /* sq_length */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
660 0, /* sq_concat */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
661 0, /* sq_repeat */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
662 0, /* sq_item */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
663 0, /* sq_slice */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
664 0, /* sq_ass_item */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
665 0, /* sq_ass_slice */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
666 (objobjproc)lazymanifest_contains, /* sq_contains */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
667 0, /* sq_inplace_concat */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
668 0, /* sq_inplace_repeat */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
669 }; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
670 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
671 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
672 /* Other methods (copy, diff, etc) */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
673 static PyTypeObject lazymanifestType; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
674 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
675 /* If the manifest has changes, build the new manifest text and reindex it. */ |
34440
7ed0750c71a1
cext: wrap before brace for functions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34438
diff
changeset
|
676 static int compact(lazymanifest *self) |
7ed0750c71a1
cext: wrap before brace for functions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34438
diff
changeset
|
677 { |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
678 int i; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
679 ssize_t need = 0; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
680 char *data; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
681 line *src, *dst; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
682 PyObject *pydata; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
683 if (!self->dirty) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
684 return 0; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
685 for (i = 0; i < self->numlines; i++) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
686 if (!self->lines[i].deleted) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
687 need += self->lines[i].len; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
688 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
689 } |
30097
3bf4b762537e
manifest: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30079
diff
changeset
|
690 pydata = PyBytes_FromStringAndSize(NULL, need); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
691 if (!pydata) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
692 return -1; |
30097
3bf4b762537e
manifest: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30079
diff
changeset
|
693 data = PyBytes_AsString(pydata); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
694 if (!data) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
695 return -1; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
696 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
697 src = self->lines; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
698 dst = self->lines; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
699 for (i = 0; i < self->numlines; i++, src++) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
700 char *tofree = NULL; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
701 if (src->from_malloc) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
702 tofree = src->start; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
703 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
704 if (!src->deleted) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
705 memcpy(data, src->start, src->len); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
706 *dst = *src; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
707 dst->start = data; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
708 dst->from_malloc = false; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
709 data += dst->len; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
710 dst++; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
711 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
712 free(tofree); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
713 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
714 Py_DECREF(self->pydata); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
715 self->pydata = pydata; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
716 self->numlines = self->livelines; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
717 self->dirty = false; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
718 return 0; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
719 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
720 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
721 static PyObject *lazymanifest_text(lazymanifest *self) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
722 { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
723 if (compact(self) != 0) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
724 PyErr_NoMemory(); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
725 return NULL; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
726 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
727 Py_INCREF(self->pydata); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
728 return self->pydata; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
729 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
730 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
731 static lazymanifest *lazymanifest_copy(lazymanifest *self) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
732 { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
733 lazymanifest *copy = NULL; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
734 if (compact(self) != 0) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
735 goto nomem; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
736 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
737 copy = PyObject_New(lazymanifest, &lazymanifestType); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
738 if (!copy) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
739 goto nomem; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
740 } |
38335
ae7f27867c2a
manifest: fix possible SEGV caused by uninitialized lazymanifest fields
Yuya Nishihara <yuya@tcha.org>
parents:
38302
diff
changeset
|
741 lazymanifest_init_early(copy); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
742 copy->numlines = self->numlines; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
743 copy->livelines = self->livelines; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
744 copy->dirty = false; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
745 copy->lines = malloc(self->maxlines *sizeof(line)); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
746 if (!copy->lines) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
747 goto nomem; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
748 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
749 memcpy(copy->lines, self->lines, self->numlines * sizeof(line)); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
750 copy->maxlines = self->maxlines; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
751 copy->pydata = self->pydata; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
752 Py_INCREF(copy->pydata); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
753 return copy; |
24975
89c2bf63a83b
lazymanifest: drop SP before some labels
Martin von Zweigbergk <martinvonz@google.com>
parents:
24974
diff
changeset
|
754 nomem: |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
755 PyErr_NoMemory(); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
756 Py_XDECREF(copy); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
757 return NULL; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
758 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
759 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
760 static lazymanifest *lazymanifest_filtercopy( |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
761 lazymanifest *self, PyObject *matchfn) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
762 { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
763 lazymanifest *copy = NULL; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
764 int i; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
765 if (!PyCallable_Check(matchfn)) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
766 PyErr_SetString(PyExc_TypeError, "matchfn must be callable"); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
767 return NULL; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
768 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
769 /* compact ourselves first to avoid double-frees later when we |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
770 * compact tmp so that it doesn't have random pointers to our |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
771 * underlying from_malloc-data (self->pydata is safe) */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
772 if (compact(self) != 0) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
773 goto nomem; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
774 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
775 copy = PyObject_New(lazymanifest, &lazymanifestType); |
27609
ca2d4080a02e
lazymanifest: check error return in filter
Augie Fackler <raf@durin42.com>
parents:
27608
diff
changeset
|
776 if (!copy) { |
ca2d4080a02e
lazymanifest: check error return in filter
Augie Fackler <raf@durin42.com>
parents:
27608
diff
changeset
|
777 goto nomem; |
ca2d4080a02e
lazymanifest: check error return in filter
Augie Fackler <raf@durin42.com>
parents:
27608
diff
changeset
|
778 } |
38335
ae7f27867c2a
manifest: fix possible SEGV caused by uninitialized lazymanifest fields
Yuya Nishihara <yuya@tcha.org>
parents:
38302
diff
changeset
|
779 lazymanifest_init_early(copy); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
780 copy->dirty = true; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
781 copy->lines = malloc(self->maxlines * sizeof(line)); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
782 if (!copy->lines) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
783 goto nomem; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
784 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
785 copy->maxlines = self->maxlines; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
786 copy->numlines = 0; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
787 copy->pydata = self->pydata; |
39423
ca77788c81bc
manifest: incref/decref copy->pydata to clarify 'copy' holds a reference
Yuya Nishihara <yuya@tcha.org>
parents:
38335
diff
changeset
|
788 Py_INCREF(copy->pydata); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
789 for (i = 0; i < self->numlines; i++) { |
27661
abc79f44f548
lazymanifest: check more return values in filtercopy
Augie Fackler <raf@durin42.com>
parents:
27609
diff
changeset
|
790 PyObject *arglist = NULL, *result = NULL; |
36619
1f8c3fadbb8e
py3: bulk-replace bytes format specifier passed to Py_BuildValue()
Yuya Nishihara <yuya@tcha.org>
parents:
35810
diff
changeset
|
791 arglist = Py_BuildValue(PY23("(s)", "(y)"), |
1f8c3fadbb8e
py3: bulk-replace bytes format specifier passed to Py_BuildValue()
Yuya Nishihara <yuya@tcha.org>
parents:
35810
diff
changeset
|
792 self->lines[i].start); |
27661
abc79f44f548
lazymanifest: check more return values in filtercopy
Augie Fackler <raf@durin42.com>
parents:
27609
diff
changeset
|
793 if (!arglist) { |
39424
094d1f42c484
manifest: fix leak on error return from lazymanifest_filtercopy()
Yuya Nishihara <yuya@tcha.org>
parents:
39423
diff
changeset
|
794 goto bail; |
27661
abc79f44f548
lazymanifest: check more return values in filtercopy
Augie Fackler <raf@durin42.com>
parents:
27609
diff
changeset
|
795 } |
abc79f44f548
lazymanifest: check more return values in filtercopy
Augie Fackler <raf@durin42.com>
parents:
27609
diff
changeset
|
796 result = PyObject_CallObject(matchfn, arglist); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
797 Py_DECREF(arglist); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
798 /* if the callback raised an exception, just let it |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
799 * through and give up */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
800 if (!result) { |
39424
094d1f42c484
manifest: fix leak on error return from lazymanifest_filtercopy()
Yuya Nishihara <yuya@tcha.org>
parents:
39423
diff
changeset
|
801 goto bail; |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
802 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
803 if (PyObject_IsTrue(result)) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
804 assert(!(self->lines[i].from_malloc)); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
805 copy->lines[copy->numlines++] = self->lines[i]; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
806 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
807 Py_DECREF(result); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
808 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
809 copy->livelines = copy->numlines; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
810 return copy; |
24975
89c2bf63a83b
lazymanifest: drop SP before some labels
Martin von Zweigbergk <martinvonz@google.com>
parents:
24974
diff
changeset
|
811 nomem: |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
812 PyErr_NoMemory(); |
39424
094d1f42c484
manifest: fix leak on error return from lazymanifest_filtercopy()
Yuya Nishihara <yuya@tcha.org>
parents:
39423
diff
changeset
|
813 bail: |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
814 Py_XDECREF(copy); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
815 return NULL; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
816 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
817 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
818 static PyObject *lazymanifest_diff(lazymanifest *self, PyObject *args) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
819 { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
820 lazymanifest *other; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
821 PyObject *pyclean = NULL; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
822 bool listclean; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
823 PyObject *emptyTup = NULL, *ret = NULL; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
824 PyObject *es; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
825 int sneedle = 0, oneedle = 0; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
826 if (!PyArg_ParseTuple(args, "O!|O", &lazymanifestType, &other, &pyclean)) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
827 return NULL; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
828 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
829 listclean = (!pyclean) ? false : PyObject_IsTrue(pyclean); |
30097
3bf4b762537e
manifest: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30079
diff
changeset
|
830 es = PyBytes_FromString(""); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
831 if (!es) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
832 goto nomem; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
833 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
834 emptyTup = PyTuple_Pack(2, Py_None, es); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
835 Py_DECREF(es); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
836 if (!emptyTup) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
837 goto nomem; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
838 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
839 ret = PyDict_New(); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
840 if (!ret) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
841 goto nomem; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
842 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
843 while (sneedle != self->numlines || oneedle != other->numlines) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
844 line *left = self->lines + sneedle; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
845 line *right = other->lines + oneedle; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
846 int result; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
847 PyObject *key; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
848 PyObject *outer; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
849 /* If we're looking at a deleted entry and it's not |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
850 * the end of the manifest, just skip it. */ |
35810
113a30b87716
lazymanifest: avoid reading uninitialized memory
Jun Wu <quark@fb.com>
parents:
34861
diff
changeset
|
851 if (sneedle < self->numlines && left->deleted) { |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
852 sneedle++; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
853 continue; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
854 } |
35810
113a30b87716
lazymanifest: avoid reading uninitialized memory
Jun Wu <quark@fb.com>
parents:
34861
diff
changeset
|
855 if (oneedle < other->numlines && right->deleted) { |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
856 oneedle++; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
857 continue; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
858 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
859 /* if we're at the end of either manifest, then we |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
860 * know the remaining items are adds so we can skip |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
861 * the strcmp. */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
862 if (sneedle == self->numlines) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
863 result = 1; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
864 } else if (oneedle == other->numlines) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
865 result = -1; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
866 } else { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
867 result = linecmp(left, right); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
868 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
869 key = result <= 0 ? |
30097
3bf4b762537e
manifest: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30079
diff
changeset
|
870 PyBytes_FromString(left->start) : |
3bf4b762537e
manifest: convert PyString* to PyBytes*
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30079
diff
changeset
|
871 PyBytes_FromString(right->start); |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
872 if (!key) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
873 goto nomem; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
874 if (result < 0) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
875 PyObject *l = hashflags(left); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
876 if (!l) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
877 goto nomem; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
878 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
879 outer = PyTuple_Pack(2, l, emptyTup); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
880 Py_DECREF(l); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
881 if (!outer) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
882 goto nomem; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
883 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
884 PyDict_SetItem(ret, key, outer); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
885 Py_DECREF(outer); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
886 sneedle++; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
887 } else if (result > 0) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
888 PyObject *r = hashflags(right); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
889 if (!r) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
890 goto nomem; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
891 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
892 outer = PyTuple_Pack(2, emptyTup, r); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
893 Py_DECREF(r); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
894 if (!outer) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
895 goto nomem; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
896 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
897 PyDict_SetItem(ret, key, outer); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
898 Py_DECREF(outer); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
899 oneedle++; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
900 } else { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
901 /* file exists in both manifests */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
902 if (left->len != right->len |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
903 || memcmp(left->start, right->start, left->len) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
904 || left->hash_suffix != right->hash_suffix) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
905 PyObject *l = hashflags(left); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
906 PyObject *r; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
907 if (!l) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
908 goto nomem; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
909 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
910 r = hashflags(right); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
911 if (!r) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
912 Py_DECREF(l); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
913 goto nomem; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
914 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
915 outer = PyTuple_Pack(2, l, r); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
916 Py_DECREF(l); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
917 Py_DECREF(r); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
918 if (!outer) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
919 goto nomem; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
920 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
921 PyDict_SetItem(ret, key, outer); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
922 Py_DECREF(outer); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
923 } else if (listclean) { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
924 PyDict_SetItem(ret, key, Py_None); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
925 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
926 sneedle++; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
927 oneedle++; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
928 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
929 Py_DECREF(key); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
930 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
931 Py_DECREF(emptyTup); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
932 return ret; |
24975
89c2bf63a83b
lazymanifest: drop SP before some labels
Martin von Zweigbergk <martinvonz@google.com>
parents:
24974
diff
changeset
|
933 nomem: |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
934 PyErr_NoMemory(); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
935 Py_XDECREF(ret); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
936 Py_XDECREF(emptyTup); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
937 return NULL; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
938 } |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
939 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
940 static PyMethodDef lazymanifest_methods[] = { |
24295
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
941 {"iterkeys", (PyCFunction)lazymanifest_getkeysiter, METH_NOARGS, |
2b7ab29627fd
lazymanifest: add iterkeys() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
24294
diff
changeset
|
942 "Iterate over file names in this lazymanifest."}, |
24298
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24295
diff
changeset
|
943 {"iterentries", (PyCFunction)lazymanifest_getentriesiter, METH_NOARGS, |
29254
c5912a0b156c
lazymanifest: fix typo s/typles/tuples/
Javi Merino <merino.jav@gmail.com>
parents:
27661
diff
changeset
|
944 "Iterate over (path, nodeid, flags) tuples in this lazymanifest."}, |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
945 {"copy", (PyCFunction)lazymanifest_copy, METH_NOARGS, |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
946 "Make a copy of this lazymanifest."}, |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
947 {"filtercopy", (PyCFunction)lazymanifest_filtercopy, METH_O, |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
948 "Make a copy of this manifest filtered by matchfn."}, |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
949 {"diff", (PyCFunction)lazymanifest_diff, METH_VARARGS, |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
950 "Compare this lazymanifest to another one."}, |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
951 {"text", (PyCFunction)lazymanifest_text, METH_NOARGS, |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
952 "Encode this manifest to text."}, |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
953 {NULL}, |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
954 }; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
955 |
30079
84debea79903
manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29254
diff
changeset
|
956 #ifdef IS_PY3K |
84debea79903
manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29254
diff
changeset
|
957 #define LAZYMANIFEST_TPFLAGS Py_TPFLAGS_DEFAULT |
84debea79903
manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29254
diff
changeset
|
958 #else |
84debea79903
manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29254
diff
changeset
|
959 #define LAZYMANIFEST_TPFLAGS Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_SEQUENCE_IN |
84debea79903
manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29254
diff
changeset
|
960 #endif |
84debea79903
manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29254
diff
changeset
|
961 |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
962 static PyTypeObject lazymanifestType = { |
34861
6ece4a85c350
cext: add /* header */ comment to all PyVarObject_HEAD_INIT() calls
Augie Fackler <augie@google.com>
parents:
34440
diff
changeset
|
963 PyVarObject_HEAD_INIT(NULL, 0) /* header */ |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
964 "parsers.lazymanifest", /* tp_name */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
965 sizeof(lazymanifest), /* tp_basicsize */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
966 0, /* tp_itemsize */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
967 (destructor)lazymanifest_dealloc, /* tp_dealloc */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
968 0, /* tp_print */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
969 0, /* tp_getattr */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
970 0, /* tp_setattr */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
971 0, /* tp_compare */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
972 0, /* tp_repr */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
973 0, /* tp_as_number */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
974 &lazymanifest_seq_meths, /* tp_as_sequence */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
975 &lazymanifest_mapping_methods, /* tp_as_mapping */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
976 0, /* tp_hash */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
977 0, /* tp_call */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
978 0, /* tp_str */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
979 0, /* tp_getattro */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
980 0, /* tp_setattro */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
981 0, /* tp_as_buffer */ |
30079
84debea79903
manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29254
diff
changeset
|
982 LAZYMANIFEST_TPFLAGS, /* tp_flags */ |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
983 "TODO(augie)", /* tp_doc */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
984 0, /* tp_traverse */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
985 0, /* tp_clear */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
986 0, /* tp_richcompare */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
987 0, /* tp_weaklistoffset */ |
24298
49cd847fd69a
lazymanifest: make __iter__ generate filenames, not 3-tuples
Martin von Zweigbergk <martinvonz@google.com>
parents:
24295
diff
changeset
|
988 (getiterfunc)lazymanifest_getkeysiter, /* tp_iter */ |
24214
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
989 0, /* tp_iternext */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
990 lazymanifest_methods, /* tp_methods */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
991 0, /* tp_members */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
992 0, /* tp_getset */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
993 0, /* tp_base */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
994 0, /* tp_dict */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
995 0, /* tp_descr_get */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
996 0, /* tp_descr_set */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
997 0, /* tp_dictoffset */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
998 (initproc)lazymanifest_init, /* tp_init */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
999 0, /* tp_alloc */ |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1000 }; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1001 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1002 void manifest_module_init(PyObject * mod) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1003 { |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1004 lazymanifestType.tp_new = PyType_GenericNew; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1005 if (PyType_Ready(&lazymanifestType) < 0) |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1006 return; |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1007 Py_INCREF(&lazymanifestType); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1008 |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1009 PyModule_AddObject(mod, "lazymanifest", |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1010 (PyObject *)&lazymanifestType); |
a5f1bccd2996
manifest.c: new extension code to lazily parse manifests
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1011 } |