Port bzzdec plugin to build on python2/python3

This commit is contained in:
Eli Schwartz 2019-01-10 02:40:15 -05:00
parent 1a16a0e545
commit dcf58e9a15

View File

@ -683,7 +683,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 +694,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;
} }