Mercurial > hg
changeset 11361:3de3d670d2b6
parsers.c: Added support for py3k.
This patch adds support for py3k in parsers.c. This is accomplished by including
a header file responsible for abstracting the API differences between python 2
and python 3.
author | Renato Cunha <renatoc@gmail.com> |
---|---|
date | Tue, 15 Jun 2010 19:49:56 -0300 |
parents | 2ac98313b26c |
children | f42ef9493fa9 |
files | mercurial/parsers.c |
diffstat | 1 files changed, 30 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/parsers.c Tue Jun 15 19:49:56 2010 -0300 +++ b/mercurial/parsers.c Tue Jun 15 19:49:56 2010 -0300 @@ -11,6 +11,8 @@ #include <ctype.h> #include <string.h> +#include "util.h" + static int hexdigit(char c) { if (c >= '0' && c <= '9') @@ -33,11 +35,13 @@ const char *c; char *d; - ret = PyString_FromStringAndSize(NULL, len / 2); + ret = PyBytes_FromStringAndSize(NULL, len / 2); + if (!ret) return NULL; - d = PyString_AS_STRING(ret); + d = PyBytes_AsString(ret); + for (c = str; c < str + len;) { int hi = hexdigit(*c++); int lo = hexdigit(*c++); @@ -81,7 +85,8 @@ goto quit; } - file = PyString_FromStringAndSize(start, zero - start); + file = PyBytes_FromStringAndSize(start, zero - start); + if (!file) goto bail; @@ -92,7 +97,7 @@ goto bail; if (nlen > 40) { - flags = PyString_FromStringAndSize(zero + 41, + flags = PyBytes_FromStringAndSize(zero + 41, nlen - 40); if (!flags) goto bail; @@ -206,8 +211,8 @@ cpos = memchr(cur, 0, flen); if (cpos) { - fname = PyString_FromStringAndSize(cur, cpos - cur); - cname = PyString_FromStringAndSize(cpos + 1, + fname = PyBytes_FromStringAndSize(cur, cpos - cur); + cname = PyBytes_FromStringAndSize(cpos + 1, flen - (cpos - cur) - 1); if (!fname || !cname || PyDict_SetItem(cmap, fname, cname) == -1 || @@ -215,7 +220,7 @@ goto quit; Py_DECREF(cname); } else { - fname = PyString_FromStringAndSize(cur, flen); + fname = PyBytes_FromStringAndSize(cur, flen); if (!fname || PyDict_SetItem(dmap, fname, entry) == -1) goto quit; @@ -248,8 +253,9 @@ int err; PyObject *entry, *node_id, *n_obj; - node_id = PyString_FromStringAndSize(c_node_id, 20); + node_id = PyBytes_FromStringAndSize(c_node_id, 20); n_obj = PyInt_FromLong(n); + if (!node_id || !n_obj) err = -1; else @@ -427,7 +433,23 @@ {NULL, NULL} }; +#ifdef IS_PY3K +static struct PyModuleDef parsers_module = { + PyModuleDef_HEAD_INIT, + "parsers", + parsers_doc, + -1, + methods +}; + +PyMODINIT_FUNC PyInit_parsers(void) +{ + return PyModule_Create(&parsers_module); +} +#else PyMODINIT_FUNC initparsers(void) { Py_InitModule3("parsers", methods, parsers_doc); } +#endif +