]> granicus.if.org Git - cracklib/commitdiff
port Python binding to Python3
authorJan Dittberner <jan@dittberner.info>
Fri, 18 May 2012 13:55:17 +0000 (13:55 +0000)
committerJan Dittberner <jan@dittberner.info>
Fri, 18 May 2012 13:55:17 +0000 (13:55 +0000)
git-svn-id: file:///tmp/cracklib-svn/trunk@192 4175fe1e-86d5-4fdc-8e6a-506fab9d8533

cracklib/NEWS
cracklib/python/_cracklibmodule.c

index 6994749987c0a4123c23ef3419ad9e19e797936a..fc223a6957e6f844572924e0b9efad2d3f2988b5 100644 (file)
@@ -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
index d4ba95d4fe76b79c1fd68a96237be62883448668..a19e9bf0d3c2931532f5ccd6b3ba99ee3d77603e 100644 (file)
@@ -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
 }