Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support PEP 489 multi-phase module init #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 21 additions & 29 deletions hypatia/text/okascore.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@

#include "Python.h"

#if PY_MAJOR_VERSION >= 3
#define PY3K
#endif

#define K1 1.2
#define B 0.75

Expand Down Expand Up @@ -131,37 +127,33 @@ static char score__doc__[] =
"\n"
"Do the inner scoring loop for an Okapi index.\n";

static PyMethodDef okascore_functions[] = {
static PyMethodDef module_functions[] = {
{"score", score, METH_VARARGS, score__doc__},
{NULL}
};

#ifdef PY3K
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"okascore", /* m_name */
"inner scoring loop for Okapi rank", /* m_doc */
-1, /* m_size */
okascore_functions, /* m_methods */
NULL, /* m_reload */
NULL, /* m_traverse */
NULL, /* m_clear */
NULL, /* m_free */
};
static char module__name__[] = "okascore";
static char module__doc__[] = "inner scoring loop for Okapi rank";

/*
* No slot definitions needed multi-phase initialization:
*
* we have no state, and initialize / register no types.
*/
static PyModuleDef_Slot module_slots[] = {
{0, NULL}
};

static struct PyModuleDef module_def = {
PyModuleDef_HEAD_INIT,
.m_name = module__name__,
.m_doc = module__doc__,
.m_methods = module_functions,
.m_slots = module_slots,
};

PyMODINIT_FUNC
PyInit_okascore(void)
{
PyObject *m;
m = PyModule_Create(&moduledef);
return m;
}
#else
PyMODINIT_FUNC
initokascore(void)
{
/* XXX: Error checking */
Py_InitModule3("okascore", okascore_functions,
"inner scoring loop for Okapi rank");
return PyModuleDef_Init(&module_def);
}
#endif