mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
More multi-phase init
This commit is contained in:
parent
027bf97633
commit
e02ae467a7
@ -1255,30 +1255,25 @@ static PyMethodDef _patiencediff_c_methods[] = {
|
|||||||
{NULL, NULL, 0, NULL}
|
{NULL, NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct PyModuleDef _patiencediff_c_module = {
|
static int
|
||||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
exec_module(PyObject *mod) {
|
||||||
/* m_name */ "_patiencediff_c",
|
|
||||||
/* m_doc */ "C implementation of PatienceSequenceMatcher.",
|
|
||||||
/* m_size */ -1,
|
|
||||||
/* m_methods */ _patiencediff_c_methods,
|
|
||||||
/* m_slots */ 0,
|
|
||||||
/* m_traverse */ 0,
|
|
||||||
/* m_clear */ 0,
|
|
||||||
/* m_free */ 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
CALIBRE_MODINIT_FUNC PyInit__patiencediff_c(void) {
|
|
||||||
if (PyType_Ready(&PatienceSequenceMatcherType) < 0)
|
if (PyType_Ready(&PatienceSequenceMatcherType) < 0)
|
||||||
return NULL;
|
return -1;
|
||||||
|
|
||||||
PyObject *mod = PyModule_Create(&_patiencediff_c_module);
|
|
||||||
if (mod == NULL) return NULL;
|
|
||||||
|
|
||||||
Py_INCREF(&PatienceSequenceMatcherType);
|
Py_INCREF(&PatienceSequenceMatcherType);
|
||||||
PyModule_AddObject(mod, "PatienceSequenceMatcher_c",
|
PyModule_AddObject(mod, "PatienceSequenceMatcher_c",
|
||||||
(PyObject *)&PatienceSequenceMatcherType);
|
(PyObject *)&PatienceSequenceMatcherType);
|
||||||
|
return 0;
|
||||||
|
|
||||||
return mod;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim: sw=4 et */
|
static PyModuleDef_Slot slots[] = { {Py_mod_exec, exec_module}, {0, NULL} };
|
||||||
|
|
||||||
|
static struct PyModuleDef module_def = {
|
||||||
|
.m_base = PyModuleDef_HEAD_INIT,
|
||||||
|
.m_name = "_patiencediff_c",
|
||||||
|
.m_doc = "C implementation of PatienceSequenceMatcher.",
|
||||||
|
.m_methods = _patiencediff_c_methods,
|
||||||
|
.m_slots = slots,
|
||||||
|
};
|
||||||
|
|
||||||
|
CALIBRE_MODINIT_FUNC PyInit__patiencediff_c(void) { return PyModuleDef_Init(&module_def); }
|
||||||
|
@ -1222,19 +1222,8 @@ static PyMethodDef icu_methods[] = {
|
|||||||
{NULL} /* Sentinel */
|
{NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct PyModuleDef icu_module = {
|
static int
|
||||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
exec_module(PyObject *mod) {
|
||||||
/* m_name */ "icu",
|
|
||||||
/* m_doc */ "Wrapper for the ICU internationalization library",
|
|
||||||
/* m_size */ -1,
|
|
||||||
/* m_methods */ icu_methods,
|
|
||||||
/* m_slots */ 0,
|
|
||||||
/* m_traverse */ 0,
|
|
||||||
/* m_clear */ 0,
|
|
||||||
/* m_free */ 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
CALIBRE_MODINIT_FUNC PyInit_icu(void) {
|
|
||||||
UVersionInfo ver, uver;
|
UVersionInfo ver, uver;
|
||||||
UErrorCode status = U_ZERO_ERROR;
|
UErrorCode status = U_ZERO_ERROR;
|
||||||
char version[U_MAX_VERSION_STRING_LENGTH+1] = {0}, uversion[U_MAX_VERSION_STRING_LENGTH+5] = {0};
|
char version[U_MAX_VERSION_STRING_LENGTH+1] = {0}, uversion[U_MAX_VERSION_STRING_LENGTH+5] = {0};
|
||||||
@ -1242,7 +1231,7 @@ CALIBRE_MODINIT_FUNC PyInit_icu(void) {
|
|||||||
u_init(&status);
|
u_init(&status);
|
||||||
if (U_FAILURE(status)) {
|
if (U_FAILURE(status)) {
|
||||||
PyErr_Format(PyExc_RuntimeError, "u_init() failed with error: %s", u_errorName(status));
|
PyErr_Format(PyExc_RuntimeError, "u_init() failed with error: %s", u_errorName(status));
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
u_getVersion(ver);
|
u_getVersion(ver);
|
||||||
u_versionToString(ver, version);
|
u_versionToString(ver, version);
|
||||||
@ -1250,13 +1239,9 @@ CALIBRE_MODINIT_FUNC PyInit_icu(void) {
|
|||||||
u_versionToString(uver, uversion);
|
u_versionToString(uver, uversion);
|
||||||
|
|
||||||
if (PyType_Ready(&icu_CollatorType) < 0)
|
if (PyType_Ready(&icu_CollatorType) < 0)
|
||||||
return NULL;
|
return -1;
|
||||||
if (PyType_Ready(&icu_BreakIteratorType) < 0)
|
if (PyType_Ready(&icu_BreakIteratorType) < 0)
|
||||||
return NULL;
|
return -1;
|
||||||
|
|
||||||
PyObject *mod = PyModule_Create(&icu_module);
|
|
||||||
|
|
||||||
if (mod == NULL) return NULL;
|
|
||||||
|
|
||||||
Py_INCREF(&icu_CollatorType); Py_INCREF(&icu_BreakIteratorType);
|
Py_INCREF(&icu_CollatorType); Py_INCREF(&icu_BreakIteratorType);
|
||||||
PyModule_AddObject(mod, "Collator", (PyObject *)&icu_CollatorType);
|
PyModule_AddObject(mod, "Collator", (PyObject *)&icu_CollatorType);
|
||||||
@ -1298,6 +1283,19 @@ CALIBRE_MODINIT_FUNC PyInit_icu(void) {
|
|||||||
ADDUCONST(UBRK_LINE);
|
ADDUCONST(UBRK_LINE);
|
||||||
ADDUCONST(UBRK_SENTENCE);
|
ADDUCONST(UBRK_SENTENCE);
|
||||||
|
|
||||||
return mod;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyModuleDef_Slot slots[] = { {Py_mod_exec, exec_module}, {0, NULL} };
|
||||||
|
|
||||||
|
static struct PyModuleDef module_def = {
|
||||||
|
.m_base = PyModuleDef_HEAD_INIT,
|
||||||
|
.m_name = "icu",
|
||||||
|
.m_doc = "Wrapper for the ICU internationalization library",
|
||||||
|
.m_methods = icu_methods,
|
||||||
|
.m_slots = slots,
|
||||||
|
};
|
||||||
|
|
||||||
|
CALIBRE_MODINIT_FUNC PyInit_icu(void) { return PyModuleDef_Init(&module_def); }
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
@ -501,31 +501,24 @@ static PyTypeObject MatcherType = { // {{{
|
|||||||
/* tp_new */ PyType_GenericNew,
|
/* tp_new */ PyType_GenericNew,
|
||||||
}; // }}}
|
}; // }}}
|
||||||
|
|
||||||
static struct PyModuleDef matcher_module = {
|
static int
|
||||||
/* m_base */ PyModuleDef_HEAD_INIT,
|
exec_module(PyObject *mod) {
|
||||||
/* m_name */ "matcher",
|
if (PyType_Ready(&MatcherType) < 0) return -1;
|
||||||
/* m_doc */ "Find subsequence matches.",
|
|
||||||
/* m_size */ -1,
|
|
||||||
/* m_methods */ 0,
|
|
||||||
/* m_slots */ 0,
|
|
||||||
/* m_traverse */ 0,
|
|
||||||
/* m_clear */ 0,
|
|
||||||
/* m_free */ 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
CALIBRE_MODINIT_FUNC PyInit_matcher(void) {
|
|
||||||
PyObject *mod = PyModule_Create(&matcher_module);
|
|
||||||
if (mod == NULL) return NULL;
|
|
||||||
|
|
||||||
if (PyType_Ready(&MatcherType) < 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
Py_INCREF(&MatcherType);
|
Py_INCREF(&MatcherType);
|
||||||
if(PyModule_AddObject(mod, "Matcher", (PyObject *)&MatcherType) < 0) {
|
if(PyModule_AddObject(mod, "Matcher", (PyObject *)&MatcherType) < 0) {
|
||||||
Py_DECREF(&MatcherType);
|
Py_DECREF(&MatcherType);
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
return mod;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyModuleDef_Slot slots[] = { {Py_mod_exec, exec_module}, {0, NULL} };
|
||||||
|
|
||||||
|
static struct PyModuleDef module_def = {
|
||||||
|
.m_base = PyModuleDef_HEAD_INIT,
|
||||||
|
.m_name = "matcher",
|
||||||
|
.m_doc = "Find subsequence matches.",
|
||||||
|
.m_slots = slots,
|
||||||
|
};
|
||||||
|
|
||||||
|
CALIBRE_MODINIT_FUNC PyInit_matcher(void) { return PyModuleDef_Init(&module_def); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user