From f264fbdd0df542fac3b21ae27c31f4abc0a36c21 Mon Sep 17 00:00:00 2001 From: Flaviu Tamas Date: Thu, 23 Aug 2018 21:53:23 -0400 Subject: [PATCH] Build unicode_names in py3 --- src/unicode_names/unicode_names.c | 49 +++++++++++++++---------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/src/unicode_names/unicode_names.c b/src/unicode_names/unicode_names.c index 766cd0aea5..d0c9238efe 100644 --- a/src/unicode_names/unicode_names.c +++ b/src/unicode_names/unicode_names.c @@ -84,38 +84,37 @@ nfc(PyObject *self UNUSED, PyObject *args) { return PyUnicode_FromString(n); } -static PyMethodDef module_methods[] = { +static PyMethodDef unicode_names_methods[] = { {"all_words", (PyCFunction)all_words, METH_NOARGS, ""}, {"codepoints_for_word", (PyCFunction)cfw, METH_VARARGS, ""}, {"name_for_codepoint", (PyCFunction)nfc, METH_VARARGS, ""}, {NULL, NULL, 0, NULL} /* Sentinel */ }; -#if PY_VERSION_HEX >= 0x03000000 -static struct PyModuleDef module = { - .m_base = PyModuleDef_HEAD_INIT, - .m_name = "unicode_names", /* name of module */ - .m_doc = NULL, - .m_size = -1, - .m_methods = module_methods +#if PY_MAJOR_VERSION >= 3 +#define INITERROR return NULL +static struct PyModuleDef unicode_names_module = { + /* m_base */ PyModuleDef_HEAD_INIT, + /* m_name */ "unicode_names", + /* m_doc */ "A library to assist with selecting special characters", + /* m_size */ -1, + /* m_methods */ unicode_names_methods, + /* m_slots */ 0, + /* m_traverse */ 0, + /* m_clear */ 0, + /* m_free */ 0, }; - -EXPORTED PyMODINIT_FUNC -PyInit_unicode_names(void) { - PyObject *m; - - m = PyModule_Create(&module); - if (m == NULL) return NULL; - return m; -} +CALIBRE_MODINIT_FUNC PyInit_unicode_names(void) { #else -EXPORTED -initunicode_names(void) { - PyObject *m; - m = Py_InitModule3("unicode_names", module_methods, - "" - ); - if (m == NULL) return; -} +#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 +}