changeset 11360:2ac98313b26c

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.
author Renato Cunha <renatoc@gmail.com>
date Tue, 15 Jun 2010 19:49:56 -0300
parents 4eaacccbb2ca
children 3de3d670d2b6
files mercurial/mpatch.c
diffstat 1 files changed, 29 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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