##// 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 #include <ctype.h>
11 #include <ctype.h>
12 #include <string.h>
12 #include <string.h>
13
13
14 #include "util.h"
15
14 static int hexdigit(char c)
16 static int hexdigit(char c)
15 {
17 {
16 if (c >= '0' && c <= '9')
18 if (c >= '0' && c <= '9')
@@ -33,11 +35,13 b' static PyObject *unhexlify(const char *s'
33 const char *c;
35 const char *c;
34 char *d;
36 char *d;
35
37
36 ret = PyString_FromStringAndSize(NULL, len / 2);
38 ret = PyBytes_FromStringAndSize(NULL, len / 2);
39
37 if (!ret)
40 if (!ret)
38 return NULL;
41 return NULL;
39
42
40 d = PyString_AS_STRING(ret);
43 d = PyBytes_AsString(ret);
44
41 for (c = str; c < str + len;) {
45 for (c = str; c < str + len;) {
42 int hi = hexdigit(*c++);
46 int hi = hexdigit(*c++);
43 int lo = hexdigit(*c++);
47 int lo = hexdigit(*c++);
@@ -81,7 +85,8 b' static PyObject *parse_manifest(PyObject'
81 goto quit;
85 goto quit;
82 }
86 }
83
87
84 file = PyString_FromStringAndSize(start, zero - start);
88 file = PyBytes_FromStringAndSize(start, zero - start);
89
85 if (!file)
90 if (!file)
86 goto bail;
91 goto bail;
87
92
@@ -92,7 +97,7 b' static PyObject *parse_manifest(PyObject'
92 goto bail;
97 goto bail;
93
98
94 if (nlen > 40) {
99 if (nlen > 40) {
95 flags = PyString_FromStringAndSize(zero + 41,
100 flags = PyBytes_FromStringAndSize(zero + 41,
96 nlen - 40);
101 nlen - 40);
97 if (!flags)
102 if (!flags)
98 goto bail;
103 goto bail;
@@ -206,8 +211,8 b' static PyObject *parse_dirstate(PyObject'
206
211
207 cpos = memchr(cur, 0, flen);
212 cpos = memchr(cur, 0, flen);
208 if (cpos) {
213 if (cpos) {
209 fname = PyString_FromStringAndSize(cur, cpos - cur);
214 fname = PyBytes_FromStringAndSize(cur, cpos - cur);
210 cname = PyString_FromStringAndSize(cpos + 1,
215 cname = PyBytes_FromStringAndSize(cpos + 1,
211 flen - (cpos - cur) - 1);
216 flen - (cpos - cur) - 1);
212 if (!fname || !cname ||
217 if (!fname || !cname ||
213 PyDict_SetItem(cmap, fname, cname) == -1 ||
218 PyDict_SetItem(cmap, fname, cname) == -1 ||
@@ -215,7 +220,7 b' static PyObject *parse_dirstate(PyObject'
215 goto quit;
220 goto quit;
216 Py_DECREF(cname);
221 Py_DECREF(cname);
217 } else {
222 } else {
218 fname = PyString_FromStringAndSize(cur, flen);
223 fname = PyBytes_FromStringAndSize(cur, flen);
219 if (!fname ||
224 if (!fname ||
220 PyDict_SetItem(dmap, fname, entry) == -1)
225 PyDict_SetItem(dmap, fname, entry) == -1)
221 goto quit;
226 goto quit;
@@ -248,8 +253,9 b' static PyObject * _build_idx_entry(PyObj'
248 int err;
253 int err;
249 PyObject *entry, *node_id, *n_obj;
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 n_obj = PyInt_FromLong(n);
257 n_obj = PyInt_FromLong(n);
258
253 if (!node_id || !n_obj)
259 if (!node_id || !n_obj)
254 err = -1;
260 err = -1;
255 else
261 else
@@ -427,7 +433,23 b' static PyMethodDef methods[] = {'
427 {NULL, NULL}
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 PyMODINIT_FUNC initparsers(void)
450 PyMODINIT_FUNC initparsers(void)
431 {
451 {
432 Py_InitModule3("parsers", methods, parsers_doc);
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