summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Dittberner <jan@dittberner.info>2012-05-18 13:55:17 +0000
committerJan Dittberner <jan@dittberner.info>2012-05-18 13:55:17 +0000
commit219de98766b9f1e4c8c5b174de770158ffda3a93 (patch)
treead7dad5949c3b2b4d3c26f559e5b334c717c3a2e
parent62aa9819680cc72d5b5d3d0c085727b19f05c54b (diff)
downloadcracklib-219de98766b9f1e4c8c5b174de770158ffda3a93.tar.gz
port Python binding to Python3
git-svn-id: file:///tmp/cracklib-svn/trunk@192 4175fe1e-86d5-4fdc-8e6a-506fab9d8533
-rw-r--r--cracklib/NEWS1
-rw-r--r--cracklib/python/_cracklibmodule.c39
2 files changed, 38 insertions, 2 deletions
diff --git a/cracklib/NEWS b/cracklib/NEWS
index 6994749..fc223a6 100644
--- a/cracklib/NEWS
+++ b/cracklib/NEWS
@@ -2,6 +2,7 @@ v2.8.19 drop autogenerated files from SVN (Mike Frysinger)
add words from "The Top 500 Worst Passwords of All Time" <http://www.whatsmypass.com/the-top-500-worst-passwords-of-all-time> to dicts/cracklib-small (patch by Fabian Greffrath)
include sys/stat.h in python/_cracklibmodule.c (Mike Frysinger)
add test suite for Python binding (Jan Dittberner)
+ port Python binding to Python3 (Jan Dittberner)
v2.8.18 also include stdlib.h in stringlib.c (Mike Frysinger)
make sure python lib builds against build dir instead of system installed libs (Arfrever Frehtes Taifersar Arahesis)
v2.8.17 fixed compilation on interix systems
diff --git a/cracklib/python/_cracklibmodule.c b/cracklib/python/_cracklibmodule.c
index d4ba95d..a19e9bf 100644
--- a/cracklib/python/_cracklibmodule.c
+++ b/cracklib/python/_cracklibmodule.c
@@ -4,7 +4,7 @@
* Parts of this code are based on work Copyright (c) 2003 by Domenico
* Andreoli.
*
- * Copyright (c) 2008, 2009 Jan Dittberner <jan@dittberner.info>
+ * Copyright (c) 2008, 2009, 2012 Jan Dittberner <jan@dittberner.info>
*
* This file is part of cracklib.
*
@@ -28,6 +28,9 @@
#else
#include <Python.h>
#endif
+#if PY_MAJOR_VERSION >= 3
+#define IS_PY3K
+#endif
#ifdef HAVE_PTHREAD_H
#include <pthread.h>
#endif
@@ -176,8 +179,40 @@ static char _cracklib_doc[] =
"program or interpreter.\n"
;
+#ifdef IS_PY3K
+
+static struct PyModuleDef moduledef = {
+ PyModuleDef_HEAD_INIT,
+ "_cracklib",
+ _cracklib_doc,
+ 0,
+ _cracklibmethods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+#define INITERROR return NULL
+
+PyObject *
+PyInit__cracklib(void)
+
+#else
+#define INITERROR return
+
void
init_cracklib(void)
+#endif
{
- Py_InitModule3("_cracklib", _cracklibmethods, _cracklib_doc);
+#ifdef IS_PY3K
+ PyObject *module = PyModule_Create(&moduledef);
+#else
+ PyObject *module = Py_InitModule3("_cracklib", _cracklibmethods, _cracklib_doc);
+#endif
+ if (module == NULL)
+ INITERROR;
+#ifdef IS_PY3K
+ return module;
+#endif
}