[PATCH 6 of 6] imported patch bdiff.c-py3k-port.diff
Renato Cunha
renatoc at gmail.com
Tue Jun 8 12:57:32 CDT 2010
# HG changeset patch
# User Renato Cunha <renatoc at gmail.com>
# Date 1276015326 10800
# Node ID eeb3e447dac604555ef944ca8d639ac5db5919eb
# Parent b71f390cb6204ba2719a3f97c536c4d4c1ef86e7
imported patch bdiff.c-py3k-port.diff
diff --git a/mercurial/bdiff.c b/mercurial/bdiff.c
--- a/mercurial/bdiff.c
+++ b/mercurial/bdiff.c
@@ -46,6 +46,10 @@
#include <inttypes.h>
#endif
+#if PY_MAJOR_VERSION >= 3
+#define IS_PY3K
+#endif
+
struct line {
int h, len, n, e;
const char *l;
@@ -309,8 +313,14 @@
if (!PyArg_ParseTuple(args, "SS:bdiff", &sa, &sb))
return NULL;
+#ifdef IS_PY3K
+ an = splitlines(PyBytes_AsString(sa), PyBytes_Size(sa), &a);
+ bn = splitlines(PyBytes_AsString(sb), PyBytes_Size(sb), &b);
+#else
an = splitlines(PyString_AsString(sa), PyString_Size(sa), &a);
bn = splitlines(PyString_AsString(sb), PyString_Size(sb), &b);
+#endif
+
if (!a || !b)
goto nomem;
@@ -363,12 +373,17 @@
lb = h->b2;
}
+#ifdef IS_PY3K
+ result = PyBytes_FromStringAndSize(NULL, len);
+#else
result = PyString_FromStringAndSize(NULL, len);
+#endif
+
if (!result)
goto nomem;
/* build binary patch */
- rb = PyString_AsString(result);
+ rb = PyBytes_AsString(result);
la = lb = 0;
for (h = l.base; h != l.head; h++) {
@@ -400,8 +415,23 @@
{NULL, NULL}
};
+#ifdef IS_PY3K
+static struct PyModuleDef bdiff_module = {
+ PyModuleDef_HEAD_INIT,
+ "bdiff",
+ mdiff_doc,
+ -1,
+ methods
+};
+
+PyMODINIT_FUNC PyInit_bdiff(void)
+{
+ return PyModule_Create(&bdiff_module);
+}
+#else
PyMODINIT_FUNC initbdiff(void)
{
Py_InitModule3("bdiff", methods, mdiff_doc);
}
+#endif
More information about the Mercurial-devel
mailing list