mpatch.c: Added preliminary support for py3k.
authorRenato Cunha <renatoc@gmail.com>
Tue, 15 Jun 2010 19:49:56 -0300
changeset 11360 2ac98313b26c
parent 11359 4eaacccbb2ca
child 11361 3de3d670d2b6
mpatch.c: Added preliminary support for py3k. This is done by including the util.h header file, that defines appropriate macros according to the current python version.
mercurial/mpatch.c
--- a/mercurial/mpatch.c	Tue Jun 15 19:49:56 2010 -0300
+++ b/mercurial/mpatch.c	Tue Jun 15 19:49:56 2010 -0300
@@ -24,6 +24,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "util.h"
+
 /* Definitions to get compatibility with python 2.4 and earlier which
    does not have Py_ssize_t. See also PEP 353.
    Note: msvc (8 or earlier) does not have ssize_t, so we use Py_ssize_t.
@@ -373,12 +375,12 @@
 		result = NULL;
 		goto cleanup;
 	}
-	result = PyString_FromStringAndSize(NULL, outlen);
+	result = PyBytes_FromStringAndSize(NULL, outlen);
 	if (!result) {
 		result = NULL;
 		goto cleanup;
 	}
-	out = PyString_AsString(result);
+	out = PyBytes_AsString(result);
 	if (!apply(out, in, inlen, patch)) {
 		Py_DECREF(result);
 		result = NULL;
@@ -435,10 +437,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