Skip to content
Snippets Groups Projects
Commit f42ef949 authored by Renato Cunha's avatar Renato Cunha
Browse files

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.
parent 3de3d670
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,8 @@
#include <Python.h>
#include "util.h"
static const char b85chars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~";
static char b85dec[256];
......@@ -46,6 +48,6 @@
olen++;
olen += len / 4 * 5;
}
if (!(out = PyString_FromStringAndSize(NULL, olen + 3)))
if (!(out = PyBytes_FromStringAndSize(NULL, olen + 3)))
return NULL;
......@@ -50,6 +52,6 @@
return NULL;
dst = PyString_AS_STRING(out);
dst = PyBytes_AsString(out);
while (len) {
acc = 0;
......@@ -68,7 +70,7 @@
}
if (!pad)
_PyString_Resize(&out, olen);
_PyBytes_Resize(&out, olen);
return out;
}
......@@ -89,6 +91,6 @@
i = len % 5;
if (i)
olen += i - 1;
if (!(out = PyString_FromStringAndSize(NULL, olen)))
if (!(out = PyBytes_FromStringAndSize(NULL, olen)))
return NULL;
......@@ -93,6 +95,6 @@
return NULL;
dst = PyString_AS_STRING(out);
dst = PyBytes_AsString(out);
i = 0;
while (i < len)
......@@ -153,9 +155,25 @@
{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();
}
......@@ -156,6 +174,7 @@
PyMODINIT_FUNC initbase85(void)
{
Py_InitModule3("base85", methods, base85_doc);
b85prep();
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment