Bump the minor version and add python 3 support.

This commit is contained in:
David Novakovic 2018-05-28 15:07:05 +10:00
parent d2669e5069
commit d006e4e257
No known key found for this signature in database
GPG key ID: 2A5BBD0002026A59
2 changed files with 65 additions and 5 deletions

View file

@ -6,6 +6,7 @@
*
* Copyright 2009 Russell Keith-Magee <russell@keith-magee.com>
*/
#include <Python.h>
#include <sys/types.h>
#include <stdio.h>
@ -15,6 +16,17 @@ int edit_distn(char *from, int from_len, char *to, int to_len);
char *spamsum(const unsigned char *in, unsigned int length, unsigned int flags, unsigned int bsize);
unsigned int spamsum_match(const char *str1, const char *str2);
struct module_state {
PyObject *error;
};
#if PY_MAJOR_VERSION >= 3
#define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))
#else
#define GETSTATE(m) (&_state)
static struct module_state _state;
#endif
PyObject *py_edit_distance(PyObject *self, PyObject *args)
{
PyObject *result = NULL;
@ -90,8 +102,56 @@ static PyMethodDef methods[] = {
{NULL, NULL, 0, NULL}
};
PyMODINIT_FUNC
initspamsum()
{
(void) Py_InitModule("spamsum", methods);
#if PY_MAJOR_VERSION >= 3
static int spamsum_traverse(PyObject *m, visitproc visit, void *arg) {
Py_VISIT(GETSTATE(m)->error);
return 0;
}
static int spamsum_clear(PyObject *m) {
Py_CLEAR(GETSTATE(m)->error);
return 0;
}
static struct PyModuleDef ss =
{
PyModuleDef_HEAD_INIT,
"spamsum",
"",
sizeof(struct module_state),
methods,
NULL,
spamsum_traverse,
spamsum_clear,
NULL
};
#define INITERROR return NULL
PyMODINIT_FUNC
PyInit_spamsum(void)
#else
#define INITERROR return
void
initspamsum(void)
#endif
{
#if PY_MAJOR_VERSION >= 3
PyObject *module = PyModule_Create(&ss);
#else
PyObject *module = Py_InitModule("spamsum", methods);
#endif
if (module == NULL)
INITERROR;
struct module_state *st = GETSTATE(module);
st->error = PyErr_NewException("spamsum.Error", NULL, NULL);
if (st->error == NULL) {
Py_DECREF(module);
INITERROR;
}
#if PY_MAJOR_VERSION >= 3
return module;
#endif
}

View file

@ -1,7 +1,7 @@
from distutils.core import setup, Extension
setup(name = "pyspamsum",
version = "1.0.3",
version = "1.0.4",
author = "Russell Keith-Magee",
author_email = "russell@keith-magee.com",
url = 'http://github.com/freakboy3742/pyspamsum/',