This commit is contained in:
Kovid Goyal 2019-02-21 10:22:11 +05:30
commit 405d52eedc
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -632,7 +632,11 @@ bzz_decompress(PyObject *self, PyObject *args) {
size_t buflen = 0, blocksize = MAXBLOCK * 1024; size_t buflen = 0, blocksize = MAXBLOCK * 1024;
PyObject *ans = NULL; PyObject *ans = NULL;
#if PY_MAJOR_VERSION >= 3
if (!PyArg_ParseTuple(args, "y#", &(state.raw), &input_len))
#else
if (!PyArg_ParseTuple(args, "s#", &(state.raw), &input_len)) if (!PyArg_ParseTuple(args, "s#", &(state.raw), &input_len))
#endif
return NULL; return NULL;
state.end = state.raw + input_len - 1; state.end = state.raw + input_len - 1;
@ -683,7 +687,9 @@ end:
return ans; return ans;
} }
static PyMethodDef bzzdecmethods[] = { static char bzzdec_doc[] = "Decompress BZZ encoded strings (used in DJVU)";
static PyMethodDef bzzdec_methods[] = {
{"decompress", bzz_decompress, METH_VARARGS, {"decompress", bzz_decompress, METH_VARARGS,
"decompress(bytestring) -> decompressed bytestring\n\n" "decompress(bytestring) -> decompressed bytestring\n\n"
"Decompress a BZZ compressed byte string. " "Decompress a BZZ compressed byte string. "
@ -692,15 +698,32 @@ static PyMethodDef bzzdecmethods[] = {
{NULL, NULL, 0, NULL} {NULL, NULL, 0, NULL}
}; };
#if PY_MAJOR_VERSION >= 3
#define INITERROR return NULL
#define INITMODULE PyModule_Create(&bzzdec_module)
static struct PyModuleDef bzzdec_module = {
/* m_base */ PyModuleDef_HEAD_INIT,
/* m_name */ "bzzdec",
/* m_doc */ bzzdec_doc,
/* m_size */ -1,
/* m_methods */ bzzdec_methods,
/* m_slots */ 0,
/* m_traverse */ 0,
/* m_clear */ 0,
/* m_free */ 0,
};
CALIBRE_MODINIT_FUNC PyInit_bzzdec(void) {
#else
#define INITERROR return
#define INITMODULE Py_InitModule3("bzzdec", bzzdec_methods, bzzdec_doc)
CALIBRE_MODINIT_FUNC initbzzdec(void) {
#endif
PyObject *m = INITMODULE;
CALIBRE_MODINIT_FUNC if (m == NULL) {
initbzzdec(void) { INITERROR;
PyObject *m; }
m = Py_InitModule3("bzzdec", bzzdecmethods, #if PY_MAJOR_VERSION >= 3
"Decompress BZZ encoded strings (used in DJVU)" return m;
); #endif
if (m == NULL) return;
} }