##// END OF EJS Templates
parsers.c: Added support for py3k....
Renato Cunha -
r11361:3de3d670 default
parent child Browse files
Show More
@@ -11,6 +11,8 b''
11 11 #include <ctype.h>
12 12 #include <string.h>
13 13
14 #include "util.h"
15
14 16 static int hexdigit(char c)
15 17 {
16 18 if (c >= '0' && c <= '9')
@@ -33,11 +35,13 b' static PyObject *unhexlify(const char *s'
33 35 const char *c;
34 36 char *d;
35 37
36 ret = PyString_FromStringAndSize(NULL, len / 2);
38 ret = PyBytes_FromStringAndSize(NULL, len / 2);
39
37 40 if (!ret)
38 41 return NULL;
39 42
40 d = PyString_AS_STRING(ret);
43 d = PyBytes_AsString(ret);
44
41 45 for (c = str; c < str + len;) {
42 46 int hi = hexdigit(*c++);
43 47 int lo = hexdigit(*c++);
@@ -81,7 +85,8 b' static PyObject *parse_manifest(PyObject'
81 85 goto quit;
82 86 }
83 87
84 file = PyString_FromStringAndSize(start, zero - start);
88 file = PyBytes_FromStringAndSize(start, zero - start);
89
85 90 if (!file)
86 91 goto bail;
87 92
@@ -92,7 +97,7 b' static PyObject *parse_manifest(PyObject'
92 97 goto bail;
93 98
94 99 if (nlen > 40) {
95 flags = PyString_FromStringAndSize(zero + 41,
100 flags = PyBytes_FromStringAndSize(zero + 41,
96 101 nlen - 40);
97 102 if (!flags)
98 103 goto bail;
@@ -206,8 +211,8 b' static PyObject *parse_dirstate(PyObject'
206 211
207 212 cpos = memchr(cur, 0, flen);
208 213 if (cpos) {
209 fname = PyString_FromStringAndSize(cur, cpos - cur);
210 cname = PyString_FromStringAndSize(cpos + 1,
214 fname = PyBytes_FromStringAndSize(cur, cpos - cur);
215 cname = PyBytes_FromStringAndSize(cpos + 1,
211 216 flen - (cpos - cur) - 1);
212 217 if (!fname || !cname ||
213 218 PyDict_SetItem(cmap, fname, cname) == -1 ||
@@ -215,7 +220,7 b' static PyObject *parse_dirstate(PyObject'
215 220 goto quit;
216 221 Py_DECREF(cname);
217 222 } else {
218 fname = PyString_FromStringAndSize(cur, flen);
223 fname = PyBytes_FromStringAndSize(cur, flen);
219 224 if (!fname ||
220 225 PyDict_SetItem(dmap, fname, entry) == -1)
221 226 goto quit;
@@ -248,8 +253,9 b' static PyObject * _build_idx_entry(PyObj'
248 253 int err;
249 254 PyObject *entry, *node_id, *n_obj;
250 255
251 node_id = PyString_FromStringAndSize(c_node_id, 20);
256 node_id = PyBytes_FromStringAndSize(c_node_id, 20);
252 257 n_obj = PyInt_FromLong(n);
258
253 259 if (!node_id || !n_obj)
254 260 err = -1;
255 261 else
@@ -427,7 +433,23 b' static PyMethodDef methods[] = {'
427 433 {NULL, NULL}
428 434 };
429 435
436 #ifdef IS_PY3K
437 static struct PyModuleDef parsers_module = {
438 PyModuleDef_HEAD_INIT,
439 "parsers",
440 parsers_doc,
441 -1,
442 methods
443 };
444
445 PyMODINIT_FUNC PyInit_parsers(void)
446 {
447 return PyModule_Create(&parsers_module);
448 }
449 #else
430 450 PyMODINIT_FUNC initparsers(void)
431 451 {
432 452 Py_InitModule3("parsers", methods, parsers_doc);
433 453 }
454 #endif
455
General Comments 0
You need to be logged in to leave comments. Login now