From 5d4023de29d270cde87c6804f6ee42532255be30 Mon Sep 17 00:00:00 2001 From: Renato Cunha Date: Tue, 15 Jun 2010 19:49:56 -0300 Subject: [PATCH] base85.c: Added support for py3k. This patch adds support for py3k in base85.c. This is accomplished by including a header file responsible for abstracting the API differences between python 2 and python 3. --- mercurial/base85.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/mercurial/base85.c b/mercurial/base85.c index caaa4a0ed0..df966293a0 100644 --- a/mercurial/base85.c +++ b/mercurial/base85.c @@ -11,6 +11,8 @@ #include +#include "util.h" + static const char b85chars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~"; static char b85dec[256]; @@ -46,10 +48,10 @@ b85encode(PyObject *self, PyObject *args) 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_AsString(out); while (len) { acc = 0; @@ -68,7 +70,7 @@ b85encode(PyObject *self, PyObject *args) } if (!pad) - _PyString_Resize(&out, olen); + _PyBytes_Resize(&out, olen); return out; } @@ -89,10 +91,10 @@ b85decode(PyObject *self, PyObject *args) 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_AsString(out); i = 0; while (i < len) @@ -153,9 +155,26 @@ static PyMethodDef methods[] = { {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