[PATCH 4 of 6] imported patch base85.c-py3k-port.diff

Renato Cunha renatoc at gmail.com
Tue Jun 8 17:57:30 UTC 2010


# HG changeset patch
# User Renato Cunha <renatoc at gmail.com>
# Date 1276015326 10800
# Node ID da107bdf89397034141966b10855de21b429bec6
# Parent  1f11288014db47774e0b05574cc41fd0b3784616
imported patch base85.c-py3k-port.diff

diff --git a/mercurial/base85.c b/mercurial/base85.c
--- a/mercurial/base85.c
+++ b/mercurial/base85.c
@@ -11,6 +11,10 @@
 
 #include <Python.h>
 
+#if PY_MAJOR_VERSION >= 3
+#define IS_PY3K
+#endif
+
 static const char b85chars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 	"abcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~";
 static char b85dec[256];
@@ -46,10 +50,10 @@
 			olen++;
 		olen += len / 4 * 5;
 	}
-	if (!(out = PyString_FromStringAndSize(NULL, olen + 3)))
+	if (!(out = PyBytes_FromStringAndSize(NULL, olen + 3)))
 		return NULL;
 
-	dst = PyString_AS_STRING(out);
+	dst = PyBytes_AS_STRING(out);
 
 	while (len) {
 		acc = 0;
@@ -68,7 +72,7 @@
 	}
 
 	if (!pad)
-		_PyString_Resize(&out, olen);
+		_PyBytes_Resize(&out, olen);
 
 	return out;
 }
@@ -89,10 +93,10 @@
 	i = len % 5;
 	if (i)
 		olen += i - 1;
-	if (!(out = PyString_FromStringAndSize(NULL, olen)))
+	if (!(out = PyBytes_FromStringAndSize(NULL, olen)))
 		return NULL;
 
-	dst = PyString_AS_STRING(out);
+	dst = PyBytes_AS_STRING(out);
 
 	i = 0;
 	while (i < len)
@@ -153,9 +157,26 @@
 	{NULL, NULL}
 };
 
+#ifdef IS_PY3K
+static struct PyModuleDef base85_module = {
+	PyModuleDef_HEAD_INIT,
+	"base85",
+	base85_doc,
+	-1,
+	methods
+};
+
+PyMODINIT_FUNC PyInit_base85(void)
+{
+	b85prep();
+
+	return PyModule_Create(&base85_module);
+}
+#else
 PyMODINIT_FUNC initbase85(void)
 {
 	Py_InitModule3("base85", methods, base85_doc);
 
 	b85prep();
 }
+#endif



More information about the Mercurial-devel mailing list