diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2015-08-01 00:07:29 +0200 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2015-08-01 00:07:29 +0200 |
| commit | 8cd03c18b43adcf942f603cc4e89eb00305a483e (patch) | |
| tree | 75101cbe0615ae91f6f240cc6137d30000988f08 | |
| parent | updated tests and added run_test script (diff) | |
| download | SyncRNG-8cd03c18b43adcf942f603cc4e89eb00305a483e.tar.gz SyncRNG-8cd03c18b43adcf942f603cc4e89eb00305a483e.zip | |
added Python 3 support
| -rw-r--r-- | src/syncrng.c | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/src/syncrng.c b/src/syncrng.c index 668c39e..ed8ea53 100644 --- a/src/syncrng.c +++ b/src/syncrng.c @@ -164,13 +164,49 @@ static PyMethodDef SyncRNGMethods[] = { {NULL, NULL, 0, NULL} }; -PyMODINIT_FUNC initsyncrng(void) +#if PY_MAJOR_VERSION >= 3 + static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, + "syncrng", + "Python interface to SyncRNG", + -1, + SyncRNGMethods, + NULL, + NULL, + NULL, + NULL + }; +#endif + + +static PyObject * +moduleinit(void) { - PyObject *m = Py_InitModule3("syncrng", SyncRNGMethods, - "Python interface to SyncRNG"); - if (m == NULL) - return; + PyObject *m; + + #if PY_MAJOR_VERSION >= 3 + m = PyModule_Create(&moduledef); + #else + m = Py_InitModule3("syncrng", SyncRNGMethods, + "Python interface to SyncRNG"); + #endif + + return m; } + +#if PY_MAJOR_VERSION >= 3 +PyMODINIT_FUNC +PyInit_syncrng(void) +{ + return moduleinit(); +} +#else +PyMODINIT_FUNC +initsyncrng(void) +{ + moduleinit(); +} +#endif #endif #ifndef TARGETPYTHON |
