diff --git a/module.cpp b/module.cpp index f0cae64..77556d6 100644 --- a/module.cpp +++ b/module.cpp @@ -1,5 +1,6 @@ #include #include "MurmurHash3.h" +#include "version.py" static PyObject *hash32(PyObject *, PyObject *); static PyObject *hash128(PyObject *, PyObject *); @@ -145,12 +146,16 @@ static PyObject *hash128_64(PyObject *self, PyObject *args) #if PY_MAJOR_VERSION <= 2 /* Python 1.x/2.x */ - extern "C" - PyMODINIT_FUNC + extern "C" PyMODINIT_FUNC initmurmur3(void) { //Py_Initialize(); - (void) Py_InitModule3("murmur3", methods, (char *)documentation); + PyObject *module; + + module = Py_InitModule3("murmur3", methods, (char *)documentation); + if (!module) return; + + PyModule_AddStringConstant(module, "__version__", MODULE_VERSION); } #else /* Python 3.x */ @@ -167,13 +172,15 @@ static PyObject *hash128_64(PyObject *self, PyObject *args) NULL }; - extern "C" - PyMODINIT_FUNC + extern "C" PyMODINIT_FUNC PyInit_murmur3(void) { PyObject *module; module = PyModule_Create(&murmur3_module); + if (!module) return module; + PyModule_AddStringConstant(module, "__version__", MODULE_VERSION); + return module; } #endif diff --git a/setup.py b/setup.py index 5f1f6e4..dd89364 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,9 @@ from distutils.core import setup, Extension +import version setup( name = 'murmur3', - version = '0.2', + version = version.MODULE_VERSION, ext_modules = [ Extension('murmur3', ['module.cpp', 'MurmurHash3.cpp'],), ], diff --git a/version.py b/version.py new file mode 100644 index 0000000..596d498 --- /dev/null +++ b/version.py @@ -0,0 +1,5 @@ +#ifndef __FILE__ +MODULE_VERSION = "0.2.0" +#else +#define MODULE_VERSION "0.2.0" +#endif \ No newline at end of file