Show More
@@ -41,8 +41,8 b' static inline Py_ssize_t _finddir(const ' | |||||
41 |
|
41 | |||
42 | static int _addpath(PyObject *dirs, PyObject *path) |
|
42 | static int _addpath(PyObject *dirs, PyObject *path) | |
43 | { |
|
43 | { | |
44 |
const char *cpath = Py |
|
44 | const char *cpath = PyBytes_AS_STRING(path); | |
45 |
Py_ssize_t pos = Py |
|
45 | Py_ssize_t pos = PyBytes_GET_SIZE(path); | |
46 | PyObject *key = NULL; |
|
46 | PyObject *key = NULL; | |
47 | int ret = -1; |
|
47 | int ret = -1; | |
48 |
|
48 | |||
@@ -53,16 +53,16 b' static int _addpath(PyObject *dirs, PyOb' | |||||
53 | in our dict. Try to avoid allocating and |
|
53 | in our dict. Try to avoid allocating and | |
54 | deallocating a string for each prefix we check. */ |
|
54 | deallocating a string for each prefix we check. */ | |
55 | if (key != NULL) |
|
55 | if (key != NULL) | |
56 |
((Py |
|
56 | ((PyBytesObject *)key)->ob_shash = -1; | |
57 | else { |
|
57 | else { | |
58 | /* Force Python to not reuse a small shared string. */ |
|
58 | /* Force Python to not reuse a small shared string. */ | |
59 |
key = Py |
|
59 | key = PyBytes_FromStringAndSize(cpath, | |
60 | pos < 2 ? 2 : pos); |
|
60 | pos < 2 ? 2 : pos); | |
61 | if (key == NULL) |
|
61 | if (key == NULL) | |
62 | goto bail; |
|
62 | goto bail; | |
63 | } |
|
63 | } | |
64 | Py_SIZE(key) = pos; |
|
64 | Py_SIZE(key) = pos; | |
65 |
((Py |
|
65 | ((PyBytesObject *)key)->ob_sval[pos] = '\0'; | |
66 |
|
66 | |||
67 | val = PyDict_GetItem(dirs, key); |
|
67 | val = PyDict_GetItem(dirs, key); | |
68 | if (val != NULL) { |
|
68 | if (val != NULL) { | |
@@ -93,15 +93,15 b' bail:' | |||||
93 |
|
93 | |||
94 | static int _delpath(PyObject *dirs, PyObject *path) |
|
94 | static int _delpath(PyObject *dirs, PyObject *path) | |
95 | { |
|
95 | { | |
96 |
char *cpath = Py |
|
96 | char *cpath = PyBytes_AS_STRING(path); | |
97 |
Py_ssize_t pos = Py |
|
97 | Py_ssize_t pos = PyBytes_GET_SIZE(path); | |
98 | PyObject *key = NULL; |
|
98 | PyObject *key = NULL; | |
99 | int ret = -1; |
|
99 | int ret = -1; | |
100 |
|
100 | |||
101 | while ((pos = _finddir(cpath, pos - 1)) != -1) { |
|
101 | while ((pos = _finddir(cpath, pos - 1)) != -1) { | |
102 | PyObject *val; |
|
102 | PyObject *val; | |
103 |
|
103 | |||
104 |
key = Py |
|
104 | key = PyBytes_FromStringAndSize(cpath, pos); | |
105 |
|
105 | |||
106 | if (key == NULL) |
|
106 | if (key == NULL) | |
107 | goto bail; |
|
107 | goto bail; | |
@@ -134,7 +134,7 b' static int dirs_fromdict(PyObject *dirs,' | |||||
134 | Py_ssize_t pos = 0; |
|
134 | Py_ssize_t pos = 0; | |
135 |
|
135 | |||
136 | while (PyDict_Next(source, &pos, &key, &value)) { |
|
136 | while (PyDict_Next(source, &pos, &key, &value)) { | |
137 |
if (!Py |
|
137 | if (!PyBytes_Check(key)) { | |
138 | PyErr_SetString(PyExc_TypeError, "expected string key"); |
|
138 | PyErr_SetString(PyExc_TypeError, "expected string key"); | |
139 | return -1; |
|
139 | return -1; | |
140 | } |
|
140 | } | |
@@ -165,7 +165,7 b' static int dirs_fromiter(PyObject *dirs,' | |||||
165 | return -1; |
|
165 | return -1; | |
166 |
|
166 | |||
167 | while ((item = PyIter_Next(iter)) != NULL) { |
|
167 | while ((item = PyIter_Next(iter)) != NULL) { | |
168 |
if (!Py |
|
168 | if (!PyBytes_Check(item)) { | |
169 | PyErr_SetString(PyExc_TypeError, "expected string"); |
|
169 | PyErr_SetString(PyExc_TypeError, "expected string"); | |
170 | break; |
|
170 | break; | |
171 | } |
|
171 | } | |
@@ -224,7 +224,7 b' PyObject *dirs_addpath(dirsObject *self,' | |||||
224 | { |
|
224 | { | |
225 | PyObject *path; |
|
225 | PyObject *path; | |
226 |
|
226 | |||
227 |
if (!PyArg_ParseTuple(args, "O!:addpath", &Py |
|
227 | if (!PyArg_ParseTuple(args, "O!:addpath", &PyBytes_Type, &path)) | |
228 | return NULL; |
|
228 | return NULL; | |
229 |
|
229 | |||
230 | if (_addpath(self->dict, path) == -1) |
|
230 | if (_addpath(self->dict, path) == -1) | |
@@ -237,7 +237,7 b' static PyObject *dirs_delpath(dirsObject' | |||||
237 | { |
|
237 | { | |
238 | PyObject *path; |
|
238 | PyObject *path; | |
239 |
|
239 | |||
240 |
if (!PyArg_ParseTuple(args, "O!:delpath", &Py |
|
240 | if (!PyArg_ParseTuple(args, "O!:delpath", &PyBytes_Type, &path)) | |
241 | return NULL; |
|
241 | return NULL; | |
242 |
|
242 | |||
243 | if (_delpath(self->dict, path) == -1) |
|
243 | if (_delpath(self->dict, path) == -1) | |
@@ -248,7 +248,7 b' static PyObject *dirs_delpath(dirsObject' | |||||
248 |
|
248 | |||
249 | static int dirs_contains(dirsObject *self, PyObject *value) |
|
249 | static int dirs_contains(dirsObject *self, PyObject *value) | |
250 | { |
|
250 | { | |
251 |
return Py |
|
251 | return PyBytes_Check(value) ? PyDict_Contains(self->dict, value) : 0; | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | static void dirs_dealloc(dirsObject *self) |
|
254 | static void dirs_dealloc(dirsObject *self) |
General Comments 0
You need to be logged in to leave comments.
Login now