[PATCH 2 of 6] imported patch mpatch.c-py3k-port.diff
Renato Cunha
renatoc at gmail.com
Tue Jun 8 17:57:28 UTC 2010
# HG changeset patch
# User Renato Cunha <renatoc at gmail.com>
# Date 1276015325 10800
# Node ID 6161c0ce8de625954cb7e45ed0a7e08d1b87f8ba
# Parent 09df6346efc7d8fed0d2195f486a368af679d771
imported patch mpatch.c-py3k-port.diff
diff --git a/mercurial/mpatch.c b/mercurial/mpatch.c
--- a/mercurial/mpatch.c
+++ b/mercurial/mpatch.c
@@ -32,6 +32,8 @@
typedef int Py_ssize_t;
#define PY_SSIZE_T_MAX INT_MAX
#define PY_SSIZE_T_MIN INT_MIN
+#elif PY_MAJOR_VERSION >= 3
+#define IS_PY3K
#endif
#ifdef _WIN32
@@ -373,12 +375,20 @@
result = NULL;
goto cleanup;
}
+#ifdef IS_PY3K
+ result = PyBytes_FromStringAndSize(NULL, outlen);
+#else
result = PyString_FromStringAndSize(NULL, outlen);
+#endif
if (!result) {
result = NULL;
goto cleanup;
}
+#ifdef IS_PY3K
+ out = PyBytes_AsString(result);
+#else
out = PyString_AsString(result);
+#endif
if (!apply(out, in, inlen, patch)) {
Py_DECREF(result);
result = NULL;
@@ -435,10 +445,34 @@
{NULL, NULL}
};
+#ifdef IS_PY3K
+static struct PyModuleDef mpatch_module = {
+ PyModuleDef_HEAD_INIT,
+ "mpatch",
+ mpatch_doc,
+ -1,
+ methods
+};
+
+PyMODINIT_FUNC PyInit_mpatch(void)
+{
+ PyObject *m;
+
+ m = PyModule_Create(&mpatch_module);
+ if (m == NULL)
+ return NULL;
+
+ mpatch_Error = PyErr_NewException("mpatch.mpatchError", NULL, NULL);
+ Py_INCREF(mpatch_Error);
+ PyModule_AddObject(m, "mpatchError", mpatch_Error);
+
+ return m;
+}
+#else
PyMODINIT_FUNC
initmpatch(void)
{
Py_InitModule3("mpatch", methods, mpatch_doc);
mpatch_Error = PyErr_NewException("mpatch.mpatchError", NULL, NULL);
}
-
+#endif
More information about the Mercurial-devel
mailing list