Mercurial > hg
annotate mercurial/dirs.c @ 29961:774a15b129e8
manifest: move manifest.add onto manifestrevlog
This moves add and _addtree onto manifestrevlog. manifestrevlog is responsible
for all serialization decisions, so therefore the add function should live on
it. This will allow us to call add() from manifestlog, which lets us further
break our dependency on manifest.
author | Durham Goode <durham@fb.com> |
---|---|
date | Tue, 20 Sep 2016 12:24:01 -0700 |
parents | fe3a72a3e7ca |
children | 63e1dca2d6a4 |
rev | line source |
---|---|
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
1 /* |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
2 dirs.c - dynamic directory diddling for dirstates |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
3 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
4 Copyright 2013 Facebook |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
5 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
6 This software may be used and distributed according to the terms of |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
7 the GNU General Public License, incorporated herein by reference. |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
8 */ |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
9 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
10 #define PY_SSIZE_T_CLEAN |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
11 #include <Python.h> |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
12 #include "util.h" |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
13 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
14 /* |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
15 * This is a multiset of directory names, built from the files that |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
16 * appear in a dirstate or manifest. |
18901
66d3aebe2d95
dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
17 * |
66d3aebe2d95
dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
18 * A few implementation notes: |
66d3aebe2d95
dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
19 * |
66d3aebe2d95
dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
20 * We modify Python integers for refcounting, but those integers are |
66d3aebe2d95
dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
21 * never visible to Python code. |
18902
8c0a7eeda06d
dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18901
diff
changeset
|
22 * |
8c0a7eeda06d
dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18901
diff
changeset
|
23 * We mutate strings in-place, but leave them immutable once they can |
8c0a7eeda06d
dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18901
diff
changeset
|
24 * be seen by Python code. |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
25 */ |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
26 typedef struct { |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
27 PyObject_HEAD |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
28 PyObject *dict; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
29 } dirsObject; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
30 |
25093
fe3a72a3e7ca
dirs.c: pass C string, not Python string, to _finddir()
Martin von Zweigbergk <martinvonz@google.com>
parents:
25092
diff
changeset
|
31 static inline Py_ssize_t _finddir(const char *path, Py_ssize_t pos) |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
32 { |
25015
b3a68fb8b859
dirs: back out forward-searching in finddirs()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24651
diff
changeset
|
33 while (pos != -1) { |
25093
fe3a72a3e7ca
dirs.c: pass C string, not Python string, to _finddir()
Martin von Zweigbergk <martinvonz@google.com>
parents:
25092
diff
changeset
|
34 if (path[pos] == '/') |
25015
b3a68fb8b859
dirs: back out forward-searching in finddirs()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24651
diff
changeset
|
35 break; |
b3a68fb8b859
dirs: back out forward-searching in finddirs()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24651
diff
changeset
|
36 pos -= 1; |
b3a68fb8b859
dirs: back out forward-searching in finddirs()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24651
diff
changeset
|
37 } |
b3a68fb8b859
dirs: back out forward-searching in finddirs()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24651
diff
changeset
|
38 |
b3a68fb8b859
dirs: back out forward-searching in finddirs()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24651
diff
changeset
|
39 return pos; |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
40 } |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
41 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
42 static int _addpath(PyObject *dirs, PyObject *path) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
43 { |
25015
b3a68fb8b859
dirs: back out forward-searching in finddirs()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24651
diff
changeset
|
44 const char *cpath = PyString_AS_STRING(path); |
b3a68fb8b859
dirs: back out forward-searching in finddirs()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24651
diff
changeset
|
45 Py_ssize_t pos = PyString_GET_SIZE(path); |
18901
66d3aebe2d95
dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
46 PyObject *key = NULL; |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
47 int ret = -1; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
48 |
25093
fe3a72a3e7ca
dirs.c: pass C string, not Python string, to _finddir()
Martin von Zweigbergk <martinvonz@google.com>
parents:
25092
diff
changeset
|
49 while ((pos = _finddir(cpath, pos - 1)) != -1) { |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
50 PyObject *val; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
51 |
18902
8c0a7eeda06d
dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18901
diff
changeset
|
52 /* It's likely that every prefix already has an entry |
8c0a7eeda06d
dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18901
diff
changeset
|
53 in our dict. Try to avoid allocating and |
8c0a7eeda06d
dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18901
diff
changeset
|
54 deallocating a string for each prefix we check. */ |
8c0a7eeda06d
dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18901
diff
changeset
|
55 if (key != NULL) |
8c0a7eeda06d
dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18901
diff
changeset
|
56 ((PyStringObject *)key)->ob_shash = -1; |
25015
b3a68fb8b859
dirs: back out forward-searching in finddirs()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24651
diff
changeset
|
57 else { |
b3a68fb8b859
dirs: back out forward-searching in finddirs()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24651
diff
changeset
|
58 /* Force Python to not reuse a small shared string. */ |
b3a68fb8b859
dirs: back out forward-searching in finddirs()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24651
diff
changeset
|
59 key = PyString_FromStringAndSize(cpath, |
b3a68fb8b859
dirs: back out forward-searching in finddirs()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24651
diff
changeset
|
60 pos < 2 ? 2 : pos); |
18902
8c0a7eeda06d
dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18901
diff
changeset
|
61 if (key == NULL) |
8c0a7eeda06d
dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18901
diff
changeset
|
62 goto bail; |
8c0a7eeda06d
dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18901
diff
changeset
|
63 } |
8c0a7eeda06d
dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18901
diff
changeset
|
64 PyString_GET_SIZE(key) = pos; |
8c0a7eeda06d
dirs: use mutable strings internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18901
diff
changeset
|
65 PyString_AS_STRING(key)[pos] = '\0'; |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
66 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
67 val = PyDict_GetItem(dirs, key); |
18901
66d3aebe2d95
dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
68 if (val != NULL) { |
66d3aebe2d95
dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
69 PyInt_AS_LONG(val) += 1; |
25016
42e89b87ca79
dirs: speed up by storing number of direct children per dir
Martin von Zweigbergk <martinvonz@google.com>
parents:
25015
diff
changeset
|
70 break; |
18901
66d3aebe2d95
dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
71 } |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
72 |
18901
66d3aebe2d95
dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
73 /* Force Python to not reuse a small shared int. */ |
66d3aebe2d95
dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
74 val = PyInt_FromLong(0x1eadbeef); |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
75 |
18901
66d3aebe2d95
dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
76 if (val == NULL) |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
77 goto bail; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
78 |
18901
66d3aebe2d95
dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
79 PyInt_AS_LONG(val) = 1; |
66d3aebe2d95
dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
80 ret = PyDict_SetItem(dirs, key, val); |
66d3aebe2d95
dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
81 Py_DECREF(val); |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
82 if (ret == -1) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
83 goto bail; |
24651
67241ee427cf
dirs._addpath: reinstate use of Py_CLEAR
Siddharth Agarwal <sid0@fb.com>
parents:
24624
diff
changeset
|
84 Py_CLEAR(key); |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
85 } |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
86 ret = 0; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
87 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
88 bail: |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
89 Py_XDECREF(key); |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
90 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
91 return ret; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
92 } |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
93 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
94 static int _delpath(PyObject *dirs, PyObject *path) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
95 { |
25092
f41539418b41
dirs.c: extract 'cpath' variable in _delpath() to match _addpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
25016
diff
changeset
|
96 char *cpath = PyString_AS_STRING(path); |
25015
b3a68fb8b859
dirs: back out forward-searching in finddirs()
Martin von Zweigbergk <martinvonz@google.com>
parents:
24651
diff
changeset
|
97 Py_ssize_t pos = PyString_GET_SIZE(path); |
18901
66d3aebe2d95
dirs: use mutable integers internally
Bryan O'Sullivan <bryano@fb.com>
parents:
18900
diff
changeset
|
98 PyObject *key = NULL; |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
99 int ret = -1; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
100 |
25093
fe3a72a3e7ca
dirs.c: pass C string, not Python string, to _finddir()
Martin von Zweigbergk <martinvonz@google.com>
parents:
25092
diff
changeset
|
101 while ((pos = _finddir(cpath, pos - 1)) != -1) { |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
102 PyObject *val; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
103 |
25092
f41539418b41
dirs.c: extract 'cpath' variable in _delpath() to match _addpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
25016
diff
changeset
|
104 key = PyString_FromStringAndSize(cpath, pos); |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
105 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
106 if (key == NULL) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
107 goto bail; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
108 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
109 val = PyDict_GetItem(dirs, key); |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
110 if (val == NULL) { |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
111 PyErr_SetString(PyExc_ValueError, |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
112 "expected a value, found none"); |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
113 goto bail; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
114 } |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
115 |
25016
42e89b87ca79
dirs: speed up by storing number of direct children per dir
Martin von Zweigbergk <martinvonz@google.com>
parents:
25015
diff
changeset
|
116 if (--PyInt_AS_LONG(val) <= 0) { |
42e89b87ca79
dirs: speed up by storing number of direct children per dir
Martin von Zweigbergk <martinvonz@google.com>
parents:
25015
diff
changeset
|
117 if (PyDict_DelItem(dirs, key) == -1) |
42e89b87ca79
dirs: speed up by storing number of direct children per dir
Martin von Zweigbergk <martinvonz@google.com>
parents:
25015
diff
changeset
|
118 goto bail; |
42e89b87ca79
dirs: speed up by storing number of direct children per dir
Martin von Zweigbergk <martinvonz@google.com>
parents:
25015
diff
changeset
|
119 } else |
42e89b87ca79
dirs: speed up by storing number of direct children per dir
Martin von Zweigbergk <martinvonz@google.com>
parents:
25015
diff
changeset
|
120 break; |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
121 Py_CLEAR(key); |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
122 } |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
123 ret = 0; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
124 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
125 bail: |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
126 Py_XDECREF(key); |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
127 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
128 return ret; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
129 } |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
130 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
131 static int dirs_fromdict(PyObject *dirs, PyObject *source, char skipchar) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
132 { |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
133 PyObject *key, *value; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
134 Py_ssize_t pos = 0; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
135 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
136 while (PyDict_Next(source, &pos, &key, &value)) { |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
137 if (!PyString_Check(key)) { |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
138 PyErr_SetString(PyExc_TypeError, "expected string key"); |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
139 return -1; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
140 } |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
141 if (skipchar) { |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
18902
diff
changeset
|
142 if (!dirstate_tuple_check(value)) { |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
143 PyErr_SetString(PyExc_TypeError, |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
18902
diff
changeset
|
144 "expected a dirstate tuple"); |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
145 return -1; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
146 } |
21809
e250b8300e6e
parsers: inline fields of dirstate values in C version
Siddharth Agarwal <sid0@fb.com>
parents:
18902
diff
changeset
|
147 if (((dirstateTupleObject *)value)->state == skipchar) |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
148 continue; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
149 } |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
150 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
151 if (_addpath(dirs, key) == -1) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
152 return -1; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
153 } |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
154 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
155 return 0; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
156 } |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
157 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
158 static int dirs_fromiter(PyObject *dirs, PyObject *source) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
159 { |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
160 PyObject *iter, *item = NULL; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
161 int ret; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
162 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
163 iter = PyObject_GetIter(source); |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
164 if (iter == NULL) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
165 return -1; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
166 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
167 while ((item = PyIter_Next(iter)) != NULL) { |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
168 if (!PyString_Check(item)) { |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
169 PyErr_SetString(PyExc_TypeError, "expected string"); |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
170 break; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
171 } |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
172 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
173 if (_addpath(dirs, item) == -1) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
174 break; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
175 Py_CLEAR(item); |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
176 } |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
177 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
178 ret = PyErr_Occurred() ? -1 : 0; |
23960
bca4b6f126f2
dirs: fix leak of iterator in dirs_fromiter
Augie Fackler <augie@google.com>
parents:
21809
diff
changeset
|
179 Py_DECREF(iter); |
18900
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
180 Py_XDECREF(item); |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
181 return ret; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
182 } |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
183 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
184 /* |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
185 * Calculate a refcounted set of directory names for the files in a |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
186 * dirstate. |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
187 */ |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
188 static int dirs_init(dirsObject *self, PyObject *args) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
189 { |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
190 PyObject *dirs = NULL, *source = NULL; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
191 char skipchar = 0; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
192 int ret = -1; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
193 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
194 self->dict = NULL; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
195 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
196 if (!PyArg_ParseTuple(args, "|Oc:__init__", &source, &skipchar)) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
197 return -1; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
198 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
199 dirs = PyDict_New(); |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
200 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
201 if (dirs == NULL) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
202 return -1; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
203 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
204 if (source == NULL) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
205 ret = 0; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
206 else if (PyDict_Check(source)) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
207 ret = dirs_fromdict(dirs, source, skipchar); |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
208 else if (skipchar) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
209 PyErr_SetString(PyExc_ValueError, |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
210 "skip character is only supported " |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
211 "with a dict source"); |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
212 else |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
213 ret = dirs_fromiter(dirs, source); |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
214 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
215 if (ret == -1) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
216 Py_XDECREF(dirs); |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
217 else |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
218 self->dict = dirs; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
219 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
220 return ret; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
221 } |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
222 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
223 PyObject *dirs_addpath(dirsObject *self, PyObject *args) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
224 { |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
225 PyObject *path; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
226 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
227 if (!PyArg_ParseTuple(args, "O!:addpath", &PyString_Type, &path)) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
228 return NULL; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
229 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
230 if (_addpath(self->dict, path) == -1) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
231 return NULL; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
232 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
233 Py_RETURN_NONE; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
234 } |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
235 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
236 static PyObject *dirs_delpath(dirsObject *self, PyObject *args) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
237 { |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
238 PyObject *path; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
239 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
240 if (!PyArg_ParseTuple(args, "O!:delpath", &PyString_Type, &path)) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
241 return NULL; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
242 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
243 if (_delpath(self->dict, path) == -1) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
244 return NULL; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
245 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
246 Py_RETURN_NONE; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
247 } |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
248 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
249 static int dirs_contains(dirsObject *self, PyObject *value) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
250 { |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
251 return PyString_Check(value) ? PyDict_Contains(self->dict, value) : 0; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
252 } |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
253 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
254 static void dirs_dealloc(dirsObject *self) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
255 { |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
256 Py_XDECREF(self->dict); |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
257 PyObject_Del(self); |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
258 } |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
259 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
260 static PyObject *dirs_iter(dirsObject *self) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
261 { |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
262 return PyObject_GetIter(self->dict); |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
263 } |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
264 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
265 static PySequenceMethods dirs_sequence_methods; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
266 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
267 static PyMethodDef dirs_methods[] = { |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
268 {"addpath", (PyCFunction)dirs_addpath, METH_VARARGS, "add a path"}, |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
269 {"delpath", (PyCFunction)dirs_delpath, METH_VARARGS, "remove a path"}, |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
270 {NULL} /* Sentinel */ |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
271 }; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
272 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
273 static PyTypeObject dirsType = { PyObject_HEAD_INIT(NULL) }; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
274 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
275 void dirs_module_init(PyObject *mod) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
276 { |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
277 dirs_sequence_methods.sq_contains = (objobjproc)dirs_contains; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
278 dirsType.tp_name = "parsers.dirs"; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
279 dirsType.tp_new = PyType_GenericNew; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
280 dirsType.tp_basicsize = sizeof(dirsObject); |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
281 dirsType.tp_dealloc = (destructor)dirs_dealloc; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
282 dirsType.tp_as_sequence = &dirs_sequence_methods; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
283 dirsType.tp_flags = Py_TPFLAGS_DEFAULT; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
284 dirsType.tp_doc = "dirs"; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
285 dirsType.tp_iter = (getiterfunc)dirs_iter; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
286 dirsType.tp_methods = dirs_methods; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
287 dirsType.tp_init = (initproc)dirs_init; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
288 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
289 if (PyType_Ready(&dirsType) < 0) |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
290 return; |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
291 Py_INCREF(&dirsType); |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
292 |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
293 PyModule_AddObject(mod, "dirs", (PyObject *)&dirsType); |
02ee846b246a
scmutil: rewrite dirs in C, use if available
Bryan O'Sullivan <bryano@fb.com>
parents:
diff
changeset
|
294 } |