mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-07 09:01:38 -04:00
Remove py2 code paths
This commit is contained in:
parent
f250c39406
commit
9cab833728
@ -125,9 +125,6 @@ static PyMethodDef libusb_methods[] = {
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
#define INITMODULE PyModule_Create(&libusb_module)
|
||||
static struct PyModuleDef libusb_module = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "libusb",
|
||||
@ -140,40 +137,32 @@ static struct PyModuleDef libusb_module = {
|
||||
/* m_free */ 0,
|
||||
};
|
||||
CALIBRE_MODINIT_FUNC PyInit_libusb(void) {
|
||||
#else
|
||||
#define INITERROR return
|
||||
#define INITMODULE Py_InitModule3("libusb", libusb_methods, libusb_doc)
|
||||
CALIBRE_MODINIT_FUNC initlibusb(void) {
|
||||
#endif
|
||||
|
||||
PyObject *m;
|
||||
|
||||
// We deliberately use the default context. This is the context used by
|
||||
// libmtp and we want to ensure that the busnum/devnum numbers are the same
|
||||
// here and for libmtp.
|
||||
if(libusb_init(NULL) != 0) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Error = PyErr_NewException("libusb.Error", NULL, NULL);
|
||||
if (Error == NULL) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cache = PyDict_New();
|
||||
if (cache == NULL) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
m = INITMODULE;
|
||||
m = PyModule_Create(&libusb_module);
|
||||
if (m == NULL) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyModule_AddObject(m, "Error", Error);
|
||||
PyModule_AddObject(m, "cache", cache);
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
@ -86,11 +86,7 @@ static uint16_t data_to_python(void *params, void *priv, uint32_t sendlen, unsig
|
||||
cb = (ProgressCallback *)priv;
|
||||
*putlen = sendlen;
|
||||
PyEval_RestoreThread(cb->state);
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
res = PyObject_CallMethod(cb->extra, "write", "y#", data, (Py_ssize_t)sendlen);
|
||||
#else
|
||||
res = PyObject_CallMethod(cb->extra, "write", "s#", data, (Py_ssize_t)sendlen);
|
||||
#endif
|
||||
if (res == NULL) {
|
||||
ret = LIBMTP_HANDLER_RETURN_ERROR;
|
||||
*putlen = 0;
|
||||
@ -717,9 +713,6 @@ static PyMethodDef libmtp_methods[] = {
|
||||
};
|
||||
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
#define INITMODULE PyModule_Create(&libmtp_module)
|
||||
static struct PyModuleDef libmtp_module = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "libmtp",
|
||||
@ -732,25 +725,19 @@ static struct PyModuleDef libmtp_module = {
|
||||
/* m_free */ 0,
|
||||
};
|
||||
CALIBRE_MODINIT_FUNC PyInit_libmtp(void) {
|
||||
#else
|
||||
#define INITERROR return
|
||||
#define INITMODULE Py_InitModule3("libmtp", libmtp_methods, libmtp_doc);
|
||||
CALIBRE_MODINIT_FUNC initlibmtp(void) {
|
||||
#endif
|
||||
|
||||
DeviceType.tp_new = PyType_GenericNew;
|
||||
if (PyType_Ready(&DeviceType) < 0) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyObject *m = INITMODULE;
|
||||
PyObject *m = PyModule_Create(&libmtp_module);
|
||||
if (m == NULL) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MTPError = PyErr_NewException("libmtp.MTPError", NULL, NULL);
|
||||
if (MTPError == NULL) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
PyModule_AddObject(m, "MTPError", MTPError);
|
||||
|
||||
@ -782,7 +769,5 @@ CALIBRE_MODINIT_FUNC initlibmtp(void) {
|
||||
PyModule_AddIntMacro(m, LIBMTP_DEBUG_DATA);
|
||||
PyModule_AddIntMacro(m, LIBMTP_DEBUG_ALL);
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
@ -554,11 +554,7 @@ PyObject* wpd::get_file(IPortableDevice *device, const wchar_t *object_id, PyObj
|
||||
PyErr_SetString(PyExc_IOError, "Read access is denied to this object"); break;
|
||||
} else if (SUCCEEDED(hr)) {
|
||||
if (bytes_read > 0) {
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
res = PyObject_CallMethod(dest, "write", "y#", buf, bytes_read);
|
||||
#else
|
||||
res = PyObject_CallMethod(dest, "write", "s#", buf, bytes_read);
|
||||
#endif
|
||||
if (res == NULL) break;
|
||||
Py_DECREF(res); res = NULL;
|
||||
if (callback != NULL) Py_XDECREF(PyObject_CallFunction(callback, "kK", total_read, filesize));
|
||||
|
@ -302,11 +302,7 @@ PyObject* get_device_information(IPortableDevice *device, IPortableDevicePropert
|
||||
default:
|
||||
type = "unknown";
|
||||
}
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
t = PyUnicode_FromString(type);
|
||||
#else
|
||||
t = PyString_FromString(type);
|
||||
#endif
|
||||
if (t != NULL) {
|
||||
PyDict_SetItemString(ans, "type", t); Py_DECREF(t);
|
||||
}
|
||||
|
@ -183,9 +183,6 @@ static PyMethodDef wpd_methods[] = {
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
#define INITMODULE PyModule_Create(&wpd_module)
|
||||
static struct PyModuleDef wpd_module = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "wpd",
|
||||
@ -197,46 +194,39 @@ static struct PyModuleDef wpd_module = {
|
||||
/* m_clear */ 0,
|
||||
/* m_free */ 0,
|
||||
};
|
||||
CALIBRE_MODINIT_FUNC PyInit_wpd(void) {
|
||||
#else
|
||||
#define INITERROR return
|
||||
#define INITMODULE Py_InitModule3("wpd", wpd_methods, wpd_doc)
|
||||
CALIBRE_MODINIT_FUNC initwpd(void) {
|
||||
#endif
|
||||
|
||||
CALIBRE_MODINIT_FUNC PyInit_wpd(void) {
|
||||
PyObject *m;
|
||||
|
||||
wpd::DeviceType.tp_new = PyType_GenericNew;
|
||||
if (PyType_Ready(&wpd::DeviceType) < 0)
|
||||
INITERROR;
|
||||
return NULL;
|
||||
|
||||
m = INITMODULE;
|
||||
m = PyModule_Create(&wpd_module);
|
||||
if (m == NULL) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
WPDError = PyErr_NewException("wpd.WPDError", NULL, NULL);
|
||||
if (WPDError == NULL) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
PyModule_AddObject(m, "WPDError", WPDError);
|
||||
|
||||
NoWPD = PyErr_NewException("wpd.NoWPD", NULL, NULL);
|
||||
if (NoWPD == NULL) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
PyModule_AddObject(m, "NoWPD", NoWPD);
|
||||
|
||||
WPDFileBusy = PyErr_NewException("wpd.WPDFileBusy", NULL, NULL);
|
||||
if (WPDFileBusy == NULL) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
PyModule_AddObject(m, "WPDFileBusy", WPDFileBusy);
|
||||
|
||||
Py_INCREF(&DeviceType);
|
||||
PyModule_AddObject(m, "Device", (PyObject *)&DeviceType);
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
@ -461,9 +461,6 @@ static PyMethodDef usbobserver_methods[] = {
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
#define INITMODULE PyModule_Create(&usbobserver_module)
|
||||
static struct PyModuleDef usbobserver_module = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "usbobserver",
|
||||
@ -476,16 +473,8 @@ static struct PyModuleDef usbobserver_module = {
|
||||
/* m_free */ 0,
|
||||
};
|
||||
CALIBRE_MODINIT_FUNC PyInit_usbobserver(void) {
|
||||
#else
|
||||
#define INITERROR return
|
||||
#define INITMODULE Py_InitModule3("usbobserver", usbobserver_methods, usbobserver_doc)
|
||||
CALIBRE_MODINIT_FUNC initusbobserver(void) {
|
||||
#endif
|
||||
|
||||
PyObject *m = NULL;
|
||||
m = INITMODULE;
|
||||
m = PyModule_Create(&usbobserver_module);
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
@ -42,20 +42,12 @@ typedef struct {
|
||||
|
||||
#define CHAR(x) (( (x) > 127 ) ? (x)-256 : (x))
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define BUFFER_FMT "y#"
|
||||
#define BYTES_FMT "y#"
|
||||
#else
|
||||
#define BUFFER_FMT "t#"
|
||||
#define BYTES_FMT "s#"
|
||||
#endif
|
||||
|
||||
static PyObject *
|
||||
cpalmdoc_decompress(PyObject *self, PyObject *args) {
|
||||
const char *_input = NULL; Py_ssize_t input_len = 0;
|
||||
Byte *input; char *output; Byte c; PyObject *ans;
|
||||
Py_ssize_t i = 0, o = 0, j = 0, di, n;
|
||||
if (!PyArg_ParseTuple(args, BUFFER_FMT, &_input, &input_len))
|
||||
if (!PyArg_ParseTuple(args, "y#", &_input, &input_len))
|
||||
return NULL;
|
||||
input = (Byte *) PyMem_Malloc(sizeof(Byte)*input_len);
|
||||
if (input == NULL) return PyErr_NoMemory();
|
||||
@ -84,7 +76,7 @@ cpalmdoc_decompress(PyObject *self, PyObject *args) {
|
||||
output[o] = output[o - di];
|
||||
}
|
||||
}
|
||||
ans = Py_BuildValue(BYTES_FMT, output, o);
|
||||
ans = Py_BuildValue("y#", output, o);
|
||||
if (output != NULL) PyMem_Free(output);
|
||||
if (input != NULL) PyMem_Free(input);
|
||||
return ans;
|
||||
@ -170,7 +162,7 @@ cpalmdoc_compress(PyObject *self, PyObject *args) {
|
||||
char *output; PyObject *ans;
|
||||
Py_ssize_t j = 0;
|
||||
buffer b;
|
||||
if (!PyArg_ParseTuple(args, BUFFER_FMT, &_input, &input_len))
|
||||
if (!PyArg_ParseTuple(args, "y#", &_input, &input_len))
|
||||
return NULL;
|
||||
b.data = (Byte *)PyMem_Malloc(sizeof(Byte)*input_len);
|
||||
if (b.data == NULL) return PyErr_NoMemory();
|
||||
@ -184,7 +176,7 @@ cpalmdoc_compress(PyObject *self, PyObject *args) {
|
||||
if (output == NULL) return PyErr_NoMemory();
|
||||
j = cpalmdoc_do_compress(&b, output);
|
||||
if ( j == 0) return PyErr_NoMemory();
|
||||
ans = Py_BuildValue(BYTES_FMT, output, j);
|
||||
ans = Py_BuildValue("y#", output, j);
|
||||
PyMem_Free(output);
|
||||
PyMem_Free(b.data);
|
||||
return ans;
|
||||
@ -205,9 +197,6 @@ static PyMethodDef cPalmdoc_methods[] = {
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
#define INITMODULE PyModule_Create(&cPalmdoc_module)
|
||||
static struct PyModuleDef cPalmdoc_module = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "cPalmdoc",
|
||||
@ -220,19 +209,10 @@ static struct PyModuleDef cPalmdoc_module = {
|
||||
/* m_free */ 0,
|
||||
};
|
||||
CALIBRE_MODINIT_FUNC PyInit_cPalmdoc(void) {
|
||||
#else
|
||||
#define INITERROR return
|
||||
#define INITMODULE Py_InitModule3("cPalmdoc", cPalmdoc_methods, cPalmdoc_doc)
|
||||
CALIBRE_MODINIT_FUNC initcPalmdoc(void) {
|
||||
#endif
|
||||
|
||||
PyObject *m;
|
||||
m = INITMODULE;
|
||||
PyObject *m = PyModule_Create(&cPalmdoc_module);
|
||||
if (m == NULL) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
@ -632,12 +632,7 @@ bzz_decompress(PyObject *self, PyObject *args) {
|
||||
size_t buflen = 0, blocksize = MAXBLOCK * 1024;
|
||||
PyObject *ans = NULL;
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define BYTES_FMT "y#"
|
||||
#else
|
||||
#define BYTES_FMT "s#"
|
||||
#endif
|
||||
if (!PyArg_ParseTuple(args, BYTES_FMT, &(state.raw), &input_len))
|
||||
if (!PyArg_ParseTuple(args, "y#", &(state.raw), &input_len))
|
||||
return NULL;
|
||||
state.end = state.raw + input_len - 1;
|
||||
|
||||
@ -681,7 +676,7 @@ end:
|
||||
for (i = 0; i < 3; i++) {
|
||||
buflen <<= 8; buflen += (uint8_t)buf[i];
|
||||
}
|
||||
ans = Py_BuildValue(BYTES_FMT, buf + 3, MIN(buflen, pos - buf));
|
||||
ans = Py_BuildValue("y#", buf + 3, MIN(buflen, pos - buf));
|
||||
}
|
||||
if (buf != NULL) free(buf);
|
||||
if (PyErr_Occurred()) return NULL;
|
||||
@ -699,9 +694,7 @@ static PyMethodDef bzzdec_methods[] = {
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
#define INITMODULE PyModule_Create(&bzzdec_module)
|
||||
#define INITMODULE
|
||||
static struct PyModuleDef bzzdec_module = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "bzzdec",
|
||||
@ -714,17 +707,9 @@ static struct PyModuleDef bzzdec_module = {
|
||||
/* 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;
|
||||
PyObject *m = PyModule_Create(&bzzdec_module);
|
||||
if (m == NULL) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
@ -1255,8 +1255,6 @@ static PyMethodDef _patiencediff_c_methods[] = {
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
static struct PyModuleDef _patiencediff_c_module = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "_patiencediff_c",
|
||||
@ -1271,29 +1269,16 @@ static struct PyModuleDef _patiencediff_c_module = {
|
||||
|
||||
CALIBRE_MODINIT_FUNC PyInit__patiencediff_c(void) {
|
||||
if (PyType_Ready(&PatienceSequenceMatcherType) < 0)
|
||||
INITERROR;
|
||||
return NULL;
|
||||
|
||||
PyObject *mod = PyModule_Create(&_patiencediff_c_module);
|
||||
#else
|
||||
#define INITERROR return
|
||||
CALIBRE_MODINIT_FUNC init_patiencediff_c(void) {
|
||||
if (PyType_Ready(&PatienceSequenceMatcherType) < 0)
|
||||
INITERROR;
|
||||
|
||||
PyObject *mod = Py_InitModule3("_patiencediff_c", _patiencediff_c_methods,
|
||||
"C implementation of PatienceSequenceMatcher");
|
||||
#endif
|
||||
|
||||
if (mod == NULL) INITERROR;
|
||||
if (mod == NULL) return NULL;
|
||||
|
||||
Py_INCREF(&PatienceSequenceMatcherType);
|
||||
PyModule_AddObject(mod, "PatienceSequenceMatcher_c",
|
||||
(PyObject *)&PatienceSequenceMatcherType);
|
||||
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return mod;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* vim: sw=4 et */
|
@ -482,8 +482,6 @@ static PyMethodDef html_methods[] = {
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
static struct PyModuleDef html_module = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "html_syntax_highlighter",
|
||||
@ -498,28 +496,21 @@ static struct PyModuleDef html_module = {
|
||||
|
||||
CALIBRE_MODINIT_FUNC PyInit_html_syntax_highlighter(void) {
|
||||
PyObject *temp, *mod = PyModule_Create(&html_module);
|
||||
#else
|
||||
#define INITERROR return
|
||||
CALIBRE_MODINIT_FUNC inithtml_syntax_highlighter(void) {
|
||||
PyObject *temp, *mod = Py_InitModule3("html_syntax_highlighter", html_methods,
|
||||
"Speedups for the html syntax highlighter");
|
||||
#endif
|
||||
|
||||
if (mod == NULL) INITERROR;
|
||||
if (mod == NULL) return NULL;
|
||||
|
||||
if (PyType_Ready(&html_TagType) < 0)
|
||||
INITERROR;
|
||||
return NULL;
|
||||
if (PyType_Ready(&html_StateType) < 0)
|
||||
INITERROR;
|
||||
return NULL;
|
||||
|
||||
temp = Py_BuildValue("ssssssss", "b", "strong", "h1", "h2", "h3", "h4", "h5", "h6", "h7");
|
||||
if (temp == NULL) INITERROR;
|
||||
if (temp == NULL) return NULL;
|
||||
bold_tags = PyFrozenSet_New(temp);
|
||||
Py_DECREF(temp);
|
||||
temp = NULL;
|
||||
|
||||
temp = Py_BuildValue("ss", "i", "em");
|
||||
if (temp == NULL) INITERROR;
|
||||
if (temp == NULL) return NULL;
|
||||
italic_tags = PyFrozenSet_New(temp);
|
||||
Py_DECREF(temp);
|
||||
temp = NULL;
|
||||
@ -530,7 +521,7 @@ CALIBRE_MODINIT_FUNC inithtml_syntax_highlighter(void) {
|
||||
Py_XDECREF(bold_tags);
|
||||
Py_XDECREF(italic_tags);
|
||||
Py_XDECREF(zero);
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF(&html_TagType);
|
||||
@ -540,8 +531,5 @@ CALIBRE_MODINIT_FUNC inithtml_syntax_highlighter(void) {
|
||||
PyModule_AddObject(mod, "bold_tags", bold_tags);
|
||||
PyModule_AddObject(mod, "italic_tags", italic_tags);
|
||||
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return mod;
|
||||
#endif
|
||||
}
|
||||
|
@ -273,9 +273,6 @@ static PyMethodDef sqlite_custom_methods[] = {
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
#define INITMODULE PyModule_Create(&sqlite_custom_module)
|
||||
static struct PyModuleDef sqlite_custom_module = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "sqlite_custom",
|
||||
@ -288,18 +285,10 @@ static struct PyModuleDef sqlite_custom_module = {
|
||||
/* m_free */ 0,
|
||||
};
|
||||
CALIBRE_MODINIT_FUNC PyInit_sqlite_custom(void) {
|
||||
#else
|
||||
#define INITERROR return
|
||||
#define INITMODULE Py_InitModule3("sqlite_custom", sqlite_custom_methods, sqlite_custom_doc)
|
||||
CALIBRE_MODINIT_FUNC initsqlite_custom(void) {
|
||||
#endif
|
||||
|
||||
PyObject *m;
|
||||
m = INITMODULE;
|
||||
m = PyModule_Create(&sqlite_custom_module);
|
||||
if (m == NULL) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
@ -102,23 +102,17 @@ namespaces_are_equal(const char *a, const char *b, size_t len) {
|
||||
}
|
||||
|
||||
class StringOrNone {
|
||||
PyObject *temp, *orig;
|
||||
PyObject *orig;
|
||||
const char *data;
|
||||
public:
|
||||
StringOrNone(PyObject *x) : temp(0), orig(x), data(0) {
|
||||
StringOrNone(PyObject *x) : orig(x), data(0) {
|
||||
if (x && x != Py_None) {
|
||||
if (PyUnicode_Check(x)) {
|
||||
#if PY_MAJOR_VERSION > 2
|
||||
this->data = PyUnicode_AsUTF8(x);
|
||||
#else
|
||||
this->temp = PyUnicode_AsUTF8String(x);
|
||||
if (this->temp) this->data = PyBytes_AS_STRING(this->temp);
|
||||
#endif
|
||||
} else if (PyBytes_Check(x)) { this->data = PyBytes_AS_STRING(x); }
|
||||
}
|
||||
}
|
||||
~StringOrNone() {
|
||||
Py_CLEAR(this->temp);
|
||||
Py_CLEAR(this->orig);
|
||||
}
|
||||
void incref() { Py_XINCREF(this->orig); }
|
||||
@ -437,10 +431,7 @@ static PyMethodDef methods[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
#define INITMODULE PyModule_Create(&module)
|
||||
static struct PyModuleDef module = {
|
||||
static struct PyModuleDef hmod = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "html_as_json",
|
||||
/* m_doc */ doc,
|
||||
@ -452,21 +443,10 @@ static struct PyModuleDef module = {
|
||||
/* m_free */ 0,
|
||||
};
|
||||
CALIBRE_MODINIT_FUNC PyInit_html_as_json(void) {
|
||||
#else
|
||||
#define INITERROR return
|
||||
#define INITMODULE Py_InitModule3("html_as_json", methods, doc)
|
||||
CALIBRE_MODINIT_FUNC inithtml_as_json(void) {
|
||||
#endif
|
||||
|
||||
PyObject* m;
|
||||
|
||||
m = INITMODULE;
|
||||
PyObject* m = PyModule_Create(&hmod);
|
||||
if (m == NULL) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
// }}}
|
||||
|
@ -379,8 +379,6 @@ static PyMethodDef certgen_methods[] = {
|
||||
};
|
||||
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
static struct PyModuleDef certgen_module = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "certgen",
|
||||
@ -395,20 +393,11 @@ static struct PyModuleDef certgen_module = {
|
||||
|
||||
CALIBRE_MODINIT_FUNC PyInit_certgen(void) {
|
||||
PyObject *mod = PyModule_Create(&certgen_module);
|
||||
#else
|
||||
#define INITERROR return
|
||||
CALIBRE_MODINIT_FUNC initcertgen(void) {
|
||||
PyObject *mod = Py_InitModule3("certgen", certgen_methods,
|
||||
"OpenSSL bindings to easily create certificates/certificate authorities");
|
||||
#endif
|
||||
|
||||
if (mod == NULL) INITERROR;
|
||||
if (mod == NULL) return NULL;
|
||||
|
||||
OpenSSL_add_all_algorithms();
|
||||
ERR_load_crypto_strings();
|
||||
ERR_load_BIO_strings();
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return mod;
|
||||
#endif
|
||||
}
|
||||
|
@ -102,9 +102,6 @@ static PyMethodDef module_methods[] = {
|
||||
};
|
||||
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
#define INITMODULE PyModule_Create(&cocoa_module)
|
||||
static struct PyModuleDef cocoa_module = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "cocoa",
|
||||
@ -117,17 +114,9 @@ static struct PyModuleDef cocoa_module = {
|
||||
/* m_free */ 0,
|
||||
};
|
||||
CALIBRE_MODINIT_FUNC PyInit_cocoa(void) {
|
||||
#else
|
||||
#define INITERROR return
|
||||
#define INITMODULE Py_InitModule3("cocoa", module_methods, "")
|
||||
CALIBRE_MODINIT_FUNC initcocoa(void) {
|
||||
#endif
|
||||
|
||||
PyObject *m = INITMODULE;
|
||||
PyObject *m = PyModule_Create(&cocoa_module);
|
||||
if (m == NULL) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
@ -58,11 +58,7 @@ Face_init(Face *self, PyObject *args, PyObject *kwds)
|
||||
Py_ssize_t sz;
|
||||
PyObject *ft;
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if (!PyArg_ParseTuple(args, "Oy#", &ft, &data, &sz)) return -1;
|
||||
#else
|
||||
if (!PyArg_ParseTuple(args, "Os#", &ft, &data, &sz)) return -1;
|
||||
#endif
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
error = FT_New_Memory_Face( ( (FreeType*)ft )->library,
|
||||
@ -296,9 +292,6 @@ static PyMethodDef freetype_methods[] = {
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
#define INITMODULE PyModule_Create(&freetype_module)
|
||||
static struct PyModuleDef freetype_module = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "freetype",
|
||||
@ -311,39 +304,31 @@ static struct PyModuleDef freetype_module = {
|
||||
/* m_free */ 0,
|
||||
};
|
||||
CALIBRE_MODINIT_FUNC PyInit_freetype(void) {
|
||||
#else
|
||||
#define INITERROR return
|
||||
#define INITMODULE Py_InitModule3("freetype", freetype_methods, freetype_doc)
|
||||
CALIBRE_MODINIT_FUNC initfreetype(void) {
|
||||
#endif
|
||||
|
||||
PyObject *m;
|
||||
|
||||
FreeTypeType.tp_new = PyType_GenericNew;
|
||||
if (PyType_Ready(&FreeTypeType) < 0) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
FaceType.tp_new = PyType_GenericNew;
|
||||
if (PyType_Ready(&FaceType) < 0) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
m = INITMODULE;
|
||||
m = PyModule_Create(&freetype_module);
|
||||
if (m == NULL) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
FreeTypeError = PyErr_NewException((char*)"freetype.FreeTypeError", NULL, NULL);
|
||||
if (FreeTypeError == NULL) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
PyModule_AddObject(m, "FreeTypeError", FreeTypeError);
|
||||
|
||||
Py_INCREF(&FreeTypeType);
|
||||
PyModule_AddObject(m, "FreeType", (PyObject *)&FreeTypeType);
|
||||
PyModule_AddObject(m, "Face", (PyObject *)&FaceType);
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
@ -165,11 +165,7 @@ static PyObject* add_font(PyObject *self, PyObject *args) {
|
||||
Py_ssize_t sz;
|
||||
DWORD num = 0;
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if (!PyArg_ParseTuple(args, "y#", &data, &sz)) return NULL;
|
||||
#else
|
||||
if (!PyArg_ParseTuple(args, "s#", &data, &sz)) return NULL;
|
||||
#endif
|
||||
|
||||
AddFontMemResourceEx(data, (DWORD)sz, NULL, &num);
|
||||
|
||||
@ -240,9 +236,6 @@ static PyMethodDef winfonts_methods[] = {
|
||||
};
|
||||
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
#define INITMODULE PyModule_Create(&winfonts_module)
|
||||
static struct PyModuleDef winfonts_module = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "winfonts",
|
||||
@ -254,17 +247,12 @@ static struct PyModuleDef winfonts_module = {
|
||||
/* m_clear */ 0,
|
||||
/* m_free */ 0,
|
||||
};
|
||||
CALIBRE_MODINIT_FUNC PyInit_winfonts(void) {
|
||||
#else
|
||||
#define INITERROR return
|
||||
#define INITMODULE Py_InitModule3("winfonts", winfonts_methods, winfonts_doc)
|
||||
CALIBRE_MODINIT_FUNC initwinfonts(void) {
|
||||
#endif
|
||||
|
||||
CALIBRE_MODINIT_FUNC PyInit_winfonts(void) {
|
||||
PyObject *m;
|
||||
m = INITMODULE;
|
||||
m = PyModule_Create(&winfonts_module);
|
||||
if (m == NULL) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyModule_AddIntMacro(m, FW_DONTCARE);
|
||||
@ -283,7 +271,5 @@ CALIBRE_MODINIT_FUNC initwinfonts(void) {
|
||||
PyModule_AddIntMacro(m, FW_HEAVY);
|
||||
PyModule_AddIntMacro(m, FW_BLACK);
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
@ -93,9 +93,6 @@ static PyMethodDef methods[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
#define INITMODULE PyModule_Create(&module)
|
||||
static struct PyModuleDef module = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "hyphen",
|
||||
@ -108,21 +105,12 @@ static struct PyModuleDef module = {
|
||||
/* m_free */ 0,
|
||||
};
|
||||
CALIBRE_MODINIT_FUNC PyInit_hyphen(void) {
|
||||
#else
|
||||
#define INITERROR return
|
||||
#define INITMODULE Py_InitModule3("hyphen", methods, doc)
|
||||
CALIBRE_MODINIT_FUNC inithyphen(void) {
|
||||
#endif
|
||||
|
||||
PyObject* m;
|
||||
|
||||
m = INITMODULE;
|
||||
PyObject* m = PyModule_Create(&module);
|
||||
if (m == NULL) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
// }}}
|
||||
|
@ -93,9 +93,6 @@ icu_Collator_get_strength(icu_Collator *self, void *closure) {
|
||||
static int
|
||||
icu_Collator_set_strength(icu_Collator *self, PyObject *val, void *closure) {
|
||||
if (PyLong_Check(val)) ucol_setStrength(self->collator, (int)PyLong_AsLong(val));
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
else if (PyInt_Check(val)) ucol_setStrength(self->collator, (int)PyInt_AS_LONG(val));
|
||||
#endif
|
||||
else {
|
||||
PyErr_SetString(PyExc_TypeError, "Strength must be an integer.");
|
||||
return -1;
|
||||
@ -665,11 +662,7 @@ add_split_pos_callback(void *data, int32_t pos, int32_t sz) {
|
||||
PyObject *t, *temp;
|
||||
if (pos < 0) {
|
||||
if (PyList_GET_SIZE(ans) > 0) {
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
t = PyInt_FromLong((long)sz);
|
||||
#else
|
||||
t = PyLong_FromLong((long)sz);
|
||||
#endif
|
||||
if (t == NULL) return 0;
|
||||
temp = PyList_GET_ITEM(ans, PyList_GET_SIZE(ans) - 1);
|
||||
Py_DECREF(PyTuple_GET_ITEM(temp, 1));
|
||||
@ -894,13 +887,6 @@ end:
|
||||
// set_default_encoding {{{
|
||||
static PyObject *
|
||||
icu_set_default_encoding(PyObject *self, PyObject *args) {
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
char *encoding;
|
||||
if (!PyArg_ParseTuple(args, "s:setdefaultencoding", &encoding))
|
||||
return NULL;
|
||||
if (PyUnicode_SetDefaultEncoding(encoding))
|
||||
return NULL;
|
||||
#endif
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
|
||||
@ -1029,11 +1015,7 @@ icu_ord_string(PyObject *self, PyObject *input) {
|
||||
ans = PyTuple_New(sz);
|
||||
if (ans == NULL) goto end;
|
||||
for (i = 0; i < sz; i++) {
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
temp = PyInt_FromLong((long)input_buf[i]);
|
||||
#else
|
||||
temp = PyLong_FromLong((long)input_buf[i]);
|
||||
#endif
|
||||
if (temp == NULL) { Py_DECREF(ans); ans = NULL; PyErr_NoMemory(); goto end; }
|
||||
PyTuple_SET_ITEM(ans, i, temp);
|
||||
}
|
||||
@ -1240,9 +1222,6 @@ static PyMethodDef icu_methods[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
#define INITMODULE PyModule_Create(&icu_module)
|
||||
static struct PyModuleDef icu_module = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "icu",
|
||||
@ -1256,12 +1235,6 @@ static struct PyModuleDef icu_module = {
|
||||
};
|
||||
|
||||
CALIBRE_MODINIT_FUNC PyInit_icu(void) {
|
||||
#else
|
||||
#define INITERROR return
|
||||
#define INITMODULE Py_InitModule3("icu", icu_methods, "Wrapper for the ICU internationalization library")
|
||||
CALIBRE_MODINIT_FUNC initicu(void) {
|
||||
#endif
|
||||
|
||||
UVersionInfo ver, uver;
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
char version[U_MAX_VERSION_STRING_LENGTH+1] = {0}, uversion[U_MAX_VERSION_STRING_LENGTH+5] = {0};
|
||||
@ -1269,7 +1242,7 @@ CALIBRE_MODINIT_FUNC initicu(void) {
|
||||
u_init(&status);
|
||||
if (U_FAILURE(status)) {
|
||||
PyErr_Format(PyExc_RuntimeError, "u_init() failed with error: %s", u_errorName(status));
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
u_getVersion(ver);
|
||||
u_versionToString(ver, version);
|
||||
@ -1277,13 +1250,13 @@ CALIBRE_MODINIT_FUNC initicu(void) {
|
||||
u_versionToString(uver, uversion);
|
||||
|
||||
if (PyType_Ready(&icu_CollatorType) < 0)
|
||||
INITERROR;
|
||||
return NULL;
|
||||
if (PyType_Ready(&icu_BreakIteratorType) < 0)
|
||||
INITERROR;
|
||||
return NULL;
|
||||
|
||||
PyObject *mod = INITMODULE;
|
||||
PyObject *mod = PyModule_Create(&icu_module);
|
||||
|
||||
if (mod == NULL) INITERROR;
|
||||
if (mod == NULL) return NULL;
|
||||
|
||||
Py_INCREF(&icu_CollatorType); Py_INCREF(&icu_BreakIteratorType);
|
||||
PyModule_AddObject(mod, "Collator", (PyObject *)&icu_CollatorType);
|
||||
@ -1325,8 +1298,6 @@ CALIBRE_MODINIT_FUNC initicu(void) {
|
||||
ADDUCONST(UBRK_LINE);
|
||||
ADDUCONST(UBRK_SENTENCE);
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return mod;
|
||||
#endif
|
||||
}
|
||||
// }}}
|
||||
|
@ -157,11 +157,7 @@ decompress(PyObject *self, PyObject *args)
|
||||
memory_file dest;
|
||||
PyObject *retval = NULL;
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if (!PyArg_ParseTuple(args, "y#I", &inbuf, &inlen, &outlen)) {
|
||||
#else
|
||||
if (!PyArg_ParseTuple(args, "s#I", &inbuf, &inlen, &outlen)) {
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -206,9 +202,6 @@ static PyMethodDef lzx_methods[] = {
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
#define INITMODULE PyModule_Create(&lzx_module)
|
||||
static struct PyModuleDef lzx_module = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "lzx",
|
||||
@ -222,19 +215,13 @@ static struct PyModuleDef lzx_module = {
|
||||
};
|
||||
|
||||
CALIBRE_MODINIT_FUNC PyInit_lzx(void) {
|
||||
#else
|
||||
#define INITERROR return
|
||||
#define INITMODULE Py_InitModule3("lzx", lzx_methods, lzx_doc);
|
||||
CALIBRE_MODINIT_FUNC initlzx(void) {
|
||||
#endif
|
||||
|
||||
if (PyType_Ready(&CompressorType) < 0) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyObject *m = INITMODULE;
|
||||
PyObject *m = PyModule_Create(&lzx_module);
|
||||
if (m == NULL) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LZXError = PyErr_NewException("lzx.LZXError", NULL, NULL);
|
||||
@ -244,7 +231,5 @@ CALIBRE_MODINIT_FUNC initlzx(void) {
|
||||
Py_INCREF(&CompressorType);
|
||||
PyModule_AddObject(m, "Compressor", (PyObject *)&CompressorType);
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
@ -501,8 +501,6 @@ static PyTypeObject MatcherType = { // {{{
|
||||
/* tp_new */ PyType_GenericNew,
|
||||
}; // }}}
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
static struct PyModuleDef matcher_module = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "matcher",
|
||||
@ -517,25 +515,17 @@ static struct PyModuleDef matcher_module = {
|
||||
|
||||
CALIBRE_MODINIT_FUNC PyInit_matcher(void) {
|
||||
PyObject *mod = PyModule_Create(&matcher_module);
|
||||
#else
|
||||
#define INITERROR return
|
||||
CALIBRE_MODINIT_FUNC initmatcher(void) {
|
||||
PyObject *mod = Py_InitModule3("matcher", NULL, "Find subsequence matches");
|
||||
#endif
|
||||
|
||||
if (mod == NULL) INITERROR;
|
||||
if (mod == NULL) return NULL;
|
||||
|
||||
if (PyType_Ready(&MatcherType) < 0) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF(&MatcherType);
|
||||
if(PyModule_AddObject(mod, "Matcher", (PyObject *)&MatcherType) < 0) {
|
||||
Py_DECREF(&MatcherType);
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return mod;
|
||||
#endif
|
||||
}
|
||||
|
@ -20,11 +20,7 @@ msdes_deskey(PyObject *self, PyObject *args)
|
||||
unsigned int len = 0;
|
||||
short int edf = 0;
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if (!PyArg_ParseTuple(args, "y#h", &key, &len, &edf)) {
|
||||
#else
|
||||
if (!PyArg_ParseTuple(args, "s#h", &key, &len, &edf)) {
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -52,11 +48,7 @@ msdes_des(PyObject *self, PyObject *args)
|
||||
unsigned int off = 0;
|
||||
PyObject *retval = NULL;
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if (!PyArg_ParseTuple(args, "y#", &inbuf, &len)) {
|
||||
#else
|
||||
if (!PyArg_ParseTuple(args, "s#", &inbuf, &len)) {
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -85,9 +77,6 @@ static PyMethodDef msdes_methods[] = {
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
#define INITMODULE PyModule_Create(&msdes_module)
|
||||
static struct PyModuleDef msdes_module = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "msdes",
|
||||
@ -99,30 +88,18 @@ static struct PyModuleDef msdes_module = {
|
||||
/* m_clear */ 0,
|
||||
/* m_free */ 0,
|
||||
};
|
||||
|
||||
CALIBRE_MODINIT_FUNC PyInit_msdes(void) {
|
||||
#else
|
||||
#define INITERROR return
|
||||
#define INITMODULE Py_InitModule3("msdes", msdes_methods, msdes_doc)
|
||||
CALIBRE_MODINIT_FUNC initmsdes(void) {
|
||||
#endif
|
||||
|
||||
PyObject *m;
|
||||
|
||||
m = INITMODULE;
|
||||
PyObject *m = PyModule_Create(&msdes_module);
|
||||
if (m == NULL) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MsDesError = PyErr_NewException("msdes.MsDesError", NULL, NULL);
|
||||
Py_INCREF(MsDesError);
|
||||
PyModule_AddObject(m, "MsDesError", MsDesError);
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
PyModule_AddObject(m, "EN0", PyLong_FromLong(EN0));
|
||||
PyModule_AddObject(m, "DE1", PyLong_FromLong(DE1));
|
||||
|
||||
return m;
|
||||
#else
|
||||
PyModule_AddObject(m, "EN0", PyInt_FromLong(EN0));
|
||||
PyModule_AddObject(m, "DE1", PyInt_FromLong(DE1));
|
||||
#endif
|
||||
}
|
||||
|
@ -33,18 +33,12 @@ PDFDoc_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
}
|
||||
// }}}
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define BYTES_FMT "y#"
|
||||
#else
|
||||
#define BYTES_FMT "s#"
|
||||
#endif
|
||||
|
||||
// Loading/Opening of PDF files {{{
|
||||
static PyObject *
|
||||
PDFDoc_load(PDFDoc *self, PyObject *args) {
|
||||
char *buffer; Py_ssize_t size;
|
||||
|
||||
if (!PyArg_ParseTuple(args, BYTES_FMT, &buffer, &size)) return NULL;
|
||||
if (!PyArg_ParseTuple(args, "y#", &buffer, &size)) return NULL;
|
||||
|
||||
try {
|
||||
#if PODOFO_VERSION <= 0x000905
|
||||
@ -360,7 +354,7 @@ PDFDoc_get_xmp_metadata(PDFDoc *self, PyObject *args) {
|
||||
if ((str = metadata->GetStream()) != NULL) {
|
||||
str->GetFilteredCopy(&buf, &len);
|
||||
if (buf != NULL) {
|
||||
ans = Py_BuildValue(BYTES_FMT, buf, len);
|
||||
ans = Py_BuildValue("y#", buf, len);
|
||||
free(buf); buf = NULL;
|
||||
if (ans == NULL) goto error;
|
||||
}
|
||||
@ -388,7 +382,7 @@ PDFDoc_set_xmp_metadata(PDFDoc *self, PyObject *args) {
|
||||
TVecFilters compressed(1);
|
||||
compressed[0] = ePdfFilter_FlateDecode;
|
||||
|
||||
if (!PyArg_ParseTuple(args, BYTES_FMT, &raw, &len)) return NULL;
|
||||
if (!PyArg_ParseTuple(args, "y#", &raw, &len)) return NULL;
|
||||
try {
|
||||
if ((metadata = self->doc->GetMetadata()) != NULL) {
|
||||
if ((str = metadata->GetStream()) == NULL) { PyErr_NoMemory(); goto error; }
|
||||
@ -550,11 +544,7 @@ PDFDoc_alter_links(PDFDoc *self, PyObject *args) {
|
||||
static PyObject *
|
||||
PDFDoc_pages_getter(PDFDoc *self, void *closure) {
|
||||
int pages = self->doc->GetPageCount();
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
PyObject *ans = PyLong_FromLong(static_cast<long>(pages));
|
||||
#else
|
||||
PyObject *ans = PyInt_FromLong(static_cast<long>(pages));
|
||||
#endif
|
||||
if (ans != NULL) Py_INCREF(ans);
|
||||
return ans;
|
||||
}
|
||||
|
@ -135,16 +135,6 @@ convert_w_array(const PdfArray &w) {
|
||||
return ans.release();
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION > 2
|
||||
#define py_as_long_long PyLong_AsLongLong
|
||||
#else
|
||||
static inline long long
|
||||
py_as_long_long(PyObject *x) {
|
||||
if (PyInt_Check(x)) return PyInt_AS_LONG(x);
|
||||
return PyLong_AsLongLong(x);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
convert_w_array(PyObject *src, PdfArray &dest) {
|
||||
for (Py_ssize_t i = 0; i < PyList_GET_SIZE(src); i++) {
|
||||
@ -156,7 +146,7 @@ convert_w_array(PyObject *src, PdfArray &dest) {
|
||||
convert_w_array(item, sub);
|
||||
dest.push_back(sub);
|
||||
} else {
|
||||
pdf_int64 val = py_as_long_long(item);
|
||||
pdf_int64 val = PyLong_AsLongLong(item);
|
||||
if (val == -1 && PyErr_Occurred()) { PyErr_Print(); continue; }
|
||||
dest.push_back(PdfObject(val));
|
||||
}
|
||||
|
@ -97,11 +97,7 @@ class OutputDevice : public PdfOutputDevice {
|
||||
char *buf = NULL;
|
||||
Py_ssize_t len = 0;
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if ((temp = PyLong_FromSize_t(lLen)) == NULL) throw pyerr();
|
||||
#else
|
||||
if ((temp = PyInt_FromSize_t(lLen)) == NULL) throw pyerr();
|
||||
#endif
|
||||
ret = PyObject_CallFunctionObjArgs(read_func, temp, NULL);
|
||||
NUKE(temp);
|
||||
if (ret != NULL) {
|
||||
@ -122,11 +118,7 @@ class OutputDevice : public PdfOutputDevice {
|
||||
|
||||
void Seek(size_t offset) {
|
||||
PyObject *ret, *temp;
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
if ((temp = PyLong_FromSize_t(offset)) == NULL) throw pyerr();
|
||||
#else
|
||||
if ((temp = PyInt_FromSize_t(offset)) == NULL) throw pyerr();
|
||||
#endif
|
||||
ret = PyObject_CallFunctionObjArgs(seek_func, temp, NULL);
|
||||
NUKE(temp);
|
||||
if (ret == NULL) {
|
||||
@ -152,11 +144,7 @@ class OutputDevice : public PdfOutputDevice {
|
||||
PyErr_SetString(PyExc_Exception, "tell() method did not return a number");
|
||||
throw pyerr();
|
||||
}
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
ans = PyLong_AsUnsignedLongMask(ret);
|
||||
#else
|
||||
ans = PyInt_AsUnsignedLongMask(ret);
|
||||
#endif
|
||||
Py_DECREF(ret);
|
||||
if (PyErr_Occurred() != NULL) throw pyerr();
|
||||
|
||||
|
@ -40,9 +40,6 @@ static PyMethodDef podofo_methods[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
#define INITMODULE PyModule_Create(&podofo_module)
|
||||
static struct PyModuleDef podofo_module = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "podofo",
|
||||
@ -55,34 +52,28 @@ static struct PyModuleDef podofo_module = {
|
||||
/* m_free */ 0,
|
||||
};
|
||||
CALIBRE_MODINIT_FUNC PyInit_podofo(void) {
|
||||
#else
|
||||
#define INITERROR return
|
||||
#define INITMODULE Py_InitModule3("podofo", podofo_methods, podofo_doc)
|
||||
CALIBRE_MODINIT_FUNC initpodofo(void) {
|
||||
#endif
|
||||
|
||||
PyObject* m;
|
||||
|
||||
if (PyType_Ready(&pdf::PDFDocType) < 0) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (PyType_Ready(&pdf::PDFOutlineItemType) < 0) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pdf::Error = PyErr_NewException((char*)"podofo.Error", NULL, NULL);
|
||||
if (pdf::Error == NULL) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PdfError::SetLogMessageCallback((PdfError::LogMessageCallback*)&log_message);
|
||||
|
||||
PdfError::EnableDebug(false);
|
||||
|
||||
m = INITMODULE;
|
||||
m = PyModule_Create(&podofo_module);
|
||||
if (m == NULL) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF(&pdf::PDFDocType);
|
||||
@ -90,7 +81,5 @@ CALIBRE_MODINIT_FUNC initpodofo(void) {
|
||||
|
||||
PyModule_AddObject(m, "Error", pdf::Error);
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
@ -30,11 +30,5 @@ pdf::podofo_convert_pdfstring(const PdfString &s) {
|
||||
|
||||
const PdfString
|
||||
pdf::podofo_convert_pystring(PyObject *val) {
|
||||
#if PY_MAJOR_VERSION > 2
|
||||
return PdfString(reinterpret_cast<const pdf_utf8*>(PyUnicode_AsUTF8(val)));
|
||||
#else
|
||||
pyunique_ptr temp(PyUnicode_AsUTF8String(val));
|
||||
if (!temp) throw std::bad_alloc();
|
||||
return PdfString(reinterpret_cast<const pdf_utf8*>(PyBytes_AS_STRING(temp.get())));
|
||||
#endif
|
||||
}
|
||||
|
@ -299,42 +299,6 @@ error:
|
||||
return Py_BuildValue("NII", ans, state, codep);
|
||||
}
|
||||
|
||||
// This digs into python internals and can't be implemented easily in python3
|
||||
#if PY_MAJOR_VERSION == 2
|
||||
static PyObject*
|
||||
clean_xml_chars(PyObject *self, PyObject *text) {
|
||||
Py_UNICODE *buf = NULL, ch;
|
||||
PyUnicodeObject *ans = NULL;
|
||||
Py_ssize_t i = 0, j = 0;
|
||||
if (!PyUnicode_Check(text)) {
|
||||
PyErr_SetString(PyExc_TypeError, "A unicode string is required");
|
||||
return NULL;
|
||||
}
|
||||
ans = (PyUnicodeObject*) PyUnicode_FromUnicode(NULL, PyUnicode_GET_SIZE(text));
|
||||
if (ans == NULL) return PyErr_NoMemory();
|
||||
buf = ans->str;
|
||||
|
||||
for (; i < PyUnicode_GET_SIZE(text); i++) {
|
||||
ch = PyUnicode_AS_UNICODE(text)[i];
|
||||
#ifdef Py_UNICODE_WIDE
|
||||
if ((0x20 <= ch && ch <= 0xd7ff && ch != 0x7f) || ch == 9 || ch == 10 || ch == 13 || (0xe000 <= ch && ch <= 0xfffd) || (0xffff < ch && ch <= 0x10ffff))
|
||||
buf[j++] = ch;
|
||||
#else
|
||||
if ((0x20 <= ch && ch <= 0xd7ff && ch != 0x7f) || ch == 9 || ch == 10 || ch == 13 || (0xd000 <= ch && ch <= 0xfffd)) {
|
||||
if (0xd800 <= ch && ch <= 0xdfff) {
|
||||
// Test for valid surrogate pair
|
||||
if (ch <= 0xdbff && i + 1 < PyUnicode_GET_SIZE(text) && 0xdc00 <= PyUnicode_AS_UNICODE(text)[i + 1] && PyUnicode_AS_UNICODE(text)[i+1] <= 0xdfff) {
|
||||
buf[j++] = ch; buf[j++] = PyUnicode_AS_UNICODE(text)[++i];
|
||||
}
|
||||
} else
|
||||
buf[j++] = ch;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
ans->length = j;
|
||||
return (PyObject*)ans;
|
||||
}
|
||||
#else
|
||||
static PyObject*
|
||||
clean_xml_chars(PyObject *self, PyObject *text) {
|
||||
PyObject *result = NULL;
|
||||
@ -387,7 +351,6 @@ clean_xml_chars(PyObject *self, PyObject *text) {
|
||||
free(result_text);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
static PyObject *
|
||||
speedup_iso_8601(PyObject *self, PyObject *args) {
|
||||
@ -524,7 +487,6 @@ set_thread_name(PyObject *self, PyObject *args) {
|
||||
|
||||
#define char_is_ignored(ch) (ch <= 32)
|
||||
|
||||
#if PY_MAJOR_VERSION > 2
|
||||
static size_t
|
||||
count_chars_in(PyObject *text) {
|
||||
size_t ans = 0;
|
||||
@ -538,23 +500,6 @@ count_chars_in(PyObject *text) {
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
#else
|
||||
static size_t
|
||||
count_chars_in(PyObject *text) {
|
||||
size_t ans = 0;
|
||||
#define L(data, sz) { \
|
||||
ans = sz; \
|
||||
for (Py_ssize_t i = 0; i < sz; i++) { if (char_is_ignored((data)[i])) ans--; } \
|
||||
}
|
||||
if (PyUnicode_Check(text)) {
|
||||
L(PyUnicode_AS_UNICODE(text), PyUnicode_GET_SIZE(text));
|
||||
} else {
|
||||
L(PyBytes_AS_STRING(text), PyBytes_GET_SIZE(text));
|
||||
}
|
||||
return ans;
|
||||
#undef L
|
||||
}
|
||||
#endif
|
||||
|
||||
static PyObject*
|
||||
get_element_char_length(PyObject *self, PyObject *args) {
|
||||
@ -633,8 +578,6 @@ static PyMethodDef speedup_methods[] = {
|
||||
};
|
||||
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
static struct PyModuleDef speedup_module = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "speedup",
|
||||
@ -649,20 +592,10 @@ static struct PyModuleDef speedup_module = {
|
||||
|
||||
CALIBRE_MODINIT_FUNC PyInit_speedup(void) {
|
||||
PyObject *mod = PyModule_Create(&speedup_module);
|
||||
#else
|
||||
#define INITERROR return
|
||||
CALIBRE_MODINIT_FUNC initspeedup(void) {
|
||||
PyObject *mod = Py_InitModule3("speedup", speedup_methods,
|
||||
"Implementation of methods in C for speed.");
|
||||
#endif
|
||||
|
||||
if (mod == NULL) INITERROR;
|
||||
if (mod == NULL) return NULL;
|
||||
PyDateTime_IMPORT;
|
||||
#ifdef O_CLOEXEC
|
||||
PyModule_AddIntConstant(mod, "O_CLOEXEC", O_CLOEXEC);
|
||||
#endif
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return mod;
|
||||
#endif
|
||||
}
|
||||
|
@ -166,8 +166,6 @@ static PyTypeObject DictionaryType = {
|
||||
/* tp_new */ 0,
|
||||
};
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
static struct PyModuleDef hunspell_module = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "hunspell",
|
||||
@ -182,26 +180,18 @@ static struct PyModuleDef hunspell_module = {
|
||||
|
||||
CALIBRE_MODINIT_FUNC PyInit_hunspell(void) {
|
||||
PyObject *mod = PyModule_Create(&hunspell_module);
|
||||
#else
|
||||
#define INITERROR return
|
||||
CALIBRE_MODINIT_FUNC inithunspell(void) {
|
||||
PyObject *mod = Py_InitModule3("hunspell", NULL,
|
||||
"A wrapper for the hunspell spell checking library");
|
||||
#endif
|
||||
if (mod == NULL) INITERROR;
|
||||
if (mod == NULL) return NULL;
|
||||
|
||||
HunspellError = PyErr_NewException((char*)"hunspell.HunspellError", NULL, NULL);
|
||||
if (HunspellError == NULL) INITERROR;
|
||||
if (HunspellError == NULL) return NULL;
|
||||
PyModule_AddObject(mod, "HunspellError", HunspellError);
|
||||
|
||||
// Fill in some slots in the type, and make it ready
|
||||
DictionaryType.tp_new = PyType_GenericNew;
|
||||
if (PyType_Ready(&DictionaryType) < 0) INITERROR;
|
||||
if (PyType_Ready(&DictionaryType) < 0) return NULL;
|
||||
// Add the type to the module.
|
||||
Py_INCREF(&DictionaryType);
|
||||
PyModule_AddObject(mod, "Dictionary", (PyObject *)&DictionaryType);
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return mod;
|
||||
#endif
|
||||
}
|
||||
|
@ -474,9 +474,6 @@ be a unicode string. Returns unicode strings."
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
#define INITMODULE PyModule_Create(&winutil_module)
|
||||
static struct PyModuleDef winutil_module = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "winutil",
|
||||
@ -489,17 +486,10 @@ static struct PyModuleDef winutil_module = {
|
||||
/* m_free */ 0,
|
||||
};
|
||||
CALIBRE_MODINIT_FUNC PyInit_winutil(void) {
|
||||
#else
|
||||
#define INITERROR return
|
||||
#define INITMODULE Py_InitModule3("winutil", winutil_methods, winutil_doc)
|
||||
CALIBRE_MODINIT_FUNC initwinutil(void) {
|
||||
#endif
|
||||
|
||||
PyObject *m;
|
||||
m = INITMODULE;
|
||||
PyObject *m = PyModule_Create(&winutil_module);
|
||||
|
||||
if (m == NULL) {
|
||||
INITERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyModule_AddIntConstant(m, "CSIDL_ADMINTOOLS", CSIDL_ADMINTOOLS);
|
||||
@ -524,7 +514,5 @@ CALIBRE_MODINIT_FUNC initwinutil(void) {
|
||||
PyModule_AddIntConstant(m, "CSIDL_STARTUP", CSIDL_STARTUP);
|
||||
PyModule_AddIntConstant(m, "CSIDL_COMMON_STARTUP", CSIDL_COMMON_STARTUP);
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
@ -100,18 +100,6 @@ class scoped_com_initializer { // {{{
|
||||
scoped_com_initializer & operator=( const scoped_com_initializer & ) ;
|
||||
}; // }}}
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
static wchar_t*
|
||||
PyUnicode_AsWideCharString(PyObject *obj, Py_ssize_t *size) {
|
||||
Py_ssize_t sz = PyUnicode_GET_SIZE(obj) * 4 + 4;
|
||||
wchar_t *ans = (wchar_t*)PyMem_Malloc(sz);
|
||||
memset(ans, 0, sz);
|
||||
Py_ssize_t res = PyUnicode_AsWideChar(reinterpret_cast<PyUnicodeObject*>(obj), ans, (sz / sizeof(wchar_t)) - 1);
|
||||
if (size) *size = res;
|
||||
return ans;
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline int
|
||||
py_to_wchar(PyObject *obj, wchar_raii *output) {
|
||||
if (!PyUnicode_Check(obj)) {
|
||||
|
@ -55,24 +55,18 @@ tokenizer_Token_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define PyObject_Unicode_Compat(arg) PyObject_Str(arg)
|
||||
#else
|
||||
#define PyObject_Unicode_Compat(arg) PyObject_Unicode(arg)
|
||||
#endif
|
||||
|
||||
static PyObject *
|
||||
tokenizer_Token_repr(tokenizer_Token *self) {
|
||||
PyObject *type = NULL, *line = NULL, *column = NULL, *value = NULL, *ans = NULL, *unit = NULL;
|
||||
if (!self->type || !self->line || !self->column || !self->value)
|
||||
return PyBytes_FromString("<Token NULL fields>");
|
||||
type = PyObject_Unicode_Compat(self->type);
|
||||
line = PyObject_Unicode_Compat(self->line);
|
||||
column = PyObject_Unicode_Compat(self->column);
|
||||
value = PyObject_Unicode_Compat(self->value);
|
||||
type = PyObject_Str(self->type);
|
||||
line = PyObject_Str(self->line);
|
||||
column = PyObject_Str(self->column);
|
||||
value = PyObject_Str(self->value);
|
||||
if (type && line && column && value) {
|
||||
if (self->unit != NULL && PyObject_IsTrue(self->unit)) {
|
||||
unit = PyObject_Unicode_Compat(self->unit);
|
||||
unit = PyObject_Str(self->unit);
|
||||
if (unit != NULL)
|
||||
ans = PyUnicode_FromFormat("<Token %U at %U:%U %U%U>", type, line, column, value, unit);
|
||||
else
|
||||
@ -205,20 +199,12 @@ tokenize_init(PyObject *self, PyObject *args) {
|
||||
#define END_ITER_CODE_PTS }}
|
||||
|
||||
static PyObject *unicode_to_number(PyObject *src) {
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
PyObject* ans = PyFloat_FromString(src);
|
||||
#else
|
||||
PyObject* ans = PyFloat_FromString(src, NULL);
|
||||
#endif
|
||||
double val = PyFloat_AsDouble(ans);
|
||||
long lval = (long)val;
|
||||
if (val - lval != 0) return ans;
|
||||
Py_DECREF(ans);
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return PyLong_FromLong(lval);
|
||||
#else
|
||||
return PyInt_FromLong(lval);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -465,8 +451,6 @@ static PyMethodDef tokenizer_methods[] = {
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
static struct PyModuleDef tokenizer_module = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "tokenizer",
|
||||
@ -480,25 +464,11 @@ static struct PyModuleDef tokenizer_module = {
|
||||
};
|
||||
|
||||
CALIBRE_MODINIT_FUNC PyInit_tokenizer(void) {
|
||||
if (PyType_Ready(&tokenizer_TokenType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&tokenizer_TokenType) < 0) return NULL;
|
||||
|
||||
PyObject *mod = PyModule_Create(&tokenizer_module);
|
||||
#else
|
||||
#define INITERROR return
|
||||
CALIBRE_MODINIT_FUNC inittokenizer(void) {
|
||||
if (PyType_Ready(&tokenizer_TokenType) < 0)
|
||||
INITERROR;
|
||||
|
||||
PyObject *mod = Py_InitModule3("tokenizer", tokenizer_methods,
|
||||
"Implementation of tokenizer in C for speed.");
|
||||
#endif
|
||||
|
||||
if (mod == NULL) INITERROR;
|
||||
if (mod == NULL) return NULL;
|
||||
Py_INCREF(&tokenizer_TokenType);
|
||||
PyModule_AddObject(mod, "Token", (PyObject *) &tokenizer_TokenType);
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
return mod;
|
||||
#endif
|
||||
}
|
||||
|
@ -81,8 +81,6 @@ static PyMethodDef unicode_names_methods[] = {
|
||||
{NULL, NULL, 0, NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define INITERROR return NULL
|
||||
static struct PyModuleDef unicode_names_module = {
|
||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
||||
/* m_name */ "unicode_names",
|
||||
@ -96,15 +94,6 @@ static struct PyModuleDef unicode_names_module = {
|
||||
};
|
||||
|
||||
CALIBRE_MODINIT_FUNC PyInit_unicode_names(void) {
|
||||
#else
|
||||
#define INITERROR return
|
||||
CALIBRE_MODINIT_FUNC initunicode_names(void) {
|
||||
#endif
|
||||
// Create the module
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
PyObject *mod = PyModule_Create(&unicode_names_module);
|
||||
return mod;
|
||||
#else
|
||||
Py_InitModule3("unicode_names", unicode_names_methods, "");
|
||||
#endif
|
||||
return PyModule_Create(&unicode_names_module);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user